Skip to content

Commit

Permalink
Vacuums: separate battery into its own sensor entity
Browse files Browse the repository at this point in the history
In HA 2023.8, the battery_level attribute on vacuums is deprecated, to
be replaced by separate sensors.

Issue make-all#954
Obsoletes PR make-all#969 for Proscenic M9
  • Loading branch information
make-all committed Aug 9, 2023
1 parent 1c9fe24 commit 452a138
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 57 deletions.
1 change: 0 additions & 1 deletion custom_components/tuya_local/devices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_local/devices/kabum_smart500_vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_local/devices/kogan_lx10_vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_local/devices/kyvol_e30_vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_local/devices/lefant_ls1_vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_local/devices/lefant_m213_vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_local/devices/lenovo_e1_vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_local/devices/moebot_s_mower.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions custom_components/tuya_local/devices/proscenic_m9_vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 9 additions & 3 deletions custom_components/tuya_local/devices/rinkmo_d2_vacuum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion custom_components/tuya_local/helpers/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def has_entity_name(self):
@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
Expand Down
9 changes: 0 additions & 9 deletions custom_components/tuya_local/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self, device: TuyaLocalDevice, config: TuyaEntityConfig):
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)
Expand All @@ -66,8 +65,6 @@ def supported_features(self):
| VacuumEntityFeature.STATUS
| VacuumEntityFeature.SEND_COMMAND
)
if self._battery_dps:
support |= VacuumEntityFeature.BATTERY
if self._fan_dps:
support |= VacuumEntityFeature.FAN_SPEED
if self._power_dps:
Expand All @@ -94,12 +91,6 @@ def supported_features(self):

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."""
Expand Down
14 changes: 8 additions & 6 deletions tests/devices/test_kyvol_e30_vacuum.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -98,6 +98,13 @@ def setUp(self):
"dps": STATUS_DPS,
"name": "sensor_status",
},
{
"dps": BATTERY_DPS,
"name": "sensor_battery",
"unit": PERCENTAGE,
"device_class": SensorDeviceClass.BATTERY,
"state_class": STATE_CLASS_MEASUREMENT,
},
],
)

Expand All @@ -122,7 +129,6 @@ def test_supported_features(self):
VacuumEntityFeature.STATE
| VacuumEntityFeature.STATUS
| VacuumEntityFeature.SEND_COMMAND
| VacuumEntityFeature.BATTERY
| VacuumEntityFeature.FAN_SPEED
| VacuumEntityFeature.TURN_ON
| VacuumEntityFeature.TURN_OFF
Expand All @@ -134,10 +140,6 @@ def test_supported_features(self):
),
)

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")
Expand Down
16 changes: 9 additions & 7 deletions tests/devices/test_lefant_m213_vacuum.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -8,7 +8,7 @@
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
Expand Down Expand Up @@ -52,6 +52,13 @@ def setUp(self):
"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"])
Expand All @@ -63,7 +70,6 @@ def test_supported_features(self):
VacuumEntityFeature.STATE
| VacuumEntityFeature.STATUS
| VacuumEntityFeature.SEND_COMMAND
| VacuumEntityFeature.BATTERY
| VacuumEntityFeature.TURN_ON
| VacuumEntityFeature.TURN_OFF
| VacuumEntityFeature.START
Expand All @@ -75,10 +81,6 @@ def test_supported_features(self):
),
)

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")
Expand Down
3 changes: 1 addition & 2 deletions tests/devices/test_moebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def test_supported_features(self):
self.assertEqual(
self.subject.supported_features,
(
VacuumEntityFeature.BATTERY
| VacuumEntityFeature.CLEAN_SPOT
VacuumEntityFeature.CLEAN_SPOT
| VacuumEntityFeature.PAUSE
| VacuumEntityFeature.RETURN_HOME
| VacuumEntityFeature.SEND_COMMAND
Expand Down

0 comments on commit 452a138

Please sign in to comment.