1 """Kuler Sky light platform."""
3 from __future__
import annotations
5 from datetime
import timedelta
24 from .const
import DATA_ADDRESSES, DATA_DISCOVERY_SUBSCRIPTION, DOMAIN
26 _LOGGER = logging.getLogger(__name__)
33 config_entry: ConfigEntry,
34 async_add_entities: AddEntitiesCallback,
36 """Set up Kuler sky light devices."""
39 """Attempt to discover new lights."""
40 lights = await pykulersky.discover()
46 if light.address
not in hass.data[DOMAIN][DATA_ADDRESSES]
50 for light
in new_lights:
51 hass.data[DOMAIN][DATA_ADDRESSES].
add(light.address)
61 hass, discover, DISCOVERY_INTERVAL
66 """Representation of a Kuler Sky Light."""
68 _attr_has_entity_name =
True
70 _attr_available =
False
71 _attr_supported_color_modes = {ColorMode.RGBW}
72 _attr_color_mode = ColorMode.RGBW
74 def __init__(self, light: pykulersky.Light) ->
None:
75 """Initialize a Kuler Sky light."""
79 identifiers={(DOMAIN, light.address)},
80 manufacturer=
"Brightech",
85 """Run when entity about to be added to hass."""
87 self.
hasshass.bus.async_listen_once(
93 """Run when entity will be removed from hass."""
95 await self.
_light_light.disconnect()
96 except pykulersky.PykulerskyException:
98 "Exception disconnected from %s", self.
_light_light.address, exc_info=
True
103 """Return true if light is on."""
107 """Instruct the light to turn on."""
109 rgbw = kwargs.get(ATTR_RGBW_COLOR, default_rgbw)
112 brightness = kwargs.get(ATTR_BRIGHTNESS, default_brightness)
114 if brightness == 0
and not kwargs:
120 rgbw_scaled = [round(x * brightness / 255)
for x
in rgbw]
122 await self.
_light_light.set_color(*rgbw_scaled)
125 """Instruct the light to turn off."""
126 await self.
_light_light.set_color(0, 0, 0, 0)
129 """Fetch new state data for this light."""
132 await self.
_light_light.connect()
133 rgbw = await self.
_light_light.get_color()
134 except pykulersky.PykulerskyException
as exc:
136 _LOGGER.warning(
"Unable to connect to %s: %s", self.
_light_light.address, exc)
140 _LOGGER.warning(
"Reconnected to %s", self.
_light_light.address)
143 brightness =
max(rgbw)
147 rgbw_normalized = [round(x * 255 / brightness)
for x
in rgbw]
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_added_to_hass(self)
None __init__(self, pykulersky.Light light)
None async_will_remove_from_hass(self, *args)
int|None brightness(self)
tuple[int, int, int, int]|None rgbw_color(self)
None async_will_remove_from_hass(self)
None async_on_remove(self, CALLBACK_TYPE func)
bool add(self, _T matcher)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
list[tuple[str, int]] discover(HomeAssistant hass)
CALLBACK_TYPE async_track_time_interval(HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, timedelta interval, *str|None name=None, bool|None cancel_on_shutdown=None)