Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Litter-Robot entities for common data and methods."""
2 
3 from __future__ import annotations
4 
5 from typing import Generic, TypeVar
6 
7 from pylitterbot import Robot
8 from pylitterbot.robot import EVENT_UPDATE
9 
10 from homeassistant.helpers.device_registry import DeviceInfo
11 from homeassistant.helpers.entity import EntityDescription
13  CoordinatorEntity,
14  DataUpdateCoordinator,
15 )
16 
17 from .const import DOMAIN
18 from .hub import LitterRobotHub
19 
20 _RobotT = TypeVar("_RobotT", bound=Robot)
21 
22 
24  CoordinatorEntity[DataUpdateCoordinator[bool]], Generic[_RobotT]
25 ):
26  """Generic Litter-Robot entity representing common data and methods."""
27 
28  _attr_has_entity_name = True
29 
30  def __init__(
31  self, robot: _RobotT, hub: LitterRobotHub, description: EntityDescription
32  ) -> None:
33  """Pass coordinator to CoordinatorEntity."""
34  super().__init__(hub.coordinator)
35  self.robotrobot = robot
36  self.hubhub = hub
37  self.entity_descriptionentity_description = description
38  self._attr_unique_id_attr_unique_id = f"{self.robot.serial}-{description.key}"
39 
40  @property
41  def device_info(self) -> DeviceInfo:
42  """Return the device information for a Litter-Robot."""
43  assert self.robotrobot.serial
44  return DeviceInfo(
45  identifiers={(DOMAIN, self.robotrobot.serial)},
46  manufacturer="Litter-Robot",
47  model=self.robotrobot.model,
48  name=self.robotrobot.name,
49  sw_version=getattr(self.robotrobot, "firmware", None),
50  )
51 
52  async def async_added_to_hass(self) -> None:
53  """Set up a listener for the entity."""
54  await super().async_added_to_hass()
55  self.async_on_remove(self.robotrobot.on(EVENT_UPDATE, self.async_write_ha_state))
None __init__(self, _RobotT robot, LitterRobotHub hub, EntityDescription description)
Definition: entity.py:32