|
|
@@ -6,7 +6,7 @@ from homeassistant.components.light import (
|
|
|
ATTR_COLOR_MODE,
|
|
|
ATTR_COLOR_TEMP,
|
|
|
ATTR_EFFECT,
|
|
|
- ATTR_RGBW_COLOR,
|
|
|
+ ATTR_HS_COLOR,
|
|
|
ATTR_WHITE,
|
|
|
ColorMode,
|
|
|
LightEntity,
|
|
|
@@ -89,7 +89,7 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
return from_dp
|
|
|
|
|
|
if self._rgbhsv_dps:
|
|
|
- return ColorMode.RGBW
|
|
|
+ return ColorMode.HS
|
|
|
elif self._color_temp_dps:
|
|
|
return ColorMode.COLOR_TEMP
|
|
|
elif self._brightness_dps:
|
|
|
@@ -138,12 +138,13 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
return self._brightness_dps.get_value(self._device)
|
|
|
|
|
|
@property
|
|
|
- def rgbw_color(self):
|
|
|
- """Get the current RGBW color of the light"""
|
|
|
+ def hs_color(self):
|
|
|
+ """Get the current hs color of the light"""
|
|
|
if self._rgbhsv_dps:
|
|
|
# color data in hex format RRGGBBHHHHSSVV (14 digit hex)
|
|
|
# can also be base64 encoded.
|
|
|
# Either RGB or HSV can be used.
|
|
|
+ # Others are color data in hex format HHHHSSSSVVVV (12 digit hex)
|
|
|
color = self._rgbhsv_dps.decoded_value(self._device)
|
|
|
|
|
|
fmt = self._rgbhsv_dps.format
|
|
|
@@ -156,10 +157,6 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
# for h
|
|
|
n = fmt["names"][idx]
|
|
|
r = fmt["ranges"][idx]
|
|
|
- if r["min"] != 0:
|
|
|
- raise AttributeError(
|
|
|
- f"Unhandled minimum range for {n} in RGBW value"
|
|
|
- )
|
|
|
mx = r["max"]
|
|
|
scale = 1
|
|
|
if n == "h":
|
|
|
@@ -173,17 +170,13 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
idx += 1
|
|
|
|
|
|
if "h" in rgbhsv and "s" in rgbhsv and "v" in rgbhsv:
|
|
|
- h = rgbhsv["h"]
|
|
|
- s = rgbhsv["s"]
|
|
|
- # convert RGB from H and S to seperate out the V component
|
|
|
- r, g, b = color_util.color_hs_to_RGB(h, s)
|
|
|
- w = rgbhsv["v"]
|
|
|
+ hs = (rgbhsv["h"], rgbhsv["s"])
|
|
|
else:
|
|
|
r = rgbhsv.get("r")
|
|
|
g = rgbhsv.get("g")
|
|
|
b = rgbhsv.get("b")
|
|
|
- w = self.brightness
|
|
|
- return (r, g, b, w)
|
|
|
+ hs = color_util.color_rgb_to_hs(r, g, b)
|
|
|
+ return hs
|
|
|
|
|
|
@property
|
|
|
def effect_list(self):
|
|
|
@@ -242,18 +235,17 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
**self._color_temp_dps.get_values_to_set(self._device, color_temp),
|
|
|
}
|
|
|
elif self._rgbhsv_dps and (
|
|
|
- ATTR_RGBW_COLOR in params
|
|
|
- or (ATTR_BRIGHTNESS in params and self.raw_color_mode == ColorMode.RGBW)
|
|
|
+ ATTR_HS_COLOR in params
|
|
|
+ or (ATTR_BRIGHTNESS in params and self.raw_color_mode == ColorMode.HS)
|
|
|
):
|
|
|
- if self.raw_color_mode != ColorMode.RGBW:
|
|
|
- color_mode = ColorMode.RGBW
|
|
|
+ if self.raw_color_mode != ColorMode.HS:
|
|
|
+ color_mode = ColorMode.HS
|
|
|
|
|
|
- rgbw = params.get(ATTR_RGBW_COLOR, self.rgbw_color or (0, 0, 0, 0))
|
|
|
+ hs = params.get(ATTR_HS_COLOR, self.hs_color or (0, 0))
|
|
|
brightness = params.get(ATTR_BRIGHTNESS, self.brightness or 255)
|
|
|
fmt = self._rgbhsv_dps.format
|
|
|
- if rgbw and fmt:
|
|
|
- rgb = (rgbw[0], rgbw[1], rgbw[2])
|
|
|
- hs = color_util.color_RGB_to_hs(rgbw[0], rgbw[1], rgbw[2])
|
|
|
+ if hs and fmt:
|
|
|
+ rgb = color_util.color_hsv_to_RGB(*hs, brightness / 2.55)
|
|
|
rgbhsv = {
|
|
|
"r": rgb[0],
|
|
|
"g": rgb[1],
|
|
|
@@ -263,7 +255,7 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
"v": brightness,
|
|
|
}
|
|
|
_LOGGER.debug(
|
|
|
- f"Setting RGBW as {rgb[0]},{rgb[1]},{rgb[2]},{hs[0]},{hs[1]},{brightness}"
|
|
|
+ f"Setting color as {rgb[0]},{rgb[1]},{rgb[2]},{hs[0]},{hs[1]},{brightness}"
|
|
|
)
|
|
|
ordered = []
|
|
|
idx = 0
|
|
|
@@ -276,7 +268,17 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
scale = r["max"] / 360
|
|
|
else:
|
|
|
scale = r["max"] / 255
|
|
|
- ordered.append(round(rgbhsv[n] * scale))
|
|
|
+ val = round(rgbhsv[n] * scale)
|
|
|
+ if val < r["min"]:
|
|
|
+ _LOGGER.warning(
|
|
|
+ "Color data %s=%d constrained to be above %d",
|
|
|
+ n,
|
|
|
+ val,
|
|
|
+ r["min"],
|
|
|
+ )
|
|
|
+ val = r["min"]
|
|
|
+ _LOGGER.warning("%s=%d", n, val)
|
|
|
+ ordered.append(val)
|
|
|
idx += 1
|
|
|
binary = pack(fmt["format"], *ordered)
|
|
|
settings = {
|
|
|
@@ -307,7 +309,7 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
|
|
|
if (
|
|
|
ATTR_BRIGHTNESS in params
|
|
|
- and self.raw_color_mode != ColorMode.RGBW
|
|
|
+ and self.raw_color_mode != ColorMode.HS
|
|
|
and self._brightness_dps
|
|
|
):
|
|
|
bright = params.get(ATTR_BRIGHTNESS)
|