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