Use shorthand attributes in Plum (#99770)
Use shorthand attributes in Plum shorthand
This commit is contained in:
parent
61b02e9c66
commit
3afdecd51f
1 changed files with 20 additions and 54 deletions
|
@ -73,6 +73,14 @@ class PlumLight(LightEntity):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self._load = load
|
self._load = load
|
||||||
self._brightness = load.level
|
self._brightness = load.level
|
||||||
|
unique_id = f"{load.llid}.light"
|
||||||
|
self._attr_unique_id = unique_id
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, unique_id)},
|
||||||
|
manufacturer="Plum",
|
||||||
|
model="Dimmer",
|
||||||
|
name=load.name,
|
||||||
|
)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to dimmerchange events."""
|
"""Subscribe to dimmerchange events."""
|
||||||
|
@ -83,21 +91,6 @@ class PlumLight(LightEntity):
|
||||||
self._brightness = event["level"]
|
self._brightness = event["level"]
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Combine logical load ID with .light to guarantee it is unique."""
|
|
||||||
return f"{self._load.llid}.light"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return the device info."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self.unique_id)},
|
|
||||||
manufacturer="Plum",
|
|
||||||
model="Dimmer",
|
|
||||||
name=self._load.name,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self) -> int:
|
def brightness(self) -> int:
|
||||||
"""Return the brightness of this switch between 0..255."""
|
"""Return the brightness of this switch between 0..255."""
|
||||||
|
@ -138,18 +131,27 @@ class GlowRing(LightEntity):
|
||||||
_attr_color_mode = ColorMode.HS
|
_attr_color_mode = ColorMode.HS
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
_attr_supported_color_modes = {ColorMode.HS}
|
_attr_supported_color_modes = {ColorMode.HS}
|
||||||
|
_attr_icon = "mdi:crop-portrait"
|
||||||
|
|
||||||
def __init__(self, lightpad):
|
def __init__(self, lightpad):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
self._lightpad = lightpad
|
self._lightpad = lightpad
|
||||||
self._name = f"{lightpad.friendly_name} Glow Ring"
|
self._attr_name = f"{lightpad.friendly_name} Glow Ring"
|
||||||
|
|
||||||
self._state = lightpad.glow_enabled
|
self._attr_is_on = lightpad.glow_enabled
|
||||||
self._glow_intensity = lightpad.glow_intensity
|
self._glow_intensity = lightpad.glow_intensity
|
||||||
|
unique_id = f"{self._lightpad.lpid}.glow"
|
||||||
|
self._attr_unique_id = unique_id
|
||||||
|
|
||||||
self._red = lightpad.glow_color["red"]
|
self._red = lightpad.glow_color["red"]
|
||||||
self._green = lightpad.glow_color["green"]
|
self._green = lightpad.glow_color["green"]
|
||||||
self._blue = lightpad.glow_color["blue"]
|
self._blue = lightpad.glow_color["blue"]
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, unique_id)},
|
||||||
|
manufacturer="Plum",
|
||||||
|
model="Glow Ring",
|
||||||
|
name=self._attr_name,
|
||||||
|
)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to configchange events."""
|
"""Subscribe to configchange events."""
|
||||||
|
@ -159,13 +161,12 @@ class GlowRing(LightEntity):
|
||||||
"""Handle Configuration change event."""
|
"""Handle Configuration change event."""
|
||||||
config = event["changes"]
|
config = event["changes"]
|
||||||
|
|
||||||
self._state = config["glowEnabled"]
|
self._attr_is_on = config["glowEnabled"]
|
||||||
self._glow_intensity = config["glowIntensity"]
|
self._glow_intensity = config["glowIntensity"]
|
||||||
|
|
||||||
self._red = config["glowColor"]["red"]
|
self._red = config["glowColor"]["red"]
|
||||||
self._green = config["glowColor"]["green"]
|
self._green = config["glowColor"]["green"]
|
||||||
self._blue = config["glowColor"]["blue"]
|
self._blue = config["glowColor"]["blue"]
|
||||||
|
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -173,46 +174,11 @@ class GlowRing(LightEntity):
|
||||||
"""Return the hue and saturation color value [float, float]."""
|
"""Return the hue and saturation color value [float, float]."""
|
||||||
return color_util.color_RGB_to_hs(self._red, self._green, self._blue)
|
return color_util.color_RGB_to_hs(self._red, self._green, self._blue)
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Combine LightPad ID with .glow to guarantee it is unique."""
|
|
||||||
return f"{self._lightpad.lpid}.glow"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the switch if any."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return the device info."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self.unique_id)},
|
|
||||||
manufacturer="Plum",
|
|
||||||
model="Glow Ring",
|
|
||||||
name=self.name,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self) -> int:
|
def brightness(self) -> int:
|
||||||
"""Return the brightness of this switch between 0..255."""
|
"""Return the brightness of this switch between 0..255."""
|
||||||
return min(max(int(round(self._glow_intensity * 255, 0)), 0), 255)
|
return min(max(int(round(self._glow_intensity * 255, 0)), 0), 255)
|
||||||
|
|
||||||
@property
|
|
||||||
def glow_intensity(self):
|
|
||||||
"""Brightness in float form."""
|
|
||||||
return self._glow_intensity
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self) -> bool:
|
|
||||||
"""Return true if light is on."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the crop-portrait icon representing the glow ring."""
|
|
||||||
return "mdi:crop-portrait"
|
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the light on."""
|
"""Turn the light on."""
|
||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
|
|
Loading…
Add table
Reference in a new issue