Skip to content

Commit

Permalink
Add new sensors to Roborock (#99983)
Browse files Browse the repository at this point in the history
* Add 3 new sensor types

* add state options for dock error

* add unit of measurement
  • Loading branch information
Lash-L authored Sep 9, 2023
1 parent 092580a commit 602e36a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
36 changes: 35 additions & 1 deletion homeassistant/components/roborock/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from collections.abc import Callable
from dataclasses import dataclass

from roborock.containers import RoborockErrorCode, RoborockStateCode
from roborock.containers import (
RoborockDockErrorCode,
RoborockDockTypeCode,
RoborockErrorCode,
RoborockStateCode,
)
from roborock.roborock_typing import DeviceProp

from homeassistant.components.sensor import (
Expand Down Expand Up @@ -134,6 +139,35 @@ class RoborockSensorDescription(
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY,
),
# Only available on some newer models
RoborockSensorDescription(
key="clean_percent",
icon="mdi:progress-check",
translation_key="clean_percent",
value_fn=lambda data: data.status.clean_percent,
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=PERCENTAGE,
),
# Only available with more than just the basic dock
RoborockSensorDescription(
key="dock_error",
icon="mdi:garage-open",
translation_key="dock_error",
value_fn=lambda data: data.status.dock_error_status.name
if data.status.dock_type != RoborockDockTypeCode.no_dock
else None,
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.ENUM,
options=RoborockDockErrorCode.keys(),
),
RoborockSensorDescription(
key="mop_clean_remaining",
native_unit_of_measurement=UnitOfTime.SECONDS,
device_class=SensorDeviceClass.DURATION,
value_fn=lambda data: data.status.rdt,
translation_key="mop_drying_remaining_time",
entity_category=EntityCategory.DIAGNOSTIC,
),
]


Expand Down
17 changes: 17 additions & 0 deletions homeassistant/components/roborock/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,26 @@
"cleaning_time": {
"name": "Cleaning time"
},
"clean_percent": {
"name": "Cleaning progress"
},
"dock_error": {
"name": "Dock error",
"state": {
"ok": "Ok",
"duct_blockage": "Duct blockage",
"water_empty": "Water empty",
"waste_water_tank_full": "Waste water tank full",
"dirty_tank_latch_open": "Dirty tank latch open",
"no_dustbin": "No dustbin"
}
},
"main_brush_time_left": {
"name": "Main brush time left"
},
"mop_drying_remaining_time": {
"name": "Mop drying remaining time"
},
"side_brush_time_left": {
"name": "Side brush time left"
},
Expand Down
3 changes: 2 additions & 1 deletion tests/components/roborock/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

async def test_sensors(hass: HomeAssistant, setup_entry: MockConfigEntry) -> None:
"""Test sensors and check test values are correctly set."""
assert len(hass.states.async_all("sensor")) == 11
assert len(hass.states.async_all("sensor")) == 12
assert hass.states.get("sensor.roborock_s7_maxv_main_brush_time_left").state == str(
MAIN_BRUSH_REPLACE_TIME - 74382
)
Expand All @@ -38,3 +38,4 @@ async def test_sensors(hass: HomeAssistant, setup_entry: MockConfigEntry) -> Non
assert hass.states.get("sensor.roborock_s7_maxv_cleaning_area").state == "21.0"
assert hass.states.get("sensor.roborock_s7_maxv_vacuum_error").state == "none"
assert hass.states.get("sensor.roborock_s7_maxv_battery").state == "100"
assert hass.states.get("sensor.roborock_s7_maxv_dock_error").state == "ok"

0 comments on commit 602e36a

Please sign in to comment.