1 """Support for EufyHome lights."""
3 from __future__
import annotations
21 color_temperature_kelvin_to_mired
as kelvin_to_mired,
22 color_temperature_mired_to_kelvin
as mired_to_kelvin,
25 EUFYHOME_MAX_KELVIN = 6500
26 EUFYHOME_MIN_KELVIN = 2700
32 add_entities: AddEntitiesCallback,
33 discovery_info: DiscoveryInfoType |
None =
None,
35 """Set up EufyHome bulbs."""
36 if discovery_info
is None:
42 """Representation of a EufyHome light."""
45 """Initialize the light."""
51 self.
_name_name = device[
"name"]
53 self.
_code_code = device[
"code"]
54 self.
_type_type = device[
"type"]
57 if self.
_type_type ==
"T1011":
59 elif self.
_type_type ==
"T1012":
63 self.
_bulb_bulb.connect()
66 """Synchronise state from the bulb."""
68 if self.
_bulb_bulb.power:
71 if self.
_bulb_bulb.colors:
73 self.
_hs_hs = color_util.color_RGB_to_hs(*self.
_bulb_bulb.colors)
80 """Return the ID of this light."""
85 """Return the name of the device if any."""
86 return self.
_name_name
90 """Return true if device is on."""
95 """Return the brightness of this light between 0..255."""
100 """Return minimum supported color temperature."""
101 return kelvin_to_mired(EUFYHOME_MAX_KELVIN)
105 """Return maximum supported color temperature."""
106 return kelvin_to_mired(EUFYHOME_MIN_KELVIN)
110 """Return the color temperature of this light."""
113 + (self.
_temp_temp * (EUFYHOME_MAX_KELVIN - EUFYHOME_MIN_KELVIN) / 100)
115 return kelvin_to_mired(temp_in_k)
119 """Return the color of this light."""
124 """Return the color mode of the light."""
125 if self.
_type_type ==
"T1011":
126 return ColorMode.BRIGHTNESS
127 if self.
_type_type ==
"T1012":
128 return ColorMode.COLOR_TEMP
131 return ColorMode.COLOR_TEMP
135 """Turn the specified light on."""
136 brightness = kwargs.get(ATTR_BRIGHTNESS)
137 colortemp = kwargs.get(ATTR_COLOR_TEMP)
138 hs = kwargs.get(ATTR_HS_COLOR)
140 if brightness
is not None:
141 brightness =
int(brightness * 100 / 255)
147 if colortemp
is not None:
149 temp_in_k = mired_to_kelvin(colortemp)
150 relative_temp = temp_in_k - EUFYHOME_MIN_KELVIN
152 relative_temp * 100 / (EUFYHOME_MAX_KELVIN - EUFYHOME_MIN_KELVIN)
158 rgb = color_util.color_hsv_to_RGB(hs[0], hs[1], brightness / 255 * 100)
161 rgb = color_util.color_hsv_to_RGB(
162 self.
_hs_hs[0], self.
_hs_hs[1], brightness / 255 * 100
168 self.
_bulb_bulb.set_state(
169 power=
True, brightness=brightness, temperature=temp, colors=rgb
171 except BrokenPipeError:
172 self.
_bulb_bulb.connect()
173 self.
_bulb_bulb.set_state(
174 power=
True, brightness=brightness, temperature=temp, colors=rgb
178 """Turn the specified light off."""
180 self.
_bulb_bulb.set_state(power=
False)
181 except BrokenPipeError:
182 self.
_bulb_bulb.connect()
183 self.
_bulb_bulb.set_state(power=
False)
def __init__(self, device)
ColorMode color_mode(self)
None turn_off(self, **Any kwargs)
_attr_supported_color_modes
None turn_on(self, **Any kwargs)
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)