Cleanup litterrobot select entity (#136282)
parent
f8dc3d6624
commit
dc24f83407
|
@ -21,22 +21,16 @@ from .hub import LitterRobotHub
|
||||||
_CastTypeT = TypeVar("_CastTypeT", int, float, str)
|
_CastTypeT = TypeVar("_CastTypeT", int, float, str)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
class RequiredKeysMixin(Generic[_RobotT, _CastTypeT]):
|
|
||||||
"""A class that describes robot select entity required keys."""
|
|
||||||
|
|
||||||
current_fn: Callable[[_RobotT], _CastTypeT | None]
|
|
||||||
options_fn: Callable[[_RobotT], list[_CastTypeT]]
|
|
||||||
select_fn: Callable[[_RobotT, str], Coroutine[Any, Any, bool]]
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class RobotSelectEntityDescription(
|
class RobotSelectEntityDescription(
|
||||||
SelectEntityDescription, RequiredKeysMixin[_RobotT, _CastTypeT]
|
SelectEntityDescription, Generic[_RobotT, _CastTypeT]
|
||||||
):
|
):
|
||||||
"""A class that describes robot select entities."""
|
"""A class that describes robot select entities."""
|
||||||
|
|
||||||
entity_category: EntityCategory = EntityCategory.CONFIG
|
entity_category: EntityCategory = EntityCategory.CONFIG
|
||||||
|
current_fn: Callable[[_RobotT], _CastTypeT | None]
|
||||||
|
options_fn: Callable[[_RobotT], list[_CastTypeT]]
|
||||||
|
select_fn: Callable[[_RobotT, str], Coroutine[Any, Any, bool]]
|
||||||
|
|
||||||
|
|
||||||
ROBOT_SELECT_MAP: dict[type[Robot], RobotSelectEntityDescription] = {
|
ROBOT_SELECT_MAP: dict[type[Robot], RobotSelectEntityDescription] = {
|
||||||
|
@ -51,12 +45,14 @@ ROBOT_SELECT_MAP: dict[type[Robot], RobotSelectEntityDescription] = {
|
||||||
LitterRobot4: RobotSelectEntityDescription[LitterRobot4, str](
|
LitterRobot4: RobotSelectEntityDescription[LitterRobot4, str](
|
||||||
key="panel_brightness",
|
key="panel_brightness",
|
||||||
translation_key="brightness_level",
|
translation_key="brightness_level",
|
||||||
current_fn=lambda robot: bri.name.lower()
|
current_fn=(
|
||||||
if (bri := robot.panel_brightness) is not None
|
lambda robot: bri.name.lower()
|
||||||
else None,
|
if (bri := robot.panel_brightness) is not None
|
||||||
|
else None
|
||||||
|
),
|
||||||
options_fn=lambda _: [level.name.lower() for level in BrightnessLevel],
|
options_fn=lambda _: [level.name.lower() for level in BrightnessLevel],
|
||||||
select_fn=lambda robot, opt: robot.set_panel_brightness(
|
select_fn=(
|
||||||
BrightnessLevel[opt.upper()]
|
lambda robot, opt: robot.set_panel_brightness(BrightnessLevel[opt.upper()])
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
FeederRobot: RobotSelectEntityDescription[FeederRobot, float](
|
FeederRobot: RobotSelectEntityDescription[FeederRobot, float](
|
||||||
|
|
Loading…
Reference in New Issue