from typing import Any import flickerstrip_py as flstrp from homeassistant.core import HomeAssistant from homeassistant.components.light import ( ATTR_BRIGHTNESS, LightEntity, ) from .const import ( DEFAULT_PORT, ) class Flickerstrip(LightEntity): """Flickerstrip class.""" def __init__( self, hass: HomeAssistant, host: str, port: int = DEFAULT_PORT, ): self.hass = hass self.host = host self.port = port self._flickerstrip = flstrp.Flickerstrip(host) @property def name(self) -> str: """Return the display name of this light.""" return self._name @property def brightness(self): """Return the brightness of the light.""" return self._flickerstrip.status.brightness @property def is_on(self) -> bool | None: """Return true if light is on.""" return self._flickerstrip.status.power def turn_on(self, **kwargs: Any) -> None: """Instruct the light to turn on.""" brightness = kwargs.get(ATTR_BRIGHTNESS, 100) self._flickerstrip.set_brightness(brightness) self._flickerstrip.power_on() def turn_off(self, **kwargs: Any) -> None: """Instruct the light to turn off.""" self._flickerstrip.power_off() def update(self) -> None: """Fetch new state data for this light. This is the only method that should fetch new data for Home Assistant. """ self._flickerstrip.force_update()