"""Diagnostic binary sensors of a ninlight lamp: the sACN receiver's state.""" from __future__ import annotations from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .coordinator import NinlightConfigEntry, NinlightCoordinator from .entity import NinlightEntity PARALLEL_UPDATES = 0 async def async_setup_entry( hass: HomeAssistant, entry: NinlightConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: async_add_entities( [NinlightSacnActive(entry.runtime_data), NinlightSacnMulticast(entry.runtime_data)] ) class _NinlightSacnInfo(NinlightEntity, BinarySensorEntity): """Base for the two flags the lamp reports under system/info -> sacn.""" _attr_entity_category = EntityCategory.DIAGNOSTIC _field: str @property def available(self) -> bool: return super().available and self.coordinator.data.sacn_info is not None @property def is_on(self) -> bool: return bool((self.coordinator.data.sacn_info or {}).get(self._field)) class NinlightSacnActive(_NinlightSacnInfo): """True while a controller is driving the lamp.""" _attr_translation_key = "sacn_active" _field = "active" def __init__(self, coordinator: NinlightCoordinator) -> None: super().__init__(coordinator, "sacn_active") class NinlightSacnMulticast(_NinlightSacnInfo): """True when the lamp joined the multicast group of its universe. Off by default like the other diagnostics: it reads "true" in normal operation and only earns its place when multicast does not arrive. It is worth having - a wrong group address once cost two evenings of searching, and this flag is where that shows. """ _attr_translation_key = "sacn_multicast" _attr_entity_registry_enabled_default = False _field = "multicast" def __init__(self, coordinator: NinlightCoordinator) -> None: super().__init__(coordinator, "sacn_multicast")