Просмотр исходного кода

Inital attempt to get Merkury BW904 Smart Bulb working

Jon 2 лет назад
Родитель
Сommit
ba90be6f3f

+ 46 - 0
custom_components/tuya_local/devices/rgbw_lightbulb.yaml

@@ -0,0 +1,46 @@
+name: RGBW lightbulb
+primary_entity:
+  entity: light
+  dps:
+    - id: 1
+      type: boolean
+      name: switch
+    - id: 2
+      name: color_mode
+      type: string
+      mapping:
+        - dps_val: white
+          value: white
+        - dps_val: colour
+          value: rgbw
+    - id: 3
+      name: brightness
+      type: integer
+      range:
+        min: 25
+        max: 255
+    - id: 5
+      name: rgbhsv
+      type: hex
+      format:
+        - name: r
+          bytes: 1
+        - name: g
+          bytes: 1
+        - name: b
+          bytes: 1
+        - name: h
+          bytes: 2
+          range:
+            min: 0
+            max: 360
+        - name: s
+          bytes: 1
+          range:
+            min: 0
+            max: 255
+        - name: v
+          bytes: 1
+          range:
+            min: 0
+            max: 255

+ 19 - 1
custom_components/tuya_local/light.py

@@ -7,6 +7,7 @@ from homeassistant.components.light import (
     ATTR_COLOR_TEMP,
     ATTR_EFFECT,
     ATTR_RGBW_COLOR,
+    ATTR_WHITE,
     ColorMode,
     LightEntity,
     LightEntityFeature,
@@ -52,6 +53,7 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
         self._color_temp_dps = dps_map.pop("color_temp", None)
         self._rgbhsv_dps = dps_map.pop("rgbhsv", None)
         self._effect_dps = dps_map.pop("effect", None)
+        self._white_dps = dps_map.pop("white", None)
         self._init_end(dps_map)
 
     @property
@@ -210,7 +212,23 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
         settings = {}
         color_mode = None
 
-        if self._color_temp_dps and ATTR_COLOR_TEMP in params:
+        if self._color_mode_dps and ATTR_WHITE in params:
+            if self.color_mode != ColorMode.WHITE:
+                color_mode = ColorMode.WHITE
+                if (
+                   ATTR_BRIGHTNESS not in params
+                   and self._brightness_dps
+                 ):
+                   bright = params.get(ATTR_WHITE)
+                   _LOGGER.debug(f"Setting brightness via WHITE parameter to {bright}")
+                   settings = {
+                       **settings,
+                       **self._brightness_dps.get_values_to_set(
+                           self._device,
+                           bright,
+                       ),
+                   }
+        elif self._color_temp_dps and ATTR_COLOR_TEMP in params:
             if self.color_mode != ColorMode.COLOR_TEMP:
                 color_mode = ColorMode.COLOR_TEMP