Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Common entity for VeSync Component."""
2 
3 from typing import Any
4 
5 from pyvesync.vesyncbasedevice import VeSyncBaseDevice
6 
7 from homeassistant.helpers.device_registry import DeviceInfo
8 from homeassistant.helpers.entity import Entity, ToggleEntity
9 
10 from .const import DOMAIN
11 
12 
14  """Base class for VeSync Entity Representations."""
15 
16  _attr_has_entity_name = True
17 
18  def __init__(self, device: VeSyncBaseDevice) -> None:
19  """Initialize the VeSync device."""
20  self.devicedevice = device
21  self._attr_unique_id_attr_unique_id = self.base_unique_idbase_unique_id
22 
23  @property
24  def base_unique_id(self):
25  """Return the ID of this device."""
26  # The unique_id property may be overridden in subclasses, such as in
27  # sensors. Maintaining base_unique_id allows us to group related
28  # entities under a single device.
29  if isinstance(self.devicedevice.sub_device_no, int):
30  return f"{self.device.cid}{self.device.sub_device_no!s}"
31  return self.devicedevice.cid
32 
33  @property
34  def available(self) -> bool:
35  """Return True if device is available."""
36  return self.devicedevice.connection_status == "online"
37 
38  @property
39  def device_info(self) -> DeviceInfo:
40  """Return device information."""
41  return DeviceInfo(
42  identifiers={(DOMAIN, self.base_unique_idbase_unique_id)},
43  name=self.devicedevice.device_name,
44  model=self.devicedevice.device_type,
45  manufacturer="VeSync",
46  sw_version=self.devicedevice.current_firm_version,
47  )
48 
49  def update(self) -> None:
50  """Update vesync device."""
51  self.devicedevice.update()
52 
53 
55  """Base class for VeSync Device Representations."""
56 
57  @property
58  def details(self):
59  """Provide access to the device details dictionary."""
60  return self.devicedevice.details
61 
62  @property
63  def is_on(self) -> bool:
64  """Return True if device is on."""
65  return self.devicedevice.device_status == "on"
66 
67  def turn_off(self, **kwargs: Any) -> None:
68  """Turn the device off."""
69  self.devicedevice.turn_off()
None __init__(self, VeSyncBaseDevice device)
Definition: entity.py:18