1 """Support for MySensors lights."""
3 from __future__
import annotations
5 from typing
import Any, cast
21 from .
import setup_mysensors_platform
22 from .const
import MYSENSORS_DISCOVERY, DiscoveryInfo, SensorType
23 from .entity
import MySensorsChildEntity
24 from .helpers
import on_unload
29 config_entry: ConfigEntry,
30 async_add_entities: AddEntitiesCallback,
32 """Set up this platform for a specific ConfigEntry(==Gateway)."""
33 device_class_map: dict[SensorType, type[MySensorsChildEntity]] = {
34 "S_DIMMER": MySensorsLightDimmer,
35 "S_RGB_LIGHT": MySensorsLightRGB,
36 "S_RGBW_LIGHT": MySensorsLightRGBW,
40 """Discover and add a MySensors light."""
46 async_add_entities=async_add_entities,
51 config_entry.entry_id,
54 MYSENSORS_DISCOVERY.format(config_entry.entry_id, Platform.LIGHT),
61 """Representation of a MySensors Light child node."""
64 """Initialize a MySensors Light."""
66 self.
_state_state: bool |
None =
None
70 """Return true if device is on."""
74 """Turn on light child device."""
75 set_req = self.gateway.const.SetReq
79 self.gateway.set_child_value(
80 self.node_id, self.child_id, set_req.V_LIGHT, 1, ack=1
86 self._values[set_req.V_LIGHT] = STATE_ON
89 """Turn on dimmer child device."""
90 set_req = self.gateway.const.SetReq
93 ATTR_BRIGHTNESS
not in kwargs
95 or set_req.V_DIMMER
not in self._values
98 brightness: int = kwargs[ATTR_BRIGHTNESS]
99 percent = round(100 * brightness / 255)
100 self.gateway.set_child_value(
101 self.node_id, self.child_id, set_req.V_DIMMER, percent, ack=1
107 self._values[set_req.V_DIMMER] = percent
110 """Turn the device off."""
111 value_type = self.gateway.const.SetReq.V_LIGHT
112 self.gateway.set_child_value(self.node_id, self.child_id, value_type, 0, ack=1)
116 self._values[value_type] = STATE_OFF
121 """Update the controller with values from light child."""
122 value_type = self.gateway.const.SetReq.V_LIGHT
123 self.
_state_state = self._values[value_type] == STATE_ON
127 """Update the controller with values from dimmer child."""
128 value_type = self.gateway.const.SetReq.V_DIMMER
129 if value_type
in self._values:
136 """Dimmer child class to MySensorsLight."""
138 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
139 _attr_color_mode = ColorMode.BRIGHTNESS
142 """Turn the device on."""
150 """Update the controller with the latest value from a sensor."""
157 """RGB child class to MySensorsLight."""
159 _attr_supported_color_modes = {ColorMode.RGB}
160 _attr_color_mode = ColorMode.RGB
163 """Turn the device on."""
171 """Turn on RGB child device."""
172 hex_color = self._values.
get(self.value_type)
173 new_rgb: tuple[int, int, int] |
None = kwargs.get(ATTR_RGB_COLOR)
176 red, green, blue = new_rgb
177 hex_color = f
"{red:02x}{green:02x}{blue:02x}"
178 self.gateway.set_child_value(
179 self.node_id, self.child_id, self.value_type, hex_color, ack=1
185 self._values[self.value_type] = hex_color
189 """Update the controller with the latest value from a sensor."""
197 """Update the controller with values from RGB child."""
198 value = self._values[self.value_type]
205 """RGBW child class to MySensorsLightRGB."""
207 _attr_supported_color_modes = {ColorMode.RGBW}
208 _attr_color_mode = ColorMode.RGBW
211 """Turn the device on."""
219 """Turn on RGBW child device."""
220 hex_color = self._values.
get(self.value_type)
221 new_rgbw: tuple[int, int, int, int] |
None = kwargs.get(ATTR_RGBW_COLOR)
224 red, green, blue, white = new_rgbw
225 hex_color = f
"{red:02x}{green:02x}{blue:02x}{white:02x}"
226 self.gateway.set_child_value(
227 self.node_id, self.child_id, self.value_type, hex_color, ack=1
233 self._values[self.value_type] = hex_color
237 """Update the controller with values from RGBW child."""
238 value = self._values[self.value_type]
None async_turn_on(self, **Any kwargs)
None _turn_on_rgbw(self, **Any kwargs)
None _async_update_rgb_or_w(self)
None async_turn_on(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None _turn_on_rgb(self, **Any kwargs)
None _async_update_rgb_or_w(self)
None _async_update_dimmer(self)
None _turn_on_light(self)
None _async_update_light(self)
None __init__(self, *Any args)
None _turn_on_dimmer(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_write_ha_state(self)
web.Response get(self, web.Request request, str config_key)
None on_unload(HomeAssistant hass, GatewayId gateway_id, Callable fnct)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None async_discover(DiscoveryInfo discovery_info)
list[MySensorsChildEntity]|None setup_mysensors_platform(HomeAssistant hass, Platform domain, DiscoveryInfo discovery_info, type[MySensorsChildEntity]|Mapping[SensorType, type[MySensorsChildEntity]] device_class,(tuple|None) device_args=None, Callable|None async_add_entities=None)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
list[int] rgb_hex_to_rgb_list(str hex_string)