mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Check that dock error status is not None for Roborock (#101321)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
d14e5dc56a
commit
f08d66741d
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
import datetime
|
||||||
|
|
||||||
from roborock.containers import (
|
from roborock.containers import (
|
||||||
RoborockDockErrorCode,
|
RoborockDockErrorCode,
|
||||||
@ -38,7 +39,7 @@ from .device import RoborockCoordinatedEntity
|
|||||||
class RoborockSensorDescriptionMixin:
|
class RoborockSensorDescriptionMixin:
|
||||||
"""A class that describes sensor entities."""
|
"""A class that describes sensor entities."""
|
||||||
|
|
||||||
value_fn: Callable[[DeviceProp], int]
|
value_fn: Callable[[DeviceProp], StateType | datetime.datetime]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -48,6 +49,15 @@ class RoborockSensorDescription(
|
|||||||
"""A class that describes Roborock sensors."""
|
"""A class that describes Roborock sensors."""
|
||||||
|
|
||||||
|
|
||||||
|
def _dock_error_value_fn(properties: DeviceProp) -> str | None:
|
||||||
|
if (
|
||||||
|
status := properties.status.dock_error_status
|
||||||
|
) is not None and properties.status.dock_type != RoborockDockTypeCode.no_dock:
|
||||||
|
return status.name
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
SENSOR_DESCRIPTIONS = [
|
SENSOR_DESCRIPTIONS = [
|
||||||
RoborockSensorDescription(
|
RoborockSensorDescription(
|
||||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||||
@ -173,9 +183,7 @@ SENSOR_DESCRIPTIONS = [
|
|||||||
key="dock_error",
|
key="dock_error",
|
||||||
icon="mdi:garage-open",
|
icon="mdi:garage-open",
|
||||||
translation_key="dock_error",
|
translation_key="dock_error",
|
||||||
value_fn=lambda data: data.status.dock_error_status.name
|
value_fn=_dock_error_value_fn,
|
||||||
if data.status.dock_type != RoborockDockTypeCode.no_dock
|
|
||||||
else None,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
options=RoborockDockErrorCode.keys(),
|
options=RoborockDockErrorCode.keys(),
|
||||||
@ -228,7 +236,7 @@ class RoborockSensorEntity(RoborockCoordinatedEntity, SensorEntity):
|
|||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType | datetime.datetime:
|
||||||
"""Return the value reported by the sensor."""
|
"""Return the value reported by the sensor."""
|
||||||
return self.entity_description.value_fn(
|
return self.entity_description.value_fn(
|
||||||
self.coordinator.roborock_device_info.props
|
self.coordinator.roborock_device_info.props
|
||||||
|
Loading…
x
Reference in New Issue
Block a user