Skip to content

Commit 7ee9a74

Browse files
committed
Fix CodeFactor issues
1 parent de90f90 commit 7ee9a74

20 files changed

+740
-956
lines changed

custom_components/oig_cloud/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,16 @@ async def _setup_frontend_panel(hass: HomeAssistant, entry: ConfigEntry) -> None
318318
):
319319
try:
320320
frontend.async_remove_panel(hass, panel_id, warn_if_unknown=False)
321-
except Exception:
321+
except Exception as err:
322322
try:
323323
frontend.async_remove_panel(hass, panel_id)
324-
except Exception:
325-
pass
324+
except Exception as fallback_err:
325+
_LOGGER.debug(
326+
"Failed to remove panel %s: %s (fallback: %s)",
327+
panel_id,
328+
err,
329+
fallback_err,
330+
)
326331

327332
# OPRAVA: Kontrola existence funkce a její volání bez await pokud vrací None
328333
if hasattr(frontend, "async_register_built_in_panel"):

custom_components/oig_cloud/api/api_chmu.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,19 @@ async def _resolve_latest_cap_url(self, session: aiohttp.ClientSession) -> str:
125125
)
126126
index_html = await response.text()
127127

128+
def _parse_index_dt(value: str) -> Optional[datetime]:
129+
try:
130+
return datetime.strptime(value, "%d-%b-%Y %H:%M")
131+
except Exception as err:
132+
_LOGGER.debug("Skipping CAP index entry '%s': %s", value, err)
133+
return None
134+
128135
items: list[tuple[datetime, str, str]] = []
129136
for m in self._AUTO_INDEX_RE.finditer(index_html):
130-
try:
131-
dt = datetime.strptime(m.group("dt"), "%d-%b-%Y %H:%M")
132-
items.append((dt, m.group("series"), m.group("file")))
133-
except Exception:
137+
dt = _parse_index_dt(m.group("dt"))
138+
if dt is None:
134139
continue
140+
items.append((dt, m.group("series"), m.group("file")))
135141

136142
if not items:
137143
raise ChmuApiError("CAP index neobsahuje žádné alert_cap_*.xml soubory")
@@ -164,7 +170,7 @@ def _parse_cap_xml(self, xml_text: str) -> List[Dict[str, Any]]:
164170
Seznam varování (raw data z XML)
165171
"""
166172
try:
167-
root = ET.fromstring(xml_text)
173+
root = ET.fromstring(xml_text) # nosec B314
168174
except ET.ParseError as e:
169175
_LOGGER.error(f"Chyba parsování CAP XML: {e}")
170176
return []

custom_components/oig_cloud/api/ote_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ async def _download_soap(self, body_xml: str, action: str) -> str:
289289

290290
def _parse_soap_response(self, soap_response: str) -> ET.Element:
291291
try:
292-
root = ET.fromstring(soap_response)
292+
root = ET.fromstring(soap_response) # nosec B314
293293
except Exception as e:
294294
if "Application is not available" in soap_response:
295295
raise UpdateFailed("OTE Portal is currently not available!") from e

custom_components/oig_cloud/config_flow_wizard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,6 @@ async def _detect_fve_power(self) -> float:
10601060
state = self.hass.states.get(entity.entity_id)
10611061
if state and state.state not in ("unknown", "unavailable"):
10621062
return round(float(state.state) / 1000, 1)
1063-
except Exception:
1064-
pass
1063+
except Exception as err:
1064+
_LOGGER.debug("Auto-detect FVE power failed: %s", err)
10651065
return 5.4 # Default

custom_components/oig_cloud/data_source.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def _parse_dt(value: Any) -> Optional[dt_util.dt.datetime]:
126126
if ts > 1_000_000_000_000: # ms epoch
127127
ts = ts / 1000.0
128128
return dt_util.dt.datetime.fromtimestamp(ts, tz=dt_util.UTC)
129-
except Exception:
130-
pass
129+
except Exception as err:
130+
_LOGGER.debug("Failed to parse numeric timestamp '%s': %s", value, err)
131131
dt = dt_util.parse_datetime(value)
132132
if dt is None:
133133
try:
@@ -325,8 +325,8 @@ async def async_start(self) -> None:
325325
):
326326
snap = self.telemetry_store.get_snapshot()
327327
self.coordinator.async_set_updated_data(snap.payload)
328-
except Exception:
329-
pass
328+
except Exception as err:
329+
_LOGGER.debug("Failed to seed local telemetry snapshot: %s", err)
330330

331331
# Watch proxy last_data changes
332332
if _async_track_state_change_event is not None:
@@ -369,8 +369,8 @@ async def async_stop(self) -> None:
369369
for unsub in self._unsubs:
370370
try:
371371
unsub()
372-
except Exception:
373-
pass
372+
except Exception as err:
373+
_LOGGER.debug("Failed to unsubscribe data source listener: %s", err)
374374
self._unsubs.clear()
375375

376376
@callback
@@ -396,8 +396,8 @@ def _on_any_state_change(self, event: Any) -> None:
396396
state = get_data_source_state(self.hass, self.entry.entry_id)
397397
if state.effective_mode == DATA_SOURCE_CLOUD_ONLY:
398398
return
399-
except Exception:
400-
pass
399+
except Exception as err:
400+
_LOGGER.debug("Failed to read data source state: %s", err)
401401

402402
entity_id = event.data.get("entity_id")
403403
if not isinstance(entity_id, str):
@@ -444,8 +444,8 @@ def _on_any_state_change(self, event: Any) -> None:
444444
def _schedule_debounced_poke(self) -> None:
445445
try:
446446
self.hass.async_create_task(self._debouncer.async_call())
447-
except Exception:
448-
pass
447+
except Exception as err:
448+
_LOGGER.debug("Failed to schedule local telemetry debounce: %s", err)
449449

450450
async def _handle_local_event(self) -> None:
451451
"""Debounced handler for local telemetry changes.
@@ -469,8 +469,8 @@ async def _handle_local_event(self) -> None:
469469
):
470470
snap = self.telemetry_store.get_snapshot()
471471
self.coordinator.async_set_updated_data(snap.payload)
472-
except Exception:
473-
pass
472+
except Exception as err:
473+
_LOGGER.debug("Failed to handle local telemetry event: %s", err)
474474

475475
@callback
476476
def _update_state(self, force: bool = False) -> tuple[bool, bool]:
@@ -611,19 +611,19 @@ def _on_effective_mode_changed(self) -> None:
611611
"reason": state.reason,
612612
},
613613
)
614-
except Exception:
615-
pass
614+
except Exception as err:
615+
_LOGGER.debug("Failed to fire data source change event: %s", err)
616616

617617
if state.effective_mode == DATA_SOURCE_CLOUD_ONLY:
618618
# Ensure cloud data is fresh when falling back
619619
try:
620620
self.hass.async_create_task(self.coordinator.async_request_refresh())
621-
except Exception:
622-
pass
621+
except Exception as err:
622+
_LOGGER.debug("Failed to schedule coordinator refresh: %s", err)
623623

624624
async def _poke_coordinator(self) -> None:
625625
try:
626626
if self.coordinator and getattr(self.coordinator, "data", None) is not None:
627627
self.coordinator.async_set_updated_data(self.coordinator.data)
628-
except Exception:
629-
pass
628+
except Exception as err:
629+
_LOGGER.debug("Failed to poke coordinator: %s", err)

custom_components/oig_cloud/oig_cloud_battery_balancing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ async def async_added_to_hass(self) -> None:
299299
if attrs.get("days_since_last") is not None:
300300
try:
301301
self._days_since_last = int(attrs.get("days_since_last"))
302-
except Exception:
303-
pass
302+
except Exception as err:
303+
_LOGGER.debug("Failed to restore days_since_last: %s", err)
304304
self._planned_window = attrs.get("planned") or self._planned_window
305305
self._cost_immediate = attrs.get(
306306
"cost_immediate_czk", self._cost_immediate
@@ -309,8 +309,8 @@ async def async_added_to_hass(self) -> None:
309309
"cost_selected_czk", self._cost_selected
310310
)
311311
self._cost_savings = attrs.get("cost_savings_czk", self._cost_savings)
312-
except Exception:
313-
pass
312+
except Exception as err:
313+
_LOGGER.debug("Failed to restore balancing state: %s", err)
314314

315315
# Initial update
316316
self._update_from_manager()

custom_components/oig_cloud/oig_cloud_battery_health_old.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,8 +1256,8 @@ def _save():
12561256
try:
12571257
cycle_id = self._generate_cycle_id(measurement.timestamp)
12581258
self._processing_cycle_ids.discard(cycle_id)
1259-
except Exception:
1260-
pass
1259+
except Exception as err:
1260+
_LOGGER.debug("Failed to clear processing cycle id: %s", err)
12611261

12621262
async def _find_data_availability_window(
12631263
self,

custom_components/oig_cloud/oig_cloud_computed_sensor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,8 @@ def _cancel_reset(self) -> None:
714714
if unsub:
715715
try:
716716
unsub()
717-
except Exception:
718-
pass
717+
except Exception as err:
718+
_LOGGER.debug(
719+
"[%s] Failed to cancel daily reset listener: %s", self.entity_id, err
720+
)
719721
self._daily_reset_unsub = None

custom_components/oig_cloud/oig_cloud_coordinator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ async def _save() -> None:
280280

281281
try:
282282
self.hass.async_create_task(_save())
283-
except Exception:
284-
pass
283+
except Exception as err:
284+
_LOGGER.debug("Failed to schedule coordinator cache save: %s", err)
285285

286286
def update_intervals(self, standard_interval: int, extended_interval: int) -> None:
287287
"""Dynamicky aktualizuje intervaly coordinatoru."""
@@ -536,8 +536,8 @@ async def _async_update_data(self) -> Dict[str, Any]: # noqa: C901
536536
try:
537537
if isinstance(stats, dict):
538538
await self._maybe_fill_config_nodes_from_cloud(stats)
539-
except Exception:
540-
pass
539+
except Exception as err:
540+
_LOGGER.debug("Failed to fill config nodes from cloud: %s", err)
541541

542542
# Cloud notifications are optional and should never run in local/hybrid effective mode.
543543
cloud_notifications_enabled = bool(

custom_components/oig_cloud/oig_cloud_data_sensor.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,22 @@ async def async_will_remove_from_hass(self) -> None:
106106
if self._local_state_unsub:
107107
try:
108108
self._local_state_unsub()
109-
except Exception:
110-
pass
109+
except Exception as err:
110+
_LOGGER.debug(
111+
"[%s] Failed to unsubscribe local state listener: %s",
112+
self.entity_id,
113+
err,
114+
)
111115
self._local_state_unsub = None
112116
if self._data_source_unsub:
113117
try:
114118
self._data_source_unsub()
115-
except Exception:
116-
pass
119+
except Exception as err:
120+
_LOGGER.debug(
121+
"[%s] Failed to unsubscribe data source listener: %s",
122+
self.entity_id,
123+
err,
124+
)
117125
self._data_source_unsub = None
118126
await super().async_will_remove_from_hass()
119127

0 commit comments

Comments
 (0)