|
|
@@ -134,27 +134,27 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
@property
|
|
|
def brightness(self):
|
|
|
"""Get the current brightness of the light"""
|
|
|
+ if self.raw_color_mode == ColorMode.HS and self._rgbhsv_dps:
|
|
|
+ return self._hsv_brightness
|
|
|
+ return self._white_brightness
|
|
|
+
|
|
|
+ @property
|
|
|
+ def _white_brightness(self):
|
|
|
if self._brightness_dps:
|
|
|
return self._brightness_dps.get_value(self._device)
|
|
|
|
|
|
@property
|
|
|
- def hs_color(self):
|
|
|
- """Get the current hs color of the light"""
|
|
|
+ def _unpacked_rgbhsv(self):
|
|
|
+ """Get the unpacked rgbhsv data"""
|
|
|
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
|
|
|
if fmt and color:
|
|
|
vals = unpack(fmt.get("format"), color)
|
|
|
- rgbhsv = {}
|
|
|
idx = 0
|
|
|
+ rgbhsv = {}
|
|
|
for v in vals:
|
|
|
- # Range in HA is 0-100 for s, 0-255 for rgb and v, 0-360
|
|
|
- # for h
|
|
|
+ # Range in HA is 0-100 for s, 0-255 for rgb and v, 0-360 for h
|
|
|
n = fmt["names"][idx]
|
|
|
r = fmt["ranges"][idx]
|
|
|
mx = r["max"]
|
|
|
@@ -169,14 +169,29 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
rgbhsv[n] = round(scale * v)
|
|
|
idx += 1
|
|
|
|
|
|
- if "h" in rgbhsv and "s" in rgbhsv and "v" in rgbhsv:
|
|
|
- hs = (rgbhsv["h"], rgbhsv["s"])
|
|
|
- else:
|
|
|
- r = rgbhsv.get("r")
|
|
|
- g = rgbhsv.get("g")
|
|
|
- b = rgbhsv.get("b")
|
|
|
- hs = color_util.color_rgb_to_hs(r, g, b)
|
|
|
- return hs
|
|
|
+ return rgbhsv
|
|
|
+
|
|
|
+ @property
|
|
|
+ def _hsv_brightness(self):
|
|
|
+ """Get the colour mode brightness from the light"""
|
|
|
+ rgbhsv = self._unpacked_rgbhsv
|
|
|
+ if rgbhsv:
|
|
|
+ return rgbhsv.get("v", self._white_brightness)
|
|
|
+ return self._white_brightness
|
|
|
+
|
|
|
+ @property
|
|
|
+ def hs_color(self):
|
|
|
+ """Get the current hs color of the light"""
|
|
|
+ rgbhsv = self._unpacked_rgbhsv
|
|
|
+ if rgbhsv:
|
|
|
+ if "h" in rgbhsv and "s" in rgbhsv:
|
|
|
+ hs = (rgbhsv["h"], rgbhsv["s"])
|
|
|
+ else:
|
|
|
+ r = rgbhsv.get("r")
|
|
|
+ g = rgbhsv.get("g")
|
|
|
+ b = rgbhsv.get("b")
|
|
|
+ hs = color_util.color_rgb_to_hs(r, g, b)
|
|
|
+ return hs
|
|
|
|
|
|
@property
|
|
|
def effect_list(self):
|
|
|
@@ -277,7 +292,6 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
|
|
|
r["min"],
|
|
|
)
|
|
|
val = r["min"]
|
|
|
- _LOGGER.warning("%s=%d", n, val)
|
|
|
ordered.append(val)
|
|
|
idx += 1
|
|
|
binary = pack(fmt["format"], *ordered)
|