1 """Support for Litter-Robot binary sensors."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from typing
import Generic
9 from pylitterbot
import LitterRobot, Robot
12 BinarySensorDeviceClass,
14 BinarySensorEntityDescription,
20 from .
import LitterRobotConfigEntry
21 from .entity
import LitterRobotEntity, _RobotT
24 @dataclass(frozen=True)
26 """A class that describes robot binary sensor entity required keys."""
28 is_on_fn: Callable[[_RobotT], bool]
31 @dataclass(frozen=True)
33 BinarySensorEntityDescription, RequiredKeysMixin[_RobotT]
35 """A class that describes robot binary sensor entities."""
39 """Litter-Robot binary sensor entity."""
41 entity_description: RobotBinarySensorEntityDescription[_RobotT]
45 """Return the state."""
49 BINARY_SENSOR_MAP: dict[type[Robot], tuple[RobotBinarySensorEntityDescription, ...]] = {
51 RobotBinarySensorEntityDescription[LitterRobot](
53 translation_key=
"sleeping",
54 entity_category=EntityCategory.DIAGNOSTIC,
55 entity_registry_enabled_default=
False,
56 is_on_fn=
lambda robot: robot.is_sleeping,
58 RobotBinarySensorEntityDescription[LitterRobot](
60 translation_key=
"sleep_mode",
61 entity_category=EntityCategory.DIAGNOSTIC,
62 entity_registry_enabled_default=
False,
63 is_on_fn=
lambda robot: robot.sleep_mode_enabled,
67 RobotBinarySensorEntityDescription[Robot](
69 translation_key=
"power_status",
70 device_class=BinarySensorDeviceClass.PLUG,
71 entity_category=EntityCategory.DIAGNOSTIC,
72 entity_registry_enabled_default=
False,
73 is_on_fn=
lambda robot: robot.power_status ==
"AC",
81 entry: LitterRobotConfigEntry,
82 async_add_entities: AddEntitiesCallback,
84 """Set up Litter-Robot binary sensors using config entry."""
85 hub = entry.runtime_data
88 for robot
in hub.account.robots
89 for robot_type, entity_descriptions
in BINARY_SENSOR_MAP.items()
90 if isinstance(robot, robot_type)
91 for description
in entity_descriptions
None async_setup_entry(HomeAssistant hass, LitterRobotConfigEntry entry, AddEntitiesCallback async_add_entities)