Add battery sensor to Roborock (#97715)
* add battery sensor * Remove translation for battery Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
3ac2106eb8
commit
df45e52dc5
2 changed files with 15 additions and 2 deletions
|
@ -13,7 +13,12 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import AREA_SQUARE_METERS, EntityCategory, UnitOfTime
|
from homeassistant.const import (
|
||||||
|
AREA_SQUARE_METERS,
|
||||||
|
PERCENTAGE,
|
||||||
|
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
|
||||||
|
@ -122,6 +127,13 @@ SENSOR_DESCRIPTIONS = [
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
options=RoborockErrorCode.keys(),
|
options=RoborockErrorCode.keys(),
|
||||||
),
|
),
|
||||||
|
RoborockSensorDescription(
|
||||||
|
key="battery",
|
||||||
|
value_fn=lambda data: data.status.battery,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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")) == 10
|
assert len(hass.states.async_all("sensor")) == 11
|
||||||
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
|
||||||
)
|
)
|
||||||
|
@ -37,3 +37,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_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_vacuum_error").state == "none"
|
||||||
|
assert hass.states.get("sensor.roborock_s7_maxv_battery").state == "100"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue