"""sACN-Schalter eines ninstrip-Geraets.""" from __future__ import annotations from typing import Any from homeassistant.components.switch import SwitchEntity from homeassistant.const import EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .coordinator import NinstripConfigEntry, NinstripCoordinator from .entity import NinstripSacnEntity PARALLEL_UPDATES = 0 async def async_setup_entry( hass: HomeAssistant, entry: NinstripConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: async_add_entities([NinstripSacnSwitch(entry.runtime_data)]) class NinstripSacnSwitch(NinstripSacnEntity, SwitchEntity): """Ob das Geraet ueberhaupt auf sACN/E1.31 hoert. Abschalten holt dem Strom auch die Kontrolle ab - bei on_timeout "hold" bliebe sonst das letzte Bild stehen. Die Firmware erledigt das selbst. """ _attr_entity_category = EntityCategory.CONFIG _attr_translation_key = "sacn_enabled" def __init__(self, coordinator: NinstripCoordinator) -> None: super().__init__(coordinator, "sacn_enabled") @property def is_on(self) -> bool: return bool(self.sacn.get("enabled")) async def async_turn_on(self, **kwargs: Any) -> None: await self.coordinator.async_set_sacn(enabled=True) async def async_turn_off(self, **kwargs: Any) -> None: await self.coordinator.async_set_sacn(enabled=False)