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

Bulk change: add duration class to time related sensors.

Scaled sensors reverted back to original units, as duration class
should result in appropriate units for the timescale being used in the
UI.

- anko fan: timer had units of seconds with a range of 0-9.  This should
clearly be hours with that range.
Jason Rumney 3 лет назад
Родитель
Сommit
dadd823e99
36 измененных файлов с 73 добавлено и 48 удалено
  1. 1 1
      custom_components/tuya_local/device.py
  2. 1 1
      custom_components/tuya_local/devices/anko_fan.yaml
  3. 1 0
      custom_components/tuya_local/devices/atomi_ceramic_heater.yaml
  4. 1 0
      custom_components/tuya_local/devices/avatto_roller_blinds.yaml
  5. 1 0
      custom_components/tuya_local/devices/betterlife_bl1500_heater.yaml
  6. 1 0
      custom_components/tuya_local/devices/breville_easyair_purifier.yaml
  7. 2 5
      custom_components/tuya_local/devices/catit_pixi_smart_fountain.yaml
  8. 1 0
      custom_components/tuya_local/devices/eanons_humidifier.yaml
  9. 4 5
      custom_components/tuya_local/devices/ebac_dj4000_dehumidifier.yaml
  10. 1 0
      custom_components/tuya_local/devices/essentials_purifier.yaml
  11. 2 3
      custom_components/tuya_local/devices/fanco_ecosilentdeluxe.yaml
  12. 1 0
      custom_components/tuya_local/devices/himox_h06_purifier.yaml
  13. 1 0
      custom_components/tuya_local/devices/inkbird_sousvide_cooker.yaml
  14. 1 0
      custom_components/tuya_local/devices/inventor_atmospherexl_dehumidifier.yaml
  15. 1 0
      custom_components/tuya_local/devices/kyvol_e30_vacuum.yaml
  16. 1 0
      custom_components/tuya_local/devices/lefant_m213_vacuum.yaml
  17. 2 3
      custom_components/tuya_local/devices/nashone_mts700wb_thermostat.yaml
  18. 1 0
      custom_components/tuya_local/devices/parkside_plgs2012a1_smart_charger.yaml
  19. 1 0
      custom_components/tuya_local/devices/poiema_one_purifier.yaml
  20. 1 0
      custom_components/tuya_local/devices/vork_vk6067aw_purifier.yaml
  21. 1 0
      custom_components/tuya_local/devices/wetair_wch750_heater.yaml
  22. 1 1
      tests/devices/test_anko_fan.py
  23. 2 0
      tests/devices/test_avatto_blinds.py
  24. 2 0
      tests/devices/test_betterlife_bl1500_heater.py
  25. 2 0
      tests/devices/test_eanons_humidifier.py
  26. 1 0
      tests/devices/test_essentials_purifier.py
  27. 19 26
      tests/devices/test_grid_connect_double_power_point.py
  28. 2 0
      tests/devices/test_himox_h06_purifier.py
  29. 2 0
      tests/devices/test_inkbird_sousvide.py
  30. 2 0
      tests/devices/test_kyvol_e30_vacuum.py
  31. 2 0
      tests/devices/test_lefant_m213_vacuum.py
  32. 3 2
      tests/devices/test_nashone_mts700wb_thermostat.py
  33. 1 0
      tests/devices/test_parkside_plgs2012a1_smart_charger.py
  34. 1 0
      tests/devices/test_poiema_one_purifier.py
  35. 1 0
      tests/devices/test_vork_vk6067aw_purifier.py
  36. 5 1
      tests/devices/test_wetair_wch750_heater.py

+ 1 - 1
custom_components/tuya_local/device.py

@@ -462,7 +462,7 @@ class TuyaLocalDevice(object):
                     return retval
             except Exception as e:
                 _LOGGER.debug(
-                    "Retrying after exception %s (%d/%d)",
+                    "Retrying after exception %s %s (%d/%d)",
                     type(e),
                     e,
                     i,

+ 1 - 1
custom_components/tuya_local/devices/anko_fan.yaml

@@ -43,7 +43,7 @@ secondary_entities:
       - id: 6
         type: integer
         name: value
-        unit: s
+        unit: h
         range:
           min: 0
           max: 9

+ 1 - 0
custom_components/tuya_local/devices/atomi_ceramic_heater.yaml

@@ -87,6 +87,7 @@ secondary_entities:
   - entity: sensor
     name: Timer remain
     icon: "mdi:timer"
+    class: duration
     category: diagnostic
     dps:
       - id: 12

+ 1 - 0
custom_components/tuya_local/devices/avatto_roller_blinds.yaml

@@ -72,6 +72,7 @@ secondary_entities:
   - entity: sensor
     name: Timer
     icon: "mdi:timer"
+    class: duration
     category: diagnostic
     dps:
       - id: 9

+ 1 - 0
custom_components/tuya_local/devices/betterlife_bl1500_heater.yaml

@@ -89,6 +89,7 @@ secondary_entities:
   - entity: sensor
     name: Timer countdown
     icon: "mdi:timer"
+    class: duration
     category: diagnostic
     dps:
       - id: 12

+ 1 - 0
custom_components/tuya_local/devices/breville_easyair_purifier.yaml

@@ -70,6 +70,7 @@ secondary_entities:
   - entity: sensor
     name: Time left
     category: diagnostic
+    class: duration
     icon: "mdi:timer"
     dps:
       - id: 20

+ 2 - 5
custom_components/tuya_local/devices/catit_pixi_smart_fountain.yaml

@@ -71,16 +71,13 @@ secondary_entities:
           - dps_val: level_3
             icon: "mdi:cup"
             value: Full
-
   - entity: sensor
     name: UV runtime
+    class: duration
     icon: "mdi:timer-outline"
     category: diagnostic
     dps:
       - id: 11
         type: integer
         name: sensor
-        mapping:
-          - scale: 60
-            step: 1
-        unit: min
+        unit: s

+ 1 - 0
custom_components/tuya_local/devices/eanons_humidifier.yaml

@@ -105,6 +105,7 @@ secondary_entities:
             value: "12 hours"
   - entity: sensor
     name: Timer
+    class: duration
     icon: "mdi:timer"
     category: diagnostic
     dps:

+ 4 - 5
custom_components/tuya_local/devices/ebac_dj4000_dehumidifier.yaml

@@ -97,7 +97,6 @@ secondary_entities:
         type: integer
         name: sensor
         unit: "%"
-        class: measurement
   - entity: button
     name: Filter reset
     category: config
@@ -110,12 +109,12 @@ secondary_entities:
     name: Time left
     category: diagnostic
     icon: "mdi:timer-outline"
+    class: duration
     dps:
       - id: 18
         type: integer
         name: sensor
-        unit: "min"
-        class: duration
+        unit: min
   - entity: binary_sensor
     name: Tank
     class: problem
@@ -137,6 +136,7 @@ secondary_entities:
 #     name: Runtime total
 #     category: diagnostic
 #     icon: "mdi:timelapse"
+#     class: duration
 #     dps:
 #       - id: 27
 #         type: integer
@@ -144,8 +144,7 @@ secondary_entities:
 #         min: 0
 #         max: 1000
 #         name: sensor
-#         unit: "min"
-#         class: duration
+#         unit: min
 #   - entity: button
 #     name: Runtime total reset
 #     category: config

+ 1 - 0
custom_components/tuya_local/devices/essentials_purifier.yaml

@@ -95,6 +95,7 @@ secondary_entities:
   - entity: sensor
     name: Timer
     icon: "mdi:timer"
+    class: duration
     category: diagnostic
     dps:
       - id: 19

+ 2 - 3
custom_components/tuya_local/devices/fanco_ecosilentdeluxe.yaml

@@ -61,10 +61,9 @@ secondary_entities:
   - entity: sensor
     name: Timer
     category: diagnostic
+    class: duration
     dps:
       - id: 24
         type: integer
         name: sensor
-        unit: min
-        mapping:
-          - scale: 60
+        unit: s

+ 1 - 0
custom_components/tuya_local/devices/himox_h06_purifier.yaml

@@ -68,6 +68,7 @@ secondary_entities:
     name: Timer
     icon: "mdi:timer"
     category: diagnostic
+    class: duration
     dps:
       - id: 19
         type: integer

+ 1 - 0
custom_components/tuya_local/devices/inkbird_sousvide_cooker.yaml

@@ -69,6 +69,7 @@ secondary_entities:
   - entity: sensor
     name: Remaining time
     category: diagnostic
+    class: duration
     icon: "mdi:timer"
     dps:
       - id: 106

+ 1 - 0
custom_components/tuya_local/devices/inventor_atmospherexl_dehumidifier.yaml

@@ -198,6 +198,7 @@ secondary_entities:
             value: 9 hours
   - entity: sensor
     name: Timer
+    class: duration
     category: diagnostic
     icon: "mdi:timer"
     dps:

+ 1 - 0
custom_components/tuya_local/devices/kyvol_e30_vacuum.yaml

@@ -124,6 +124,7 @@ secondary_entities:
   - entity: sensor
     name: Clean time
     category: diagnostic
+    class: duration
     icon: "mdi:clock-outline"
     dps:
       - id: 17

+ 1 - 0
custom_components/tuya_local/devices/lefant_m213_vacuum.yaml

@@ -148,6 +148,7 @@ secondary_entities:
   - entity: sensor
     name: Clean time
     category: diagnostic
+    class: duration
     icon: "mdi:clock-outline"
     dps:
       - id: 17

+ 2 - 3
custom_components/tuya_local/devices/nashone_mts700wb_thermostat.yaml

@@ -108,11 +108,10 @@ secondary_entities:
   - entity: sensor
     category: diagnostic
     name: Timer
+    class: duration
     icon: "mdi:timer"
     dps:
       - id: 42
         type: integer
-        unit: min
+        unit: s
         name: sensor
-        mapping:
-          - scale: 60

+ 1 - 0
custom_components/tuya_local/devices/parkside_plgs2012a1_smart_charger.yaml

@@ -123,6 +123,7 @@ secondary_entities:
         unit: mA
   - entity: sensor
     name: Time remaining
+    class: duration
     icon: "mdi:battery-clock"
     dps:
       - id: 102

+ 1 - 0
custom_components/tuya_local/devices/poiema_one_purifier.yaml

@@ -93,6 +93,7 @@ secondary_entities:
   - entity: sensor
     name: Timer
     category: diagnostic
+    class: duration
     icon: "mdi:timer"
     dps:
       - id: 19

+ 1 - 0
custom_components/tuya_local/devices/vork_vk6067aw_purifier.yaml

@@ -80,6 +80,7 @@ secondary_entities:
             value: "2 hours" 
   - entity: sensor
     name: Timer
+    class: duration
     category: diagnostic
     icon: "mdi:timer"
     dps:

+ 1 - 0
custom_components/tuya_local/devices/wetair_wch750_heater.yaml

@@ -144,6 +144,7 @@ secondary_entities:
             value: "24 hours"          
   - entity: sensor
     category: diagnostic
+    class: duration
     name: Timer
     icon: "mdi:timer"
     dps:

+ 1 - 1
tests/devices/test_anko_fan.py

@@ -25,7 +25,7 @@ class TestAnkoFan(SwitchableTests, BasicNumberTests, TuyaDeviceTestCase):
             TIMER_DPS,
             self.entities.get("number_timer"),
             max=9,
-            unit=UnitOfTime.SECONDS,
+            unit=UnitOfTime.HOURS,
         )
         self.mark_secondary(["number_timer"])
 

+ 2 - 0
tests/devices/test_avatto_blinds.py

@@ -3,6 +3,7 @@ from homeassistant.components.cover import (
     CoverDeviceClass,
     CoverEntityFeature,
 )
+from homeassistant.components.sensor import SensorDeviceClass
 from homeassistant.const import UnitOfTime
 
 from ..const import AVATTO_BLINDS_PAYLOAD
@@ -39,6 +40,7 @@ class TestAvattoBlinds(MultiSensorTests, BasicSelectTests, TuyaDeviceTestCase):
                 {
                     "dps": COUNTDOWN_DP,
                     "name": "sensor_timer",
+                    "device_class": SensorDeviceClass.DURATION,
                     "min": 0,
                     "max": 86400,
                     "unit": UnitOfTime.SECONDS,

+ 2 - 0
tests/devices/test_betterlife_bl1500_heater.py

@@ -2,6 +2,7 @@ from homeassistant.components.climate.const import (
     ClimateEntityFeature,
     HVACMode,
 )
+from homeassistant.components.sensor import SensorDeviceClass
 from homeassistant.const import UnitOfTime, UnitOfTemperature
 
 from ..const import BETTERLIFE_BL1500_PAYLOAD
@@ -63,6 +64,7 @@ class TestBetterlifeBL1500Heater(
             COUNTDOWN_DPS,
             self.entities.get("sensor_timer_countdown"),
             unit=UnitOfTime.MINUTES,
+            device_class=SensorDeviceClass.DURATION,
         )
         self.mark_secondary(
             ["lock_child_lock", "select_timer", "sensor_timer_countdown"]

+ 2 - 0
tests/devices/test_eanons_humidifier.py

@@ -6,6 +6,7 @@ from homeassistant.components.humidifier.const import (
     MODE_AUTO,
     MODE_SLEEP,
 )
+from homeassistant.components.sensor import SensorDeviceClass
 
 from ..const import EANONS_HUMIDIFIER_PAYLOAD
 from ..helpers import assert_device_properties_set
@@ -65,6 +66,7 @@ class TestEanonsHumidifier(
             TIMER_DPS,
             self.entities.get("sensor_timer"),
             unit="min",
+            device_class=SensorDeviceClass.DURATION,
         )
         self.setUpBasicBinarySensor(
             ERROR_DPS,

+ 1 - 0
tests/devices/test_essentials_purifier.py

@@ -90,6 +90,7 @@ class TestEssentialsPurifier(
                     "dps": COUNTDOWN_DP,
                     "name": "sensor_timer",
                     "unit": UnitOfTime.MINUTES,
+                    "device_class": SensorDeviceClass.DURATION,
                 },
                 {
                     "dps": PM25_DP,

+ 19 - 26
tests/devices/test_grid_connect_double_power_point.py

@@ -79,8 +79,6 @@ class TestGridConnectDoubleSwitch(
                     "name": "switch_master",
                     "dps": MASTER_DPS,
                     "device_class": SwitchDeviceClass.OUTLET,
-                    "power_dps": POWER_DPS,
-                    "power_scale": 10,
                 },
             ]
         )
@@ -148,38 +146,33 @@ class TestGridConnectDoubleSwitch(
 
     # Since we have attributes, override the default test which expects none.
     def test_multi_switch_state_attributes(self):
-        self.dps[COUNTDOWN1_DPS] = 9
-        self.dps[COUNTDOWN2_DPS] = 10
-        self.dps[VOLTAGE_DPS] = 2350
-        self.dps[CURRENT_DPS] = 1234
-        self.dps[POWER_DPS] = 5678
         self.dps[TEST_DPS] = 21
-        self.dps[CALIBV_DPS] = 22
-        self.dps[CALIBA_DPS] = 23
-        self.dps[CALIBW_DPS] = 24
-        self.dps[CALIBE_DPS] = 25
         self.assertDictEqual(
             self.multiSwitch["switch_master"].extra_state_attributes,
             {
-                "current_a": 1.234,
-                "voltage_v": 235.0,
-                "current_power_w": 567.8,
                 "test_bit": 21,
-                "voltage_calibration": 22,
-                "current_calibration": 23,
-                "power_calibration": 24,
-                "energy_calibration": 25,
             },
         )
+
+    def test_multi_sensor_extra_state_attributes(self):
+        self.dps[CALIBA_DPS] = 1
+        self.dps[CALIBE_DPS] = 2
+        self.dps[CALIBV_DPS] = 3
+        self.dps[CALIBW_DPS] = 4
+
         self.assertDictEqual(
-            self.multiSwitch["switch_outlet_1"].extra_state_attributes,
-            {
-                "countdown": 9,
-            },
+            self.multiSensor["sensor_current"].extra_state_attributes,
+            {"calibration": 1},
         )
         self.assertDictEqual(
-            self.multiSwitch["switch_outlet_2"].extra_state_attributes,
-            {
-                "countdown": 10,
-            },
+            self.multiSensor["sensor_energy"].extra_state_attributes,
+            {"calibration": 2},
+        )
+        self.assertDictEqual(
+            self.multiSensor["sensor_voltage"].extra_state_attributes,
+            {"calibration": 3},
+        )
+        self.assertDictEqual(
+            self.multiSensor["sensor_power"].extra_state_attributes,
+            {"calibration": 4},
         )

+ 2 - 0
tests/devices/test_himox_h06_purifier.py

@@ -1,5 +1,6 @@
 from homeassistant.components.button import ButtonDeviceClass
 from homeassistant.components.fan import FanEntityFeature
+from homeassistant.components.sensor import SensorDeviceClass
 from homeassistant.const import (
     PERCENTAGE,
     UnitOfTime,
@@ -80,6 +81,7 @@ class TestHimoxH06Purifier(
                     "dps": COUNTDOWN_DPS,
                     "name": "sensor_timer",
                     "unit": UnitOfTime.MINUTES,
+                    "device_class": SensorDeviceClass.DURATION,
                 },
                 {
                     "dps": AQI_DPS,

+ 2 - 0
tests/devices/test_inkbird_sousvide.py

@@ -4,6 +4,7 @@ from homeassistant.components.climate.const import (
     HVACAction,
     HVACMode,
 )
+from homeassistant.components.sensor import SensorDeviceClass
 from homeassistant.const import UnitOfTime, UnitOfTemperature
 
 from ..const import INKBIRD_SOUSVIDE_PAYLOAD
@@ -88,6 +89,7 @@ class TestInkbirdSousVideCooker(
             REMAIN_DPS,
             self.entities.get("sensor_remaining_time"),
             unit=UnitOfTime.MINUTES,
+            device_class=SensorDeviceClass.DURATION,
         )
         self.mark_secondary(
             [

+ 2 - 0
tests/devices/test_kyvol_e30_vacuum.py

@@ -1,4 +1,5 @@
 from homeassistant.components.button import ButtonDeviceClass
+from homeassistant.components.sensor import SensorDeviceClass
 from homeassistant.components.vacuum import (
     STATE_CLEANING,
     STATE_DOCKED,
@@ -81,6 +82,7 @@ class TestKyvolE30Vacuum(
                     "dps": TIME_DPS,
                     "name": "sensor_clean_time",
                     "unit": UnitOfTime.MINUTES,
+                    "device_class": SensorDeviceClass.DURATION,
                 },
                 {
                     "dps": EDGE_DPS,

+ 2 - 0
tests/devices/test_lefant_m213_vacuum.py

@@ -1,3 +1,4 @@
+from homeassistant.components.sensor import SensorDeviceClass
 from homeassistant.components.vacuum import (
     STATE_CLEANING,
     STATE_DOCKED,
@@ -50,6 +51,7 @@ class TestLefantM213Vacuum(MultiSensorTests, TuyaDeviceTestCase):
                     "dps": TIME_DPS,
                     "name": "sensor_clean_time",
                     "unit": UnitOfTime.MINUTES,
+                    "device_class": SensorDeviceClass.DURATION,
                 },
             ],
         )

+ 3 - 2
tests/devices/test_nashone_mts700wb_thermostat.py

@@ -3,6 +3,7 @@ from homeassistant.components.climate.const import (
     ClimateEntityFeature,
     HVACMode,
 )
+from homeassistant.components.sensor import SensorDeviceClass
 from homeassistant.const import (
     UnitOfTime,
 )
@@ -76,8 +77,8 @@ class TestNashoneMTS700WBThermostat(
         self.setUpBasicSensor(
             COUNTDOWN_DPS,
             self.entities.get("sensor_timer"),
-            unit=UnitOfTime.MINUTES,
-            testdata=(600, 10.0),
+            unit=UnitOfTime.SECONDS,
+            device_class=SensorDeviceClass.DURATION,
         )
         self.setUpBasicSwitch(
             RESET_DPS,

+ 1 - 0
tests/devices/test_parkside_plgs2012a1_smart_charger.py

@@ -102,6 +102,7 @@ class TestParksidePLGS2012A1Charger(
                     "name": "sensor_time_remaining",
                     "dps": REMAIN_DPS,
                     "unit": UnitOfTime.MINUTES,
+                    "device_class": SensorDeviceClass.DURATION,
                 },
                 {
                     "name": "sensor_current_temperature",

+ 1 - 0
tests/devices/test_poiema_one_purifier.py

@@ -72,6 +72,7 @@ class TestPoeimaOnePurifier(
                     "dps": COUNTDOWN_DPS,
                     "name": "sensor_timer",
                     "unit": UnitOfTime.MINUTES,
+                    "device_class": SensorDeviceClass.DURATION,
                 },
             ]
         )

+ 1 - 0
tests/devices/test_vork_vk6067aw_purifier.py

@@ -79,6 +79,7 @@ class TestVorkVK6267AWPurifier(
                     "dps": COUNTDOWN_DPS,
                     "name": "sensor_timer",
                     "unit": UnitOfTime.MINUTES,
+                    "device_class": SensorDeviceClass.DURATION,
                 },
                 {
                     "dps": FILTER_DPS,

+ 5 - 1
tests/devices/test_wetair_wch750_heater.py

@@ -5,6 +5,7 @@ from homeassistant.components.climate.const import (
     PRESET_COMFORT,
     PRESET_BOOST,
 )
+from homeassistant.components.sensor import SensorDeviceClass
 from homeassistant.const import UnitOfTime, UnitOfTemperature
 
 from ..const import WETAIR_WCH750_HEATER_PAYLOAD
@@ -85,7 +86,10 @@ class TestWetairWCH750Heater(
             },
         )
         self.setUpBasicSensor(
-            COUNTDOWN_DPS, self.entities.get("sensor_timer"), unit=UnitOfTime.MINUTES
+            COUNTDOWN_DPS,
+            self.entities.get("sensor_timer"),
+            unit=UnitOfTime.MINUTES,
+            device_class=SensorDeviceClass.DURATION,
         )
         self.mark_secondary(
             [