1 """Support for lights under the iGlo brand."""
3 from __future__
import annotations
9 from iglo.lamp
import MODE_WHITE
10 import voluptuous
as vol
17 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
29 DEFAULT_NAME =
"iGlo Light"
32 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
34 vol.Required(CONF_HOST): cv.string,
35 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
36 vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
44 add_entities: AddEntitiesCallback,
45 discovery_info: DiscoveryInfoType |
None =
None,
47 """Set up the iGlo lights."""
48 host = config.get(CONF_HOST)
49 name = config.get(CONF_NAME)
50 port = config.get(CONF_PORT)
55 """Representation of an iGlo light."""
57 _attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS}
58 _attr_supported_features = LightEntityFeature.EFFECT
61 """Initialize the light."""
64 self.
_lamp_lamp = Lamp(0, host, port)
68 """Return the name of the light."""
69 return self.
_name_name
73 """Return the brightness of this light between 0..255."""
74 return int((self.
_lamp_lamp.
state()[
"brightness"] / 200.0) * 255)
78 """Return the color mode of the light."""
79 if self.
_lamp_lamp.
state()[
"mode"] == MODE_WHITE:
80 return ColorMode.COLOR_TEMP
87 """Return the color temperature."""
88 return color_util.color_temperature_kelvin_to_mired(self.
_lamp_lamp.
state()[
"white"])
92 """Return the coldest color_temp that this light supports."""
94 color_util.color_temperature_kelvin_to_mired(self.
_lamp_lamp.max_kelvin)
99 """Return the warmest color_temp that this light supports."""
101 color_util.color_temperature_kelvin_to_mired(self.
_lamp_lamp.min_kelvin)
106 """Return the hs value."""
107 return color_util.color_RGB_to_hs(*self.
_lamp_lamp.
state()[
"rgb"])
111 """Return the current effect."""
116 """Return the list of supported effects."""
121 """Return true if light is on."""
125 """Turn the light on."""
127 self.
_lamp_lamp.switch(
True)
128 if ATTR_BRIGHTNESS
in kwargs:
129 brightness =
int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0)
133 if ATTR_HS_COLOR
in kwargs:
134 rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
135 self.
_lamp_lamp.rgb(*rgb)
138 if ATTR_COLOR_TEMP
in kwargs:
140 color_util.color_temperature_mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])
142 self.
_lamp_lamp.white(kelvin)
145 if ATTR_EFFECT
in kwargs:
146 effect = kwargs[ATTR_EFFECT]
151 """Turn the light off."""
152 self.
_lamp_lamp.switch(
False)
def __init__(self, name, host, port)
ColorMode color_mode(self)
None turn_on(self, **Any kwargs)
None turn_off(self, **Any kwargs)
Literal["on", "off"]|None state(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)