"""Power-on behaviour of a ninlight lamp.""" from __future__ import annotations from homeassistant.components.select import SelectEntity 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 # POB_NAMES in the firmware's nl_api.c POWER_ON_OPTIONS = ["last", "on", "off"] async def async_setup_entry( hass: HomeAssistant, entry: NinlightConfigEntry, async_add_entities: AddConfigEntryEntitiesCallback, ) -> None: async_add_entities([NinlightPowerOnSelect(entry.runtime_data)]) class NinlightPowerOnSelect(NinlightEntity, SelectEntity): """What the lamp does when power returns.""" _attr_entity_category = EntityCategory.CONFIG _attr_translation_key = "power_on_behaviour" _attr_options = POWER_ON_OPTIONS def __init__(self, coordinator: NinlightCoordinator) -> None: super().__init__(coordinator, "power_on_behaviour") @property def current_option(self) -> str | None: value = self.coordinator.data.state.get("power_on_behaviour") return value if value in POWER_ON_OPTIONS else None async def async_select_option(self, option: str) -> None: await self.coordinator.async_set_state(power_on_behaviour=option)