Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base class for SwitchBot via API entities."""
2 
3 from typing import Any
4 
5 from switchbot_api import Commands, Device, Remote, SwitchBotAPI
6 
7 from homeassistant.helpers.device_registry import DeviceInfo
8 from homeassistant.helpers.update_coordinator import CoordinatorEntity
9 
10 from .const import DOMAIN
11 from .coordinator import SwitchBotCoordinator
12 
13 
14 class SwitchBotCloudEntity(CoordinatorEntity[SwitchBotCoordinator]):
15  """Representation of a SwitchBot Cloud entity."""
16 
17  _api: SwitchBotAPI
18  _switchbot_state: dict[str, Any] | None = None
19  _attr_has_entity_name = True
20 
21  def __init__(
22  self,
23  api: SwitchBotAPI,
24  device: Device | Remote,
25  coordinator: SwitchBotCoordinator,
26  ) -> None:
27  """Initialize the entity."""
28  super().__init__(coordinator)
29  self._api_api_api = api
30  self._attr_unique_id_attr_unique_id = device.device_id
31  self._attr_device_info_attr_device_info = DeviceInfo(
32  identifiers={(DOMAIN, device.device_id)},
33  name=device.device_name,
34  manufacturer="SwitchBot",
35  model=device.device_type,
36  )
37 
38  async def send_api_command(
39  self,
40  command: Commands,
41  command_type: str = "command",
42  parameters: dict | str = "default",
43  ) -> None:
44  """Send command to device."""
45  await self._api_api_api.send_command(
46  self._attr_unique_id_attr_unique_id,
47  command,
48  command_type,
49  parameters,
50  )
None send_api_command(self, Commands command, str command_type="command", dict|str parameters="default")
Definition: entity.py:43
None __init__(self, SwitchBotAPI api, Device|Remote device, SwitchBotCoordinator coordinator)
Definition: entity.py:26