mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Use kw_only attribute for remaining entity descriptions in litterrobot (#136202)
* Use kw_only attribute for binary sensor descriptions in litterrobot * Update time.py with kw_only for litterrobot * Wrap multiline lambda
This commit is contained in:
parent
29f9c88041
commit
67ca9e45b5
@ -21,29 +21,13 @@ from . import LitterRobotConfigEntry
|
||||
from .entity import LitterRobotEntity, _RobotT
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RequiredKeysMixin(Generic[_RobotT]):
|
||||
"""A class that describes robot binary sensor entity required keys."""
|
||||
|
||||
is_on_fn: Callable[[_RobotT], bool]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class RobotBinarySensorEntityDescription(
|
||||
BinarySensorEntityDescription, RequiredKeysMixin[_RobotT]
|
||||
BinarySensorEntityDescription, Generic[_RobotT]
|
||||
):
|
||||
"""A class that describes robot binary sensor entities."""
|
||||
|
||||
|
||||
class LitterRobotBinarySensorEntity(LitterRobotEntity[_RobotT], BinarySensorEntity):
|
||||
"""Litter-Robot binary sensor entity."""
|
||||
|
||||
entity_description: RobotBinarySensorEntityDescription[_RobotT]
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state."""
|
||||
return self.entity_description.is_on_fn(self.robot)
|
||||
is_on_fn: Callable[[_RobotT], bool]
|
||||
|
||||
|
||||
BINARY_SENSOR_MAP: dict[type[Robot], tuple[RobotBinarySensorEntityDescription, ...]] = {
|
||||
@ -90,3 +74,14 @@ async def async_setup_entry(
|
||||
if isinstance(robot, robot_type)
|
||||
for description in entity_descriptions
|
||||
)
|
||||
|
||||
|
||||
class LitterRobotBinarySensorEntity(LitterRobotEntity[_RobotT], BinarySensorEntity):
|
||||
"""Litter-Robot binary sensor entity."""
|
||||
|
||||
entity_description: RobotBinarySensorEntityDescription[_RobotT]
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state."""
|
||||
return self.entity_description.is_on_fn(self.robot)
|
||||
|
@ -19,19 +19,14 @@ from . import LitterRobotConfigEntry
|
||||
from .entity import LitterRobotEntity, _RobotT
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RequiredKeysMixin(Generic[_RobotT]):
|
||||
"""A class that describes robot time entity required keys."""
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class RobotTimeEntityDescription(TimeEntityDescription, Generic[_RobotT]):
|
||||
"""A class that describes robot time entities."""
|
||||
|
||||
value_fn: Callable[[_RobotT], time | None]
|
||||
set_fn: Callable[[_RobotT, time], Coroutine[Any, Any, bool]]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RobotTimeEntityDescription(TimeEntityDescription, RequiredKeysMixin[_RobotT]):
|
||||
"""A class that describes robot time entities."""
|
||||
|
||||
|
||||
def _as_local_time(start: datetime | None) -> time | None:
|
||||
"""Return a datetime as local time."""
|
||||
return dt_util.as_local(start).time() if start else None
|
||||
@ -42,8 +37,11 @@ LITTER_ROBOT_3_SLEEP_START = RobotTimeEntityDescription[LitterRobot3](
|
||||
translation_key="sleep_mode_start_time",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
value_fn=lambda robot: _as_local_time(robot.sleep_mode_start_time),
|
||||
set_fn=lambda robot, value: robot.set_sleep_mode(
|
||||
robot.sleep_mode_enabled, value.replace(tzinfo=dt_util.get_default_time_zone())
|
||||
set_fn=(
|
||||
lambda robot, value: robot.set_sleep_mode(
|
||||
robot.sleep_mode_enabled,
|
||||
value.replace(tzinfo=dt_util.get_default_time_zone()),
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user