Change litterrobot integration to cloud_push (#77741)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Nathan Spencer 2022-09-17 03:29:56 -06:00 committed by GitHub
parent 0b4e4e81d4
commit cc51052be5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 77 additions and 167 deletions

View file

@ -14,10 +14,11 @@ from homeassistant.components.switch import (
)
from homeassistant.config_entries import ConfigEntry
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
@ -26,31 +27,33 @@ class RequiredKeysMixin(Generic[_RobotT]):
"""A class that describes robot switch entity required keys."""
icons: tuple[str, str]
set_fn: Callable[[_RobotT], Callable[[bool], Coroutine[Any, Any, bool]]]
set_fn: Callable[[_RobotT, bool], Coroutine[Any, Any, bool]]
@dataclass
class RobotSwitchEntityDescription(SwitchEntityDescription, RequiredKeysMixin[_RobotT]):
"""A class that describes robot switch entities."""
entity_category: EntityCategory = EntityCategory.CONFIG
ROBOT_SWITCHES = [
RobotSwitchEntityDescription[Union[LitterRobot, FeederRobot]](
key="night_light_mode_enabled",
name="Night Light Mode",
icons=("mdi:lightbulb-on", "mdi:lightbulb-off"),
set_fn=lambda robot: robot.set_night_light,
set_fn=lambda robot, value: robot.set_night_light(value),
),
RobotSwitchEntityDescription[Union[LitterRobot, FeederRobot]](
key="panel_lock_enabled",
name="Panel Lockout",
icons=("mdi:lock", "mdi:lock-open"),
set_fn=lambda robot: robot.set_panel_lockout,
set_fn=lambda robot, value: robot.set_panel_lockout(value),
),
]
class RobotSwitchEntity(LitterRobotConfigEntity[_RobotT], SwitchEntity):
class RobotSwitchEntity(LitterRobotEntity[_RobotT], SwitchEntity):
"""Litter-Robot switch entity."""
entity_description: RobotSwitchEntityDescription[_RobotT]
@ -58,8 +61,6 @@ class RobotSwitchEntity(LitterRobotConfigEntity[_RobotT], SwitchEntity):
@property
def is_on(self) -> bool | None:
"""Return true if switch is on."""
if self._refresh_callback is not None:
return self._assumed_state
return bool(getattr(self.robot, self.entity_description.key))
@property
@ -70,13 +71,11 @@ class RobotSwitchEntity(LitterRobotConfigEntity[_RobotT], SwitchEntity):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on."""
set_fn = self.entity_description.set_fn
await self.perform_action_and_assume_state(set_fn(self.robot), True)
await self.entity_description.set_fn(self.robot, True)
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off."""
set_fn = self.entity_description.set_fn
await self.perform_action_and_assume_state(set_fn(self.robot), False)
await self.entity_description.set_fn(self.robot, False)
async def async_setup_entry(