Skip to content

Commit

Permalink
single item EventTriggerList fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-or committed Oct 21, 2024
1 parent c4d61e1 commit 7c70148
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions custom_components/hikvision_next/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
from contextlib import suppress
import logging
import traceback

from httpx import TimeoutException

Expand Down Expand Up @@ -59,12 +60,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
device_info = isapi.hass_device_info()
device_registry = dr.async_get(hass)
device_registry.async_get_or_create(config_entry_id=entry.entry_id, **device_info)
except (asyncio.TimeoutError, TimeoutException) as ex:
except (TimeoutError, TimeoutException) as ex:
raise ConfigEntryNotReady(f"Timeout while connecting to {host}. Cannot initialize {DOMAIN}") from ex
except Exception as ex: # pylint: disable=broad-except
raise ConfigEntryNotReady(
f"Unknown error connecting to {host}. Cannot initialize {DOMAIN}. Error is {ex}"
) from ex
msg = f"Cannot initialize {DOMAIN} {host}. Error: {ex}\n"
_LOGGER.error(msg + traceback.format_exc())
raise ConfigEntryNotReady(msg) from ex

coordinators = {}

Expand Down
2 changes: 2 additions & 0 deletions custom_components/hikvision_next/isapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ def get_event(event_trigger: dict):
supported_events = deep_get(event_notification, "EventTriggerList.EventTrigger", [])
else:
supported_events = deep_get(event_triggers, "EventTriggerList.EventTrigger", [])
if not isinstance(supported_events, list):
supported_events = [supported_events]

for event_trigger in supported_events:
if event := get_event(event_trigger):
Expand Down

0 comments on commit 7c70148

Please sign in to comment.