From dc24f83407855a7d01b4742858467a4a74d03ff4 Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Wed, 22 Jan 2025 13:27:28 -0700 Subject: [PATCH] Cleanup litterrobot select entity (#136282) --- .../components/litterrobot/select.py | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/litterrobot/select.py b/homeassistant/components/litterrobot/select.py index 6fab9c95040..06f3bfc9ce7 100644 --- a/homeassistant/components/litterrobot/select.py +++ b/homeassistant/components/litterrobot/select.py @@ -21,22 +21,16 @@ from .hub import LitterRobotHub _CastTypeT = TypeVar("_CastTypeT", int, float, str) -@dataclass(frozen=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) +@dataclass(frozen=True, kw_only=True) class RobotSelectEntityDescription( - SelectEntityDescription, RequiredKeysMixin[_RobotT, _CastTypeT] + SelectEntityDescription, Generic[_RobotT, _CastTypeT] ): """A class that describes robot select entities.""" 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] = { @@ -51,12 +45,14 @@ ROBOT_SELECT_MAP: dict[type[Robot], RobotSelectEntityDescription] = { LitterRobot4: RobotSelectEntityDescription[LitterRobot4, str]( key="panel_brightness", translation_key="brightness_level", - current_fn=lambda robot: bri.name.lower() - if (bri := robot.panel_brightness) is not None - else None, + current_fn=( + lambda robot: bri.name.lower() + if (bri := robot.panel_brightness) is not None + else None + ), options_fn=lambda _: [level.name.lower() for level in BrightnessLevel], - select_fn=lambda robot, opt: robot.set_panel_brightness( - BrightnessLevel[opt.upper()] + select_fn=( + lambda robot, opt: robot.set_panel_brightness(BrightnessLevel[opt.upper()]) ), ), FeederRobot: RobotSelectEntityDescription[FeederRobot, float](