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

Smartplugs: Enable forced updates of power, current and voltage dps.

Such devices will alternate between status() and explicit
updatedps([...]) every 30s.

Issue #420
Jason Rumney 3 лет назад
Родитель
Сommit
919ea25188
22 измененных файлов с 95 добавлено и 43 удалено
  1. 3 0
      custom_components/tuya_local/devices/aubess_1gang_switch.yaml
  2. 3 0
      custom_components/tuya_local/devices/blitzwolf_bwshp6_smartplug.yaml
  3. 3 0
      custom_components/tuya_local/devices/compteur_energy_meter.yaml
  4. 3 0
      custom_components/tuya_local/devices/digoo_dgsp202.yaml
  5. 3 0
      custom_components/tuya_local/devices/dual_power_monitor_smartplug.yaml
  6. 3 0
      custom_components/tuya_local/devices/energy_monitoring_powerstrip.yaml
  7. 3 0
      custom_components/tuya_local/devices/gosund_usb_triple_powerstrip.yaml
  8. 3 0
      custom_components/tuya_local/devices/grid_connect_usb_double_power_point.yaml
  9. 3 0
      custom_components/tuya_local/devices/moes_rgb_socket.yaml
  10. 11 0
      custom_components/tuya_local/devices/pc321ty_energy_meter.yaml
  11. 3 0
      custom_components/tuya_local/devices/pj1103_clamp_meter.yaml
  12. 3 0
      custom_components/tuya_local/devices/quad_powerstrip.yaml
  13. 3 0
      custom_components/tuya_local/devices/rgb_nightlight_outlet.yaml
  14. 3 21
      custom_components/tuya_local/devices/smartplugv1.yaml
  15. 3 22
      custom_components/tuya_local/devices/smartplugv2.yaml
  16. 3 0
      custom_components/tuya_local/devices/smartplugv2_energy.yaml
  17. 3 0
      custom_components/tuya_local/devices/smartplugv2_energyv2.yaml
  18. 3 0
      custom_components/tuya_local/devices/smartplugv2_energyv3.yaml
  19. 3 0
      custom_components/tuya_local/devices/smartplugv3.yaml
  20. 5 0
      custom_components/tuya_local/devices/solar_inverter.yaml
  21. 3 0
      custom_components/tuya_local/devices/tyte_d1_thermostat.yaml
  22. 22 0
      custom_components/tuya_local/water_heater.py

+ 3 - 0
custom_components/tuya_local/devices/aubess_1gang_switch.yaml

@@ -65,6 +65,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
   - entity: sensor
     name: Power
@@ -75,6 +76,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: W
         mapping:
           - scale: 10
@@ -86,6 +88,7 @@ secondary_entities:
       - id: 23
         name: sensor
         type: integer
+        force: true
         class: measurement
         unit: V
         mapping:

+ 3 - 0
custom_components/tuya_local/devices/blitzwolf_bwshp6_smartplug.yaml

@@ -42,6 +42,7 @@ secondary_entities:
         name: sensor
         unit: mA
         class: measurement
+        force: true
       - id: 23
         type: integer
         name: calibration
@@ -56,6 +57,7 @@ secondary_entities:
         name: sensor
         unit: W
         class: measurement
+        force: true
         mapping:
           - scale: 10
       - id: 24
@@ -72,6 +74,7 @@ secondary_entities:
         name: sensor
         unit: V
         class: measurement
+        force: true
         mapping:
           - scale: 10
       - id: 22

+ 3 - 0
custom_components/tuya_local/devices/compteur_energy_meter.yaml

@@ -41,6 +41,7 @@ secondary_entities:
         type: integer
         unit: V
         class: measurement
+        force: true
         mapping:
           - scale: 10
   - entity: sensor
@@ -53,6 +54,7 @@ secondary_entities:
         type: integer
         unit: A
         class: measurement
+        force: true
         mapping:
           - scale: 1000
   - entity: sensor
@@ -65,6 +67,7 @@ secondary_entities:
         type: integer
         unit: W
         class: measurement
+        force: true
         mapping:
           - scale: 10
 

+ 3 - 0
custom_components/tuya_local/devices/digoo_dgsp202.yaml

@@ -31,6 +31,7 @@ secondary_entities:
         type: integer
         class: measurement
         unit: V
+        force: true
         mapping:
           - scale: 10
   - entity: sensor
@@ -42,6 +43,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
   - entity: sensor
     category: diagnostic
@@ -52,6 +54,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: W
         mapping:
           - scale: 10

+ 3 - 0
custom_components/tuya_local/devices/dual_power_monitor_smartplug.yaml

@@ -29,6 +29,7 @@ secondary_entities:
         name: sensor
         unit: A
         class: measurement
+        force: true
         mapping:
           - scale: 1000
   - entity: sensor
@@ -41,6 +42,7 @@ secondary_entities:
         name: sensor
         unit: W
         class: measurement
+        force: true
         mapping:
           - scale: 10
   - entity: sensor
@@ -53,6 +55,7 @@ secondary_entities:
         name: sensor
         unit: V
         class: measurement
+        force: true
         mapping:
           - scale: 10
   - entity: number

+ 3 - 0
custom_components/tuya_local/devices/energy_monitoring_powerstrip.yaml

@@ -57,6 +57,7 @@ secondary_entities:
         name: sensor
         unit: mA
         class: measurement
+        force: true
   - entity: sensor
     name: Power
     class: power
@@ -67,6 +68,7 @@ secondary_entities:
         name: sensor
         unit: W
         class: measurement
+        force: true
         mapping:
           - scale: 10
   - entity: sensor
@@ -79,5 +81,6 @@ secondary_entities:
         name: sensor
         unit: V
         class: measurement
+        force: true
         mapping:
           - scale: 10

+ 3 - 0
custom_components/tuya_local/devices/gosund_usb_triple_powerstrip.yaml

@@ -101,6 +101,7 @@ secondary_entities:
         type: integer
         name: sensor
         unit: mA
+        force: true
         class: measurement
   - entity: sensor
     name: Power
@@ -112,6 +113,7 @@ secondary_entities:
         name: sensor
         unit: W
         class: measurement
+        force: true
         mapping:
           - scale: 10
   - entity: sensor
@@ -124,6 +126,7 @@ secondary_entities:
         name: sensor
         unit: V
         class: measurement
+        force: true
         mapping:
           - scale: 10
   - entity: binary_sensor

+ 3 - 0
custom_components/tuya_local/devices/grid_connect_usb_double_power_point.yaml

@@ -58,6 +58,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
       - id: 23
         name: calibration
@@ -72,6 +73,7 @@ secondary_entities:
         type: integer
         class: measurement
         unit: W
+        force: true
         mapping:
           - scale: 10
       - id: 24
@@ -87,6 +89,7 @@ secondary_entities:
         type: integer
         class: measurement
         unit: V
+        force: true
         mapping:
           - scale: 10
       - id: 22

+ 3 - 0
custom_components/tuya_local/devices/moes_rgb_socket.yaml

@@ -103,6 +103,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
   - entity: sensor
     name: Power
@@ -113,6 +114,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: W
         mapping:
           - scale: 10
@@ -125,6 +127,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: V
         mapping:
           - scale: 10

+ 11 - 0
custom_components/tuya_local/devices/pc321ty_energy_meter.yaml

@@ -23,6 +23,7 @@ secondary_entities:
         type: integer
         unit: V
         class: measurement
+        force: true
         mapping:
           - scale: 10
   - entity: sensor
@@ -35,6 +36,7 @@ secondary_entities:
         type: integer
         unit: A
         class: measurement
+        force: true
         mapping:
           - scale: 1000
   - entity: sensor
@@ -46,6 +48,7 @@ secondary_entities:
         name: sensor
         type: integer
         unit: W
+        force: true
         class: measurement
   - entity: sensor
     category: diagnostic
@@ -78,6 +81,7 @@ secondary_entities:
         type: integer
         unit: V
         class: measurement
+        force: true
         mapping:
           - scale: 10
   - entity: sensor
@@ -90,6 +94,7 @@ secondary_entities:
         type: integer
         unit: A
         class: measurement
+        force: true
         mapping:
           - scale: 1000
   - entity: sensor
@@ -100,6 +105,7 @@ secondary_entities:
       - id: 113
         name: sensor
         type: integer
+        force: true
         unit: W
         class: measurement
   - entity: sensor
@@ -133,6 +139,7 @@ secondary_entities:
         type: integer
         unit: V
         class: measurement
+        force: true
         mapping:
           - scale: 10
   - entity: sensor
@@ -145,6 +152,7 @@ secondary_entities:
         type: integer
         unit: A
         class: measurement
+        force: true
         mapping:
           - scale: 1000
   - entity: sensor
@@ -155,6 +163,7 @@ secondary_entities:
       - id: 123
         name: sensor
         type: integer
+        force: true
         class: measurement
         unit: W
   - entity: sensor
@@ -188,6 +197,7 @@ secondary_entities:
         name: sensor
         unit: A
         class: measurement
+        force: true
         mapping:
           - scale: 1000
   - entity: sensor
@@ -199,6 +209,7 @@ secondary_entities:
         type: integer
         name: sensor
         unit: W
+        force: true
         class: measurement
   - entity: sensor
     category: diagnostic

+ 3 - 0
custom_components/tuya_local/devices/pj1103_clamp_meter.yaml

@@ -11,6 +11,7 @@ primary_entity:
       type: integer
       unit: W
       class: measurement
+      force: true
       mapping:
         - scale: 10
     - id: 24
@@ -39,6 +40,7 @@ secondary_entities:
         type: integer
         name: sensor
         unit: mA
+        force: true
         class: measurement
       - id: 23
         type: integer
@@ -53,6 +55,7 @@ secondary_entities:
         type: integer
         name: sensor
         unit: V
+        force: true
         class: measurement
         mapping:
           - scale: 10

+ 3 - 0
custom_components/tuya_local/devices/quad_powerstrip.yaml

@@ -106,6 +106,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
       - id: 23
         type: integer
@@ -120,6 +121,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: W
         mapping:
           - scale: 10
@@ -136,6 +138,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: V
         mapping:
           - scale: 10

+ 3 - 0
custom_components/tuya_local/devices/rgb_nightlight_outlet.yaml

@@ -66,6 +66,7 @@ secondary_entities:
       - id: 4
         type: integer
         name: sensor
+        force: true
         unit: mA
         class: measurement
   - entity: sensor
@@ -76,6 +77,7 @@ secondary_entities:
       - id: 5
         type: integer
         name: sensor
+        force: true
         unit: V
         class: measurement
         mapping:
@@ -88,6 +90,7 @@ secondary_entities:
       - id: 6
         type: integer
         name: sensor
+        force: true
         unit: W
         class: measurement
         mapping:

+ 3 - 21
custom_components/tuya_local/devices/smartplugv1.yaml

@@ -7,27 +7,6 @@ primary_entity:
     - id: 1
       type: boolean
       name: switch
-    - id: 2
-      type: integer
-      name: timer
-    - id: 4
-      type: integer
-      name: current_a
-      readonly: true
-      mapping:
-        - scale: 1000
-    - id: 5
-      type: integer
-      name: current_power_w
-      readonly: true
-      mapping:
-        - scale: 10
-    - id: 6
-      type: integer
-      name: voltage_v
-      readonly: true
-      mapping:
-        - scale: 10
 secondary_entities:
   - entity: sensor
     category: diagnostic
@@ -39,6 +18,7 @@ secondary_entities:
         type: integer
         class: measurement
         unit: V
+        force: true
         mapping:
           - scale: 10
   - entity: sensor
@@ -51,6 +31,7 @@ secondary_entities:
         type: integer
         class: measurement
         unit: mA
+        force: true
   - entity: sensor
     category: diagnostic
     class: power
@@ -61,6 +42,7 @@ secondary_entities:
         type: integer
         class: measurement
         unit: W
+        force: true
         mapping:
           - scale: 10
   - entity: number

+ 3 - 22
custom_components/tuya_local/devices/smartplugv2.yaml

@@ -7,27 +7,6 @@ primary_entity:
     - id: 1
       type: boolean
       name: switch
-    - id: 9
-      type: integer
-      name: timer
-    - id: 18
-      type: integer
-      name: current_a
-      read-only: true
-      mapping:
-        - scale: 1000
-    - id: 19
-      type: integer
-      name: current_power_w
-      read-only: true
-      mapping:
-        - scale: 10
-    - id: 20
-      type: integer
-      name: voltage_v
-      read-only: true
-      mapping:
-        - scale: 10
     - id: 21
       type: bitfield
       name: factory_test
@@ -46,6 +25,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: V
         mapping:
           - scale: 10
@@ -62,6 +42,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
       - id: 23
         type: integer
@@ -76,6 +57,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: W
         mapping:
           - scale: 10
@@ -98,4 +80,3 @@ secondary_entities:
         mapping:
           - scale: 60
             step: 60
-

+ 3 - 0
custom_components/tuya_local/devices/smartplugv2_energy.yaml

@@ -58,6 +58,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
       - id: 23
         type: integer
@@ -72,6 +73,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: W
         mapping:
           - scale: 10
@@ -87,6 +89,7 @@ secondary_entities:
       - id: 20
         name: sensor
         type: integer
+        force: true
         class: measurement
         unit: V
         mapping:

+ 3 - 0
custom_components/tuya_local/devices/smartplugv2_energyv2.yaml

@@ -54,6 +54,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
       - id: 23
         type: integer
@@ -67,6 +68,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: W
         mapping:
           - scale: 10
@@ -82,6 +84,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: V
         mapping:
           - scale: 10

+ 3 - 0
custom_components/tuya_local/devices/smartplugv2_energyv3.yaml

@@ -68,6 +68,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
       - id: 23
         type: integer
@@ -81,6 +82,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: W
         mapping:
           - scale: 10
@@ -96,6 +98,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: V
         mapping:
           - scale: 10

+ 3 - 0
custom_components/tuya_local/devices/smartplugv3.yaml

@@ -43,6 +43,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: mA
       - id: 23
         type: integer
@@ -57,6 +58,7 @@ secondary_entities:
         name: sensor
         type: integer
         class: measurement
+        force: true
         unit: W
         mapping:
           - scale: 10
@@ -72,6 +74,7 @@ secondary_entities:
       - id: 20
         name: sensor
         type: integer
+        force: true
         class: measurement
         unit: V
         mapping:

+ 5 - 0
custom_components/tuya_local/devices/solar_inverter.yaml

@@ -30,6 +30,7 @@ secondary_entities:
         type: integer
         name: sensor
         unit: W
+        force: true
         class: measurement
         mapping:
           - scale: 10
@@ -43,6 +44,7 @@ secondary_entities:
         name: sensor
         unit: A
         class: measurement
+        force: true
         mapping:
           - scale: 100
   - entity: sensor
@@ -54,6 +56,7 @@ secondary_entities:
         type: integer
         name: sensor
         unit: V
+        force: true
         class: measurement
         mapping:
           - scale: 10
@@ -66,6 +69,7 @@ secondary_entities:
         type: integer
         name: sensor
         unit: V
+        force: true
         class: measurement
         mapping:
           - scale: 10
@@ -77,6 +81,7 @@ secondary_entities:
       - id: 105
         type: integer
         name: sensor
+        force: true
         unit: A
         class: measurement
         mapping:

+ 3 - 0
custom_components/tuya_local/devices/tyte_d1_thermostat.yaml

@@ -129,6 +129,7 @@ secondary_entities:
       - id: 11
         type: integer
         name: sensor
+        force: true
         unit: mA
         class: measurement
       - id: 15
@@ -144,6 +145,7 @@ secondary_entities:
         name: sensor
         unit: W
         class: measurement
+        force: true
         mapping:
           - scale: 10
       - id: 16
@@ -161,6 +163,7 @@ secondary_entities:
         type: integer
         name: sensor
         unit: V
+        force: true
         class: measurement
         mapping:
           - scale: 10

+ 22 - 0
custom_components/tuya_local/water_heater.py

@@ -171,3 +171,25 @@ class TuyaLocalWaterHeater(TuyaLocalEntity, WaterHeaterEntity):
         if self._temperature_dps:
             r = self._temperature_dps.range(self._device)
             return r.get("max")
+
+    async def async_turn_on(self):
+        """
+        Turn on the water heater.  Works only if operation_mode is a
+        boolean dp.
+        """
+        if self._operation_mode_dps and self._operation_mode_dps.type is bool:
+            await self._device.async_set_property(
+                self._operation_mode_dps.id,
+                True,
+            )
+
+    async def async_turn_off(self):
+        """
+        Turn off the water heater.  Works only if operation_mode is a
+        boolean dp.
+        """
+        if self._operation_mode_dps and self._operation_mode_dps.type is bool:
+            await self._device.async_set_property(
+                self._operation_mode_dps.id,
+                False,
+            )