1 """Support for Plum Lightpad lights."""
3 from __future__
import annotations
7 from plumlightpad
import Plum
22 from .const
import DOMAIN
28 async_add_entities: AddEntitiesCallback,
30 """Set up Plum Lightpad dimmer lights and glow rings."""
32 plum: Plum = hass.data[DOMAIN][entry.entry_id]
34 def setup_entities(device) -> None:
35 entities: list[LightEntity] = []
38 lightpad = plum.get_lightpad(device[
"lpid"])
39 entities.append(
GlowRing(lightpad=lightpad))
42 logical_load = plum.get_load(device[
"llid"])
43 entities.append(
PlumLight(load=logical_load))
47 async
def new_load(device):
48 setup_entities(device)
50 async
def new_lightpad(device):
51 setup_entities(device)
54 entry.async_create_background_task(
58 loadListener=new_load,
59 lightpadListener=new_lightpad,
60 websession=device_web_session,
62 "plum.light-discover",
67 """Representation of a Plum Lightpad dimmer."""
69 _attr_should_poll =
False
70 _attr_has_entity_name =
True
74 """Initialize the light."""
77 unique_id = f
"{load.llid}.light"
80 identifiers={(DOMAIN, unique_id)},
87 """Subscribe to dimmerchange events."""
91 """Change event handler updating the brightness."""
97 """Return the brightness of this switch between 0..255."""
102 """Return true if light is on."""
107 """Flag supported features."""
108 if self.
_load_load.dimmable:
109 return ColorMode.BRIGHTNESS
110 return ColorMode.ONOFF
114 """Flag supported color modes."""
118 """Turn the light on."""
119 if ATTR_BRIGHTNESS
in kwargs:
125 """Turn the light off."""
130 """Representation of a Plum Lightpad dimmer glow ring."""
132 _attr_color_mode = ColorMode.HS
133 _attr_should_poll =
False
134 _attr_translation_key =
"glow_ring"
135 _attr_supported_color_modes = {ColorMode.HS}
138 """Initialize the light."""
140 self.
_attr_name_attr_name = f
"{lightpad.friendly_name} Glow Ring"
144 unique_id = f
"{self._lightpad.lpid}.glow"
147 self.
_red_red = lightpad.glow_color[
"red"]
148 self.
_green_green = lightpad.glow_color[
"green"]
149 self.
_blue_blue = lightpad.glow_color[
"blue"]
151 identifiers={(DOMAIN, unique_id)},
158 """Subscribe to configchange events."""
162 """Handle Configuration change event."""
163 config = event[
"changes"]
165 self.
_attr_is_on_attr_is_on = config[
"glowEnabled"]
168 self.
_red_red = config[
"glowColor"][
"red"]
169 self.
_green_green = config[
"glowColor"][
"green"]
170 self.
_blue_blue = config[
"glowColor"][
"blue"]
175 """Return the hue and saturation color value [float, float]."""
176 return color_util.color_RGB_to_hs(self.
_red_red, self.
_green_green, self.
_blue_blue)
180 """Return the brightness of this switch between 0..255."""
184 """Turn the light on."""
185 if ATTR_BRIGHTNESS
in kwargs:
186 brightness_pct = kwargs[ATTR_BRIGHTNESS] / 255.0
187 await self.
_lightpad_lightpad.set_config({
"glowIntensity": brightness_pct})
188 elif ATTR_HS_COLOR
in kwargs:
189 hs_color = kwargs[ATTR_HS_COLOR]
190 red, green, blue = color_util.color_hs_to_RGB(*hs_color)
191 await self.
_lightpad_lightpad.set_glow_color(red, green, blue, 0)
193 await self.
_lightpad_lightpad.set_config({
"glowEnabled":
True})
196 """Turn the light off."""
197 if ATTR_BRIGHTNESS
in kwargs:
198 brightness_pct = kwargs[ATTR_BRIGHTNESS] / 255.0
199 await self.
_lightpad_lightpad.set_config({
"glowIntensity": brightness_pct})
201 await self.
_lightpad_lightpad.set_config({
"glowEnabled":
False})
ColorMode|str|None color_mode(self)
def __init__(self, lightpad)
def configchange_event(self, event)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_added_to_hass(self)
def dimmerchange(self, event)
None async_added_to_hass(self)
None async_turn_on(self, **Any kwargs)
set[ColorMode] supported_color_modes(self)
ColorMode color_mode(self)
None async_turn_off(self, **Any kwargs)
None schedule_update_ha_state(self, bool force_refresh=False)
None turn_off(self, **Any kwargs)
None turn_on(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)