mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Use entity class attributes for Blinksticklight (#52892)
* Use entity class attributes for blinksticklight * rework * remove self._serial
This commit is contained in:
parent
13c142a402
commit
12555d09d6
@ -42,57 +42,33 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
class BlinkStickLight(LightEntity):
|
||||
"""Representation of a BlinkStick light."""
|
||||
|
||||
_attr_supported_features = SUPPORT_BLINKSTICK
|
||||
|
||||
def __init__(self, stick, name):
|
||||
"""Initialize the light."""
|
||||
self._stick = stick
|
||||
self._name = name
|
||||
self._serial = stick.get_serial()
|
||||
self._hs_color = None
|
||||
self._brightness = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the light."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
"""Read back the brightness of the light."""
|
||||
return self._brightness
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
"""Read back the color of the light."""
|
||||
return self._hs_color
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return True if entity is on."""
|
||||
return self._brightness > 0
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_BLINKSTICK
|
||||
self._attr_name = name
|
||||
|
||||
def update(self):
|
||||
"""Read back the device state."""
|
||||
rgb_color = self._stick.get_color()
|
||||
hsv = color_util.color_RGB_to_hsv(*rgb_color)
|
||||
self._hs_color = hsv[:2]
|
||||
self._brightness = hsv[2]
|
||||
self._attr_hs_color = hsv[:2]
|
||||
self._attr_brightness = hsv[2]
|
||||
self._attr_is_on = self.brightness > 0
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
self._hs_color = kwargs[ATTR_HS_COLOR]
|
||||
self._attr_hs_color = kwargs[ATTR_HS_COLOR]
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
self._brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
self._attr_brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
else:
|
||||
self._brightness = 255
|
||||
self._attr_brightness = 255
|
||||
self._attr_is_on = self.brightness > 0
|
||||
|
||||
rgb_color = color_util.color_hsv_to_RGB(
|
||||
self._hs_color[0], self._hs_color[1], self._brightness / 255 * 100
|
||||
self.hs_color[0], self.hs_color[1], self.brightness / 255 * 100
|
||||
)
|
||||
self._stick.set_color(red=rgb_color[0], green=rgb_color[1], blue=rgb_color[2])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user