diff --git a/custom_components/hikvision_next/coordinator.py b/custom_components/hikvision_next/coordinator.py index 5996d0f..72dc854 100644 --- a/custom_components/hikvision_next/coordinator.py +++ b/custom_components/hikvision_next/coordinator.py @@ -45,8 +45,8 @@ async def _async_update_data(self): if event.disabled: continue try: - entity_id = ENTITY_ID_FORMAT.format(event.unique_id) - data[entity_id] = await self.isapi.get_event_enabled_state(event) + _id = ENTITY_ID_FORMAT.format(event.unique_id) + data[_id] = await self.isapi.get_event_enabled_state(event) except Exception as ex: # pylint: disable=broad-except self.isapi.handle_exception(ex, f"Cannot fetch state for {event.id}") @@ -55,18 +55,18 @@ async def _async_update_data(self): if event.disabled: continue try: - entity_id = ENTITY_ID_FORMAT.format(event.unique_id) - data[entity_id] = await self.isapi.get_event_enabled_state(event) + _id = ENTITY_ID_FORMAT.format(event.unique_id) + data[_id] = await self.isapi.get_event_enabled_state(event) except Exception as ex: # pylint: disable=broad-except self.isapi.handle_exception(ex, f"Cannot fetch state for {event.id}") # Get output port(s) status for i in range(1, self.isapi.device_info.output_ports + 1): try: - entity_id = ENTITY_ID_FORMAT.format( + _id = ENTITY_ID_FORMAT.format( f"{slugify(self.isapi.device_info.serial_no.lower())}_{i}_alarm_output" ) - data[entity_id] = await self.isapi.get_port_status("output", i) + data[_id] = await self.isapi.get_port_status("output", i) except Exception as ex: # pylint: disable=broad-except self.isapi.handle_exception(ex, f"Cannot fetch state for alarm output {i}") diff --git a/custom_components/hikvision_next/switch.py b/custom_components/hikvision_next/switch.py index c135ce0..8ce2baa 100644 --- a/custom_components/hikvision_next/switch.py +++ b/custom_components/hikvision_next/switch.py @@ -13,10 +13,10 @@ from .const import ( DOMAIN, + EVENT_IO, EVENTS_COORDINATOR, HOLIDAY_MODE, SECONDARY_COORDINATOR, - EVENT_IO, ) from .isapi import EventInfo @@ -73,7 +73,7 @@ def __init__(self, device_id: int, event: EventInfo, coordinator) -> None: @property def is_on(self) -> bool | None: """Return True if the binary sensor is on.""" - return self.coordinator.data.get(self.entity_id) + return self.coordinator.data.get(self.unique_id) async def async_turn_on(self, **kwargs: Any) -> None: """Turn on.""" @@ -93,6 +93,7 @@ async def async_turn_off(self, **kwargs: Any) -> None: finally: await self.coordinator.async_request_refresh() + class NVROutputSwitch(CoordinatorEntity, SwitchEntity): """Detection events switch.""" @@ -114,7 +115,7 @@ def __init__(self, coordinator, port_no: int) -> None: @property def is_on(self) -> bool | None: """Turn on.""" - return self.coordinator.data.get(self.entity_id) == "active" + return self.coordinator.data.get(self.unique_id) == "active" async def async_turn_on(self, **kwargs: Any) -> None: """Turn on."""