Add more information to Roborock Status (#93636)

Co-authored-by: Humberto Gontijo <humberto.gontijo@clevertech.biz>
This commit is contained in:
Luke 2023-05-30 12:51:57 -04:00 committed by GitHub
parent 8e05e3850b
commit de3406c856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 6 deletions

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from roborock.containers import RoborockStateCode
from roborock.roborock_typing import DeviceProp from roborock.roborock_typing import DeviceProp
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
@ -37,7 +38,7 @@ class RoborockSensorDescription(
"""A class that describes Roborock sensors.""" """A class that describes Roborock sensors."""
CONSUMABLE_SENSORS = [ SENSOR_DESCRIPTIONS = [
RoborockSensorDescription( RoborockSensorDescription(
native_unit_of_measurement=UnitOfTime.SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
key="main_brush_time_left", key="main_brush_time_left",
@ -74,9 +75,6 @@ CONSUMABLE_SENSORS = [
value_fn=lambda data: data.consumable.sensor_time_left, value_fn=lambda data: data.consumable.sensor_time_left,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
]
CLEAN_INFORMATION_SENSORS = [
RoborockSensorDescription( RoborockSensorDescription(
native_unit_of_measurement=UnitOfTime.SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
key="cleaning_time", key="cleaning_time",
@ -92,6 +90,15 @@ CLEAN_INFORMATION_SENSORS = [
device_class=SensorDeviceClass.DURATION, device_class=SensorDeviceClass.DURATION,
value_fn=lambda data: data.clean_summary.clean_time, value_fn=lambda data: data.clean_summary.clean_time,
), ),
RoborockSensorDescription(
key="status",
icon="mdi:information-outline",
device_class=SensorDeviceClass.ENUM,
translation_key="status",
value_fn=lambda data: data.status.state.name,
entity_category=EntityCategory.DIAGNOSTIC,
options=RoborockStateCode.keys(),
),
] ]
@ -111,7 +118,7 @@ async def async_setup_entry(
description, description,
) )
for device_id, coordinator in coordinators.items() for device_id, coordinator in coordinators.items()
for description in CONSUMABLE_SENSORS + CLEAN_INFORMATION_SENSORS for description in SENSOR_DESCRIPTIONS
) )

View File

@ -43,6 +43,34 @@
"sensor_time_left": { "sensor_time_left": {
"name": "Sensor time left" "name": "Sensor time left"
}, },
"status": {
"name": "Status",
"state": {
"starting": "Starting",
"charger_disconnected": "Charger disconnected",
"idle": "Idle",
"remote_control_active": "Remote control active",
"cleaning": "Cleaning",
"returning_home": "Returning home",
"manual_mode": "Manual mode",
"charging": "Charging",
"charging_problem": "Charging problem",
"paused": "Paused",
"spot_cleaning": "Spot cleaning",
"error": "Error",
"shutting_down": "Shutting down",
"updating": "Updating",
"docking": "Docking",
"going_to_target": "Going to target",
"zoned_cleaning": "Zoned cleaning",
"segment_cleaning": "Segment cleaning",
"emptying_the_bin": "Emptying the bin",
"washing_the_mop": "Washing the mop",
"going_to_wash_the_mop": "Going to wash the mop",
"charging_complete": "Charging complete",
"device_offline": "Device offline"
}
},
"total_cleaning_time": { "total_cleaning_time": {
"name": "Total cleaning time" "name": "Total cleaning time"
} }

View File

@ -14,7 +14,7 @@ from tests.common import MockConfigEntry
async def test_sensors(hass: HomeAssistant, setup_entry: MockConfigEntry) -> None: async def test_sensors(hass: HomeAssistant, setup_entry: MockConfigEntry) -> None:
"""Test sensors and check test values are correctly set.""" """Test sensors and check test values are correctly set."""
assert len(hass.states.async_all("sensor")) == 6 assert len(hass.states.async_all("sensor")) == 7
assert hass.states.get("sensor.roborock_s7_maxv_main_brush_time_left").state == str( assert hass.states.get("sensor.roborock_s7_maxv_main_brush_time_left").state == str(
MAIN_BRUSH_REPLACE_TIME - 74382 MAIN_BRUSH_REPLACE_TIME - 74382
) )
@ -31,3 +31,4 @@ async def test_sensors(hass: HomeAssistant, setup_entry: MockConfigEntry) -> Non
assert ( assert (
hass.states.get("sensor.roborock_s7_maxv_total_cleaning_time").state == "74382" hass.states.get("sensor.roborock_s7_maxv_total_cleaning_time").state == "74382"
) )
assert hass.states.get("sensor.roborock_s7_maxv_status").state == "charging"