parent
3b08d5f0c3
commit
eab024992e
|
@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import EntityCategory, UnitOfTime
|
from homeassistant.const import AREA_SQUARE_METERS, EntityCategory, UnitOfTime
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
@ -99,6 +99,20 @@ SENSOR_DESCRIPTIONS = [
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
options=RoborockStateCode.keys(),
|
options=RoborockStateCode.keys(),
|
||||||
),
|
),
|
||||||
|
RoborockSensorDescription(
|
||||||
|
key="cleaning_area",
|
||||||
|
icon="mdi:texture-box",
|
||||||
|
translation_key="cleaning_area",
|
||||||
|
value_fn=lambda data: data.status.square_meter_clean_area,
|
||||||
|
native_unit_of_measurement=AREA_SQUARE_METERS,
|
||||||
|
),
|
||||||
|
RoborockSensorDescription(
|
||||||
|
key="total_cleaning_area",
|
||||||
|
icon="mdi:texture-box",
|
||||||
|
translation_key="total_cleaning_area",
|
||||||
|
value_fn=lambda data: data.clean_summary.square_meter_clean_area,
|
||||||
|
native_unit_of_measurement=AREA_SQUARE_METERS,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,6 +133,7 @@ async def async_setup_entry(
|
||||||
)
|
)
|
||||||
for device_id, coordinator in coordinators.items()
|
for device_id, coordinator in coordinators.items()
|
||||||
for description in SENSOR_DESCRIPTIONS
|
for description in SENSOR_DESCRIPTIONS
|
||||||
|
if description.value_fn(coordinator.roborock_device_info.props) is not None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
"cleaning_area": {
|
||||||
|
"name": "Cleaning area"
|
||||||
|
},
|
||||||
"cleaning_time": {
|
"cleaning_time": {
|
||||||
"name": "Cleaning time"
|
"name": "Cleaning time"
|
||||||
},
|
},
|
||||||
|
@ -73,6 +76,9 @@
|
||||||
},
|
},
|
||||||
"total_cleaning_time": {
|
"total_cleaning_time": {
|
||||||
"name": "Total cleaning time"
|
"name": "Total cleaning time"
|
||||||
|
},
|
||||||
|
"total_cleaning_area": {
|
||||||
|
"name": "Total cleaning area"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"select": {
|
"select": {
|
||||||
|
|
|
@ -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")) == 7
|
assert len(hass.states.async_all("sensor")) == 9
|
||||||
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
|
||||||
)
|
)
|
||||||
|
@ -32,3 +32,7 @@ async def test_sensors(hass: HomeAssistant, setup_entry: MockConfigEntry) -> Non
|
||||||
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"
|
assert hass.states.get("sensor.roborock_s7_maxv_status").state == "charging"
|
||||||
|
assert (
|
||||||
|
hass.states.get("sensor.roborock_s7_maxv_total_cleaning_area").state == "1159.2"
|
||||||
|
)
|
||||||
|
assert hass.states.get("sensor.roborock_s7_maxv_cleaning_area").state == "21.0"
|
||||||
|
|
Loading…
Reference in New Issue