4
0
Эх сурвалжийг харах

Vacuums: separate battery into its own sensor entity

In HA 2023.8, the battery_level attribute on vacuums is deprecated, to
be replaced by separate sensors.

Issue #954
Obsoletes PR #969 for Proscenic M9
Jason Rumney 2 жил өмнө
parent
commit
452a138ce1

+ 0 - 1
custom_components/tuya_local/devices/README.md

@@ -632,7 +632,6 @@ The value "off" will be used for turning off the siren, and will be filtered fro
 - **locate** (optional, boolean): a dp to trigger a locator beep on the vacuum.
 - **power** (optional, boolean): a dp to switch full system power on and off
 - **activate** (optional, boolean): a dp to start and pause the vacuum
-- **battery** (optional, number 0-100): a dp that reports the current battery level (%)
 - **direction_control** (optional, mapping of strings): a dp that is used for directional commands
     These are additional commands that are not part of **status**. They can be sent as general commands from HA.
 - **error** (optional, bitfield): a dp that reports error status.

+ 8 - 3
custom_components/tuya_local/devices/kabum_smart500_vacuum.yaml

@@ -26,9 +26,6 @@ primary_entity:
           value: land_check
         - dps_val: 64
           value: collision
-    - id: 14
-      name: battery
-      type: integer
     - id: 25
       type: boolean
       name: activate
@@ -92,6 +89,14 @@ primary_entity:
         - dps_val: high
           value: High
 secondary_entities:
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 14
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
   - entity: switch
     name: Mute voice
     icon: "mdi:account-voice"

+ 8 - 3
custom_components/tuya_local/devices/kogan_lx10_vacuum.yaml

@@ -53,9 +53,6 @@ primary_entity:
           value: charged
         - dps_val: remotectl
           value: remotectl
-    - id: 106
-      name: battery
-      type: integer
     - id: 109
       name: fan_speed # fan_mode
       type: string
@@ -144,6 +141,14 @@ secondary_entities:
       - id: 103
         name: switch
         type: boolean
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 106
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
   - entity: sensor
     name: Current clean time
     category: diagnostic

+ 8 - 3
custom_components/tuya_local/devices/kyvol_e30_vacuum.yaml

@@ -64,9 +64,6 @@ primary_entity:
           value: right
         - dps_val: stop
           value: stop
-    - id: 6
-      name: battery
-      type: integer
     - id: 13
       type: boolean
       name: locate
@@ -119,6 +116,14 @@ primary_entity:
       type: integer
       name: carpet_adaptive
 secondary_entities:
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 6
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
   - entity: sensor
     name: Clean time
     category: diagnostic

+ 8 - 3
custom_components/tuya_local/devices/lefant_ls1_vacuum.yaml

@@ -54,9 +54,6 @@ primary_entity:
           value: charged
         - dps_val: sleep
           value: sleep
-    - id: 8
-      type: integer
-      name: battery
     - id: 9
       type: string
       name: fan_speed
@@ -113,6 +110,14 @@ secondary_entities:
         unit: m2
         mapping:
           - scale: 10
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 8
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
   - entity: sensor
     name: Water tank
     category: diagnostic

+ 8 - 3
custom_components/tuya_local/devices/lefant_m213_vacuum.yaml

@@ -59,9 +59,6 @@ primary_entity:
           value: random
         - dps_val: "7"
           value: standby
-    - id: 6
-      name: battery
-      type: integer
     - id: 13
       type: boolean
       name: locate
@@ -134,6 +131,14 @@ primary_entity:
       name: robot_info
       optional: true
 secondary_entities:
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 6
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
   - entity: sensor
     name: Clean area
     category: diagnostic

+ 8 - 3
custom_components/tuya_local/devices/lenovo_e1_vacuum.yaml

@@ -94,9 +94,6 @@ primary_entity:
           value: right
         - dps_val: stop
           value: stop
-    - id: 108
-      type: integer
-      name: battery
     - id: 112
       type: string
       name: activate
@@ -134,6 +131,14 @@ secondary_entities:
         type: integer
         name: sensor
         unit: min
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 108
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
   - entity: sensor
     name: Brush life
     icon: "mdi:pinwheel"

+ 9 - 4
custom_components/tuya_local/devices/mellerware_citymove_vacuum.yaml

@@ -100,10 +100,6 @@ primary_entity:
           value: right
         - dps_val: stop
           value: stop
-    - id: 108
-      type: integer
-      name: battery
-      optional: true
     - id: 112
       type: string
       name: activate
@@ -157,6 +153,15 @@ secondary_entities:
         name: sensor
         unit: min
         optional: true
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 108
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
+        optional: true
   - entity: sensor
     name: Brush remaining
     category: diagnostic

+ 8 - 3
custom_components/tuya_local/devices/moebot_s_mower.yaml

@@ -8,9 +8,6 @@ primary_entity:
   entity: vacuum
   icon: "mdi:robot-mower"
   dps:
-    - id: 6
-      name: battery
-      type: integer
     - id: 101
       name: status
       type: string
@@ -78,6 +75,14 @@ primary_entity:
       name: auto_mode
       optional: true
 secondary_entities:
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 6
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
   - entity: binary_sensor
     name: Error
     class: problem

+ 8 - 3
custom_components/tuya_local/devices/proscenic_m9_vacuum.yaml

@@ -82,9 +82,6 @@ primary_entity:
           value: seek_dust_bucket
         - dps_val: collecting_dust
           value: collecting_dust
-    - id: 8
-      name: battery
-      type: integer
     - id: 9
       name: fan_speed
       type: string
@@ -215,6 +212,14 @@ secondary_entities:
         mapping:
           - scale: 1
             step: 1
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 8
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement
   - entity: select
     name: Water setting
     icon: "mdi:water"

+ 9 - 3
custom_components/tuya_local/devices/rinkmo_d2_vacuum.yaml

@@ -56,9 +56,6 @@ primary_entity:
           value: standby
         - dps_val: paused
           value: paused
-    - id: 6
-      type: integer
-      name: battery
     - id: 13
       type: boolean
       name: locate
@@ -81,3 +78,12 @@ primary_entity:
         - dps_val: 64
           value: collision
         - dps_val: 512
+secondary_entities:
+  - entity: sensor
+    class: battery
+    dps:
+      - id: 6
+        type: integer
+        name: sensor
+        unit: "%"
+        class: measurement

+ 1 - 1
custom_components/tuya_local/helpers/mixin.py

@@ -44,7 +44,7 @@ class TuyaLocalEntity:
     @property
     def name(self):
         """Return the name for the UI."""
-        super_name = getattr(super(), 'name')
+        super_name = getattr(super(), "name")
         return self._config.name or super_name
 
     @property

+ 0 - 9
custom_components/tuya_local/vacuum.py

@@ -49,7 +49,6 @@ class TuyaLocalVacuum(TuyaLocalEntity, StateVacuumEntity):
         self._locate_dps = dps_map.get("locate")
         self._power_dps = dps_map.get("power")
         self._activate_dps = dps_map.get("activate")
-        self._battery_dps = dps_map.pop("battery", None)
         self._direction_dps = dps_map.get("direction_control")
         self._error_dps = dps_map.get("error")
         self._fan_dps = dps_map.pop("fan_speed", None)
@@ -66,8 +65,6 @@ class TuyaLocalVacuum(TuyaLocalEntity, StateVacuumEntity):
             | VacuumEntityFeature.STATUS
             | VacuumEntityFeature.SEND_COMMAND
         )
-        if self._battery_dps:
-            support |= VacuumEntityFeature.BATTERY
         if self._fan_dps:
             support |= VacuumEntityFeature.FAN_SPEED
         if self._power_dps:
@@ -94,12 +91,6 @@ class TuyaLocalVacuum(TuyaLocalEntity, StateVacuumEntity):
 
         return support
 
-    @property
-    def battery_level(self):
-        """Return the battery level of the vacuum cleaner."""
-        if self._battery_dps:
-            return self._battery_dps.get_value(self._device)
-
     @property
     def status(self):
         """Return the status of the vacuum cleaner."""

+ 8 - 6
tests/devices/test_kyvol_e30_vacuum.py

@@ -1,5 +1,5 @@
 from homeassistant.components.button import ButtonDeviceClass
-from homeassistant.components.sensor import SensorDeviceClass
+from homeassistant.components.sensor import SensorDeviceClass, STATE_CLASS_MEASUREMENT
 from homeassistant.components.vacuum import (
     STATE_CLEANING,
     STATE_DOCKED,
@@ -98,6 +98,13 @@ class TestKyvolE30Vacuum(MultiButtonTests, MultiSensorTests, TuyaDeviceTestCase)
                     "dps": STATUS_DPS,
                     "name": "sensor_status",
                 },
+                {
+                    "dps": BATTERY_DPS,
+                    "name": "sensor_battery",
+                    "unit": PERCENTAGE,
+                    "device_class": SensorDeviceClass.BATTERY,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                },
             ],
         )
 
@@ -122,7 +129,6 @@ class TestKyvolE30Vacuum(MultiButtonTests, MultiSensorTests, TuyaDeviceTestCase)
                 VacuumEntityFeature.STATE
                 | VacuumEntityFeature.STATUS
                 | VacuumEntityFeature.SEND_COMMAND
-                | VacuumEntityFeature.BATTERY
                 | VacuumEntityFeature.FAN_SPEED
                 | VacuumEntityFeature.TURN_ON
                 | VacuumEntityFeature.TURN_OFF
@@ -134,10 +140,6 @@ class TestKyvolE30Vacuum(MultiButtonTests, MultiSensorTests, TuyaDeviceTestCase)
             ),
         )
 
-    def test_battery_level(self):
-        self.dps[BATTERY_DPS] = 50
-        self.assertEqual(self.subject.battery_level, 50)
-
     def test_status(self):
         self.dps[COMMAND_DPS] = "standby"
         self.assertEqual(self.subject.status, "standby")

+ 9 - 7
tests/devices/test_lefant_m213_vacuum.py

@@ -1,4 +1,4 @@
-from homeassistant.components.sensor import SensorDeviceClass
+from homeassistant.components.sensor import SensorDeviceClass, STATE_CLASS_MEASUREMENT
 from homeassistant.components.vacuum import (
     STATE_CLEANING,
     STATE_DOCKED,
@@ -8,7 +8,7 @@ from homeassistant.components.vacuum import (
     STATE_RETURNING,
     VacuumEntityFeature,
 )
-from homeassistant.const import AREA_SQUARE_METERS, UnitOfTime
+from homeassistant.const import AREA_SQUARE_METERS, PERCENTAGE, UnitOfTime
 
 from ..const import LEFANT_M213_VACUUM_PAYLOAD
 from ..helpers import assert_device_properties_set
@@ -52,6 +52,13 @@ class TestLefantM213Vacuum(MultiSensorTests, TuyaDeviceTestCase):
                     "unit": UnitOfTime.MINUTES,
                     "device_class": SensorDeviceClass.DURATION,
                 },
+                {
+                    "dps": BATTERY_DPS,
+                    "name": "sensor_battery",
+                    "unit": PERCENTAGE,
+                    "device_class": SensorDeviceClass.BATTERY,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                },
             ],
         )
         self.mark_secondary(["sensor_clean_area", "sensor_clean_time"])
@@ -63,7 +70,6 @@ class TestLefantM213Vacuum(MultiSensorTests, TuyaDeviceTestCase):
                 VacuumEntityFeature.STATE
                 | VacuumEntityFeature.STATUS
                 | VacuumEntityFeature.SEND_COMMAND
-                | VacuumEntityFeature.BATTERY
                 | VacuumEntityFeature.TURN_ON
                 | VacuumEntityFeature.TURN_OFF
                 | VacuumEntityFeature.START
@@ -75,10 +81,6 @@ class TestLefantM213Vacuum(MultiSensorTests, TuyaDeviceTestCase):
             ),
         )
 
-    def test_battery_level(self):
-        self.dps[BATTERY_DPS] = 50
-        self.assertEqual(self.subject.battery_level, 50)
-
     def test_fan_speed(self):
         self.dps[FAN_DPS] = "low"
         self.assertEqual(self.subject.fan_speed, "Low")

+ 1 - 2
tests/devices/test_moebot.py

@@ -48,8 +48,7 @@ class TestMoebot(TuyaDeviceTestCase):
         self.assertEqual(
             self.subject.supported_features,
             (
-                VacuumEntityFeature.BATTERY
-                | VacuumEntityFeature.CLEAN_SPOT
+                VacuumEntityFeature.CLEAN_SPOT
                 | VacuumEntityFeature.PAUSE
                 | VacuumEntityFeature.RETURN_HOME
                 | VacuumEntityFeature.SEND_COMMAND