1 """Support for WiLight lights."""
3 from __future__
import annotations
7 from pywilight.const
import ITEM_LIGHT, LIGHT_COLOR, LIGHT_DIMMER, LIGHT_ON_OFF
8 from pywilight.wilight_device
import PyWiLightDevice
20 from .const
import DOMAIN
21 from .entity
import WiLightDevice
22 from .parent_device
import WiLightParent
26 """Parse configuration and add WiLight light entities."""
27 entities: list[LightEntity] = []
28 for item
in api_device.items:
29 if item[
"type"] != ITEM_LIGHT:
32 item_name = item[
"name"]
33 if item[
"sub_type"] == LIGHT_ON_OFF:
35 elif item[
"sub_type"] == LIGHT_DIMMER:
37 elif item[
"sub_type"] == LIGHT_COLOR:
44 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
46 """Set up WiLight lights from a config entry."""
47 parent: WiLightParent = hass.data[DOMAIN][entry.entry_id]
56 """Representation of a WiLights light on-off."""
59 _attr_color_mode = ColorMode.ONOFF
60 _attr_supported_color_modes = {ColorMode.ONOFF}
64 """Return true if device is on."""
68 """Turn the device on."""
72 """Turn the device off."""
77 """Representation of a WiLights light dimmer."""
80 _attr_color_mode = ColorMode.BRIGHTNESS
81 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
85 """Return the brightness of this light between 0..255."""
90 """Return true if device is on."""
94 """Turn the device on,set brightness if needed."""
97 if ATTR_BRIGHTNESS
in kwargs:
98 brightness = kwargs[ATTR_BRIGHTNESS]
99 await self.
_client_client.set_brightness(self.
_index_index, brightness)
104 """Turn the device off."""
109 """Convert wilight hue 1..255 to hass 0..360 scale."""
110 return min(360, round((value * 360) / 255, 3))
114 """Convert hass hue 0..360 to wilight 1..255 scale."""
115 return min(255, round((value * 255) / 360))
119 """Convert wilight saturation 1..255 to hass 0..100 scale."""
120 return min(100, round((value * 100) / 255, 3))
124 """Convert hass saturation 0..100 to wilight 1..255 scale."""
125 return min(255, round((value * 255) / 100))
129 """Representation of a WiLights light rgb."""
132 _attr_color_mode = ColorMode.HS
133 _attr_supported_color_modes = {ColorMode.HS}
137 """Return the brightness of this light between 0..255."""
142 """Return the hue and saturation color value [float, float]."""
150 """Return true if device is on."""
154 """Turn the device on,set brightness if needed."""
158 if ATTR_BRIGHTNESS
in kwargs
and ATTR_HS_COLOR
in kwargs:
159 brightness = kwargs[ATTR_BRIGHTNESS]
162 await self.
_client_client.set_hsb_color(self.
_index_index, hue, saturation, brightness)
163 elif ATTR_BRIGHTNESS
in kwargs
and ATTR_HS_COLOR
not in kwargs:
164 brightness = kwargs[ATTR_BRIGHTNESS]
165 await self.
_client_client.set_brightness(self.
_index_index, brightness)
166 elif ATTR_BRIGHTNESS
not in kwargs
and ATTR_HS_COLOR
in kwargs:
169 await self.
_client_client.set_hs_color(self.
_index_index, hue, saturation)
174 """Turn the device off."""
None async_turn_off(self, **Any kwargs)
tuple[float, float] hs_color(self)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
web.Response get(self, web.Request request, str config_key)
list[LightEntity] entities_from_discovered_wilight(PyWiLightDevice api_device)
float wilight_to_hass_hue(int value)
float wilight_to_hass_saturation(int value)
int hass_to_wilight_hue(float value)
int hass_to_wilight_saturation(float value)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)