Add color mode support to zengge light (#55260)
parent
be7fc35dfa
commit
044d71f016
|
@ -9,11 +9,10 @@ from zengge import zengge
|
|||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_WHITE_VALUE,
|
||||
ATTR_WHITE,
|
||||
COLOR_MODE_HS,
|
||||
COLOR_MODE_WHITE,
|
||||
PLATFORM_SCHEMA,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_COLOR,
|
||||
SUPPORT_WHITE_VALUE,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.const import CONF_DEVICES, CONF_NAME
|
||||
|
@ -25,8 +24,6 @@ import homeassistant.util.color as color_util
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SUPPORT_ZENGGE_LED = SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_WHITE_VALUE
|
||||
|
||||
DEVICE_SCHEMA = vol.Schema({vol.Optional(CONF_NAME): cv.string})
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
@ -103,20 +100,27 @@ class ZenggeLight(LightEntity):
|
|||
return self._white
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_ZENGGE_LED
|
||||
def color_mode(self):
|
||||
"""Return the current color mode."""
|
||||
if self._white != 0:
|
||||
return COLOR_MODE_WHITE
|
||||
return COLOR_MODE_HS
|
||||
|
||||
@property
|
||||
def supported_color_modes(self):
|
||||
"""Flag supported color modes."""
|
||||
return {COLOR_MODE_HS, COLOR_MODE_WHITE}
|
||||
|
||||
@property
|
||||
def assumed_state(self):
|
||||
"""We can report the actual state."""
|
||||
return False
|
||||
|
||||
def set_rgb(self, red, green, blue):
|
||||
def _set_rgb(self, red, green, blue):
|
||||
"""Set the rgb state."""
|
||||
return self._bulb.set_rgb(red, green, blue)
|
||||
|
||||
def set_white(self, white):
|
||||
def _set_white(self, white):
|
||||
"""Set the white state."""
|
||||
return self._bulb.set_white(white)
|
||||
|
||||
|
@ -126,28 +130,29 @@ class ZenggeLight(LightEntity):
|
|||
self._bulb.on()
|
||||
|
||||
hs_color = kwargs.get(ATTR_HS_COLOR)
|
||||
white = kwargs.get(ATTR_WHITE_VALUE)
|
||||
white = kwargs.get(ATTR_WHITE)
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
|
||||
if white is not None:
|
||||
self._white = white
|
||||
# Change the bulb to white
|
||||
self._brightness = self._white = white
|
||||
self._hs_color = (0, 0)
|
||||
|
||||
if hs_color is not None:
|
||||
# Change the bulb to hs
|
||||
self._white = 0
|
||||
self._hs_color = hs_color
|
||||
|
||||
if brightness is not None:
|
||||
self._white = 0
|
||||
self._brightness = brightness
|
||||
|
||||
if self._white != 0:
|
||||
self.set_white(self._white)
|
||||
self._set_white(self._brightness)
|
||||
else:
|
||||
rgb = color_util.color_hsv_to_RGB(
|
||||
self._hs_color[0], self._hs_color[1], self._brightness / 255 * 100
|
||||
)
|
||||
self.set_rgb(*rgb)
|
||||
self._set_rgb(*rgb)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the specified light off."""
|
||||
|
@ -161,4 +166,6 @@ class ZenggeLight(LightEntity):
|
|||
self._hs_color = hsv[:2]
|
||||
self._brightness = (hsv[2] / 100) * 255
|
||||
self._white = self._bulb.get_white()
|
||||
if self._white:
|
||||
self._brightness = self._white
|
||||
self._state = self._bulb.get_on()
|
||||
|
|
Loading…
Reference in New Issue