Change litterrobot integration to cloud_push (#77741)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
0b4e4e81d4
commit
cc51052be5
11 changed files with 77 additions and 167 deletions
|
@ -16,10 +16,11 @@ from homeassistant.components.select import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TIME_MINUTES
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .entity import LitterRobotConfigEntity, _RobotT, async_update_unique_id
|
||||
from .entity import LitterRobotEntity, _RobotT, async_update_unique_id
|
||||
from .hub import LitterRobotHub
|
||||
|
||||
_CastTypeT = TypeVar("_CastTypeT", int, float)
|
||||
|
@ -31,10 +32,7 @@ class RequiredKeysMixin(Generic[_RobotT, _CastTypeT]):
|
|||
|
||||
current_fn: Callable[[_RobotT], _CastTypeT]
|
||||
options_fn: Callable[[_RobotT], list[_CastTypeT]]
|
||||
select_fn: Callable[
|
||||
[_RobotT, str],
|
||||
tuple[Callable[[_CastTypeT], Coroutine[Any, Any, bool]], _CastTypeT],
|
||||
]
|
||||
select_fn: Callable[[_RobotT, str], Coroutine[Any, Any, bool]]
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -43,6 +41,8 @@ class RobotSelectEntityDescription(
|
|||
):
|
||||
"""A class that describes robot select entities."""
|
||||
|
||||
entity_category: EntityCategory = EntityCategory.CONFIG
|
||||
|
||||
|
||||
LITTER_ROBOT_SELECT = RobotSelectEntityDescription[LitterRobot, int](
|
||||
key="cycle_delay",
|
||||
|
@ -51,7 +51,7 @@ LITTER_ROBOT_SELECT = RobotSelectEntityDescription[LitterRobot, int](
|
|||
unit_of_measurement=TIME_MINUTES,
|
||||
current_fn=lambda robot: robot.clean_cycle_wait_time_minutes,
|
||||
options_fn=lambda robot: robot.VALID_WAIT_TIMES,
|
||||
select_fn=lambda robot, option: (robot.set_wait_time, int(option)),
|
||||
select_fn=lambda robot, option: robot.set_wait_time(int(option)),
|
||||
)
|
||||
FEEDER_ROBOT_SELECT = RobotSelectEntityDescription[FeederRobot, float](
|
||||
key="meal_insert_size",
|
||||
|
@ -60,7 +60,7 @@ FEEDER_ROBOT_SELECT = RobotSelectEntityDescription[FeederRobot, float](
|
|||
unit_of_measurement="cups",
|
||||
current_fn=lambda robot: robot.meal_insert_size,
|
||||
options_fn=lambda robot: robot.VALID_MEAL_INSERT_SIZES,
|
||||
select_fn=lambda robot, option: (robot.set_meal_insert_size, float(option)),
|
||||
select_fn=lambda robot, option: robot.set_meal_insert_size(float(option)),
|
||||
)
|
||||
|
||||
|
||||
|
@ -88,7 +88,7 @@ async def async_setup_entry(
|
|||
|
||||
|
||||
class LitterRobotSelect(
|
||||
LitterRobotConfigEntity[_RobotT], SelectEntity, Generic[_RobotT, _CastTypeT]
|
||||
LitterRobotEntity[_RobotT], SelectEntity, Generic[_RobotT, _CastTypeT]
|
||||
):
|
||||
"""Litter-Robot Select."""
|
||||
|
||||
|
@ -112,5 +112,4 @@ class LitterRobotSelect(
|
|||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
"""Change the selected option."""
|
||||
action, adjusted_option = self.entity_description.select_fn(self.robot, option)
|
||||
await self.perform_action_and_refresh(action, adjusted_option)
|
||||
await self.entity_description.select_fn(self.robot, option)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue