From dc3a4401af294feefa98cc3c149a46286f4ccf49 Mon Sep 17 00:00:00 2001 From: Ivan Coppa Date: Mon, 28 Oct 2024 21:07:35 +0100 Subject: [PATCH] Fix vacuum battery reporting for PUREi9 and 700series (#153) * fix vacuum battery reporting for PUREi9 and 700series * fix battery range minimum for 700series --- custom_components/wellbeing/api.py | 14 +++++--------- custom_components/wellbeing/vacuum.py | 8 +++++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/custom_components/wellbeing/api.py b/custom_components/wellbeing/api.py index be2d2f5..18e8c16 100644 --- a/custom_components/wellbeing/api.py +++ b/custom_components/wellbeing/api.py @@ -233,12 +233,6 @@ def _create_entities(data): attr="waterPumpRate", device_class=SensorDeviceClass.ENUM, ), - ApplianceSensor( - name="Battery Status", - attr="batteryStatus", - unit=PERCENTAGE, - device_class=SensorDeviceClass.BATTERY, - ), ApplianceSensor( name="Charging Status", attr="chargingStatus", @@ -396,9 +390,11 @@ def speed_range(self) -> tuple[int, int]: @property def battery_range(self) -> tuple[int, int]: - if self.model == Model.PUREi9: - return 2, 6 # Do not include lowest value of 1 to make this mean empty (0%) battery - + match Model(self.model): + case Model.Robot700series.value: + return 1, 100 + case Model.PUREi9.value: + return 2, 6 # Do not include lowest value of 1 to make this mean empty (0%) battery return 0, 0 @property diff --git a/custom_components/wellbeing/vacuum.py b/custom_components/wellbeing/vacuum.py index 80da077..8b3d428 100644 --- a/custom_components/wellbeing/vacuum.py +++ b/custom_components/wellbeing/vacuum.py @@ -53,7 +53,7 @@ "sleeping": STATE_DOCKED, # robot700series sleeping } -VACUUM_CHARGING_STATE = 9 # For selecting battery icon +VACUUM_CHARGING_STATES = [9, 'idle'] async def async_setup_entry(hass, entry, async_add_devices): @@ -111,8 +111,11 @@ def battery_level(self): def battery_icon(self): """Return the battery icon of the vacuum based on the battery level.""" level = self.battery_level - charging = self.get_entity.state == VACUUM_CHARGING_STATE + + charging = self.get_entity.state in VACUUM_CHARGING_STATES + level = 10*round(level / 10) # Round level to nearest 10 for icon selection + # Special cases given available icons if level == 100 and charging: return "mdi:battery-charging-100" @@ -145,7 +148,6 @@ async def async_start(self): command="play" case Model.Robot700series.value: command="startGlobalClean" - _LOGGER.warning(f"VACUUM async_start {self.entity_type} {self.entity_attr} {command}") await self.api.command_vacuum(self.pnc_id, command) async def async_stop(self):