"""Wake-on-change switch of a ninlight lamp.""" 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 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([NinlightWakeSwitch(entry.runtime_data)]) class NinlightWakeSwitch(NinlightEntity, SwitchEntity): """Turn the lamp on when its colour, temperature or brightness is changed.""" _attr_entity_category = EntityCategory.CONFIG _attr_translation_key = "wake_on_change" def __init__(self, coordinator: NinlightCoordinator) -> None: super().__init__(coordinator, "wake_on_change") @property def is_on(self) -> bool: return bool(self.coordinator.data.state.get("wake_on_change")) async def async_turn_on(self, **kwargs: Any) -> None: await self.coordinator.async_set_state(wake_on_change=True) async def async_turn_off(self, **kwargs: Any) -> None: await self.coordinator.async_set_state(wake_on_change=False)