1 """Support for Roborock sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from roborock.roborock_typing
import DeviceProp
11 BinarySensorDeviceClass,
13 BinarySensorEntityDescription,
19 from .
import RoborockConfigEntry
20 from .coordinator
import RoborockDataUpdateCoordinator
21 from .entity
import RoborockCoordinatedEntityV1
24 @dataclass(frozen=True, kw_only=True)
26 """A class that describes Roborock binary sensors."""
28 value_fn: Callable[[DeviceProp], bool | int |
None]
31 BINARY_SENSOR_DESCRIPTIONS = [
34 translation_key=
"mop_drying_status",
35 device_class=BinarySensorDeviceClass.RUNNING,
36 entity_category=EntityCategory.DIAGNOSTIC,
37 value_fn=
lambda data: data.status.dry_status,
40 key=
"water_box_carriage_status",
41 translation_key=
"mop_attached",
42 device_class=BinarySensorDeviceClass.CONNECTIVITY,
43 entity_category=EntityCategory.DIAGNOSTIC,
44 value_fn=
lambda data: data.status.water_box_carriage_status,
47 key=
"water_box_status",
48 translation_key=
"water_box_attached",
49 device_class=BinarySensorDeviceClass.CONNECTIVITY,
50 entity_category=EntityCategory.DIAGNOSTIC,
51 value_fn=
lambda data: data.status.water_box_status,
55 translation_key=
"water_shortage",
56 device_class=BinarySensorDeviceClass.PROBLEM,
57 entity_category=EntityCategory.DIAGNOSTIC,
58 value_fn=
lambda data: data.status.water_shortage_status,
62 translation_key=
"in_cleaning",
63 device_class=BinarySensorDeviceClass.RUNNING,
64 entity_category=EntityCategory.DIAGNOSTIC,
65 value_fn=
lambda data: data.status.in_cleaning,
72 config_entry: RoborockConfigEntry,
73 async_add_entities: AddEntitiesCallback,
75 """Set up the Roborock vacuum binary sensors."""
81 for coordinator
in config_entry.runtime_data.v1
82 for description
in BINARY_SENSOR_DESCRIPTIONS
83 if description.value_fn(coordinator.roborock_device_info.props)
is not None
88 """Representation of a Roborock binary sensor."""
90 entity_description: RoborockBinarySensorDescription
94 coordinator: RoborockDataUpdateCoordinator,
95 description: RoborockBinarySensorDescription,
97 """Initialize the entity."""
99 f
"{description.key}_{coordinator.duid_slug}",
106 """Return the value reported by the sensor."""
109 self.coordinator.roborock_device_info.props
None __init__(self, RoborockDataUpdateCoordinator coordinator, RoborockBinarySensorDescription description)
None async_setup_entry(HomeAssistant hass, RoborockConfigEntry config_entry, AddEntitiesCallback async_add_entities)