Check that dock error status is not None for Roborock (#101321)
Co-authored-by: Robert Resch <robert@resch.dev>pull/101378/head
parent
d14e5dc56a
commit
f08d66741d
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
import datetime
|
||||
|
||||
from roborock.containers import (
|
||||
RoborockDockErrorCode,
|
||||
|
@ -38,7 +39,7 @@ from .device import RoborockCoordinatedEntity
|
|||
class RoborockSensorDescriptionMixin:
|
||||
"""A class that describes sensor entities."""
|
||||
|
||||
value_fn: Callable[[DeviceProp], int]
|
||||
value_fn: Callable[[DeviceProp], StateType | datetime.datetime]
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -48,6 +49,15 @@ class RoborockSensorDescription(
|
|||
"""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 = [
|
||||
RoborockSensorDescription(
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
|
@ -173,9 +183,7 @@ SENSOR_DESCRIPTIONS = [
|
|||
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,
|
||||
value_fn=_dock_error_value_fn,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=RoborockDockErrorCode.keys(),
|
||||
|
@ -228,7 +236,7 @@ class RoborockSensorEntity(RoborockCoordinatedEntity, SensorEntity):
|
|||
self.entity_description = description
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
def native_value(self) -> StateType | datetime.datetime:
|
||||
"""Return the value reported by the sensor."""
|
||||
return self.entity_description.value_fn(
|
||||
self.coordinator.roborock_device_info.props
|
||||
|
|
Loading…
Reference in New Issue