Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Base classes for Crownstone devices."""
2 
3 from __future__ import annotations
4 
5 from crownstone_cloud.cloud_models.crownstones import Crownstone
6 
7 from homeassistant.helpers.device_registry import DeviceInfo
8 from homeassistant.helpers.entity import Entity
9 
10 from .const import CROWNSTONE_INCLUDE_TYPES, DOMAIN
11 
12 
14  """Base entity class for Crownstone devices."""
15 
16  _attr_should_poll = False
17  _attr_has_entity_name = True
18 
19  def __init__(self, device: Crownstone) -> None:
20  """Initialize the device."""
21  self.devicedevice = device
22 
23  @property
24  def cloud_id(self) -> str:
25  """Return the unique identifier for this device.
26 
27  Used as device ID and to generate unique entity ID's.
28  """
29  return str(self.devicedevice.cloud_id)
30 
31  @property
32  def device_info(self) -> DeviceInfo:
33  """Return device info."""
34  return DeviceInfo(
35  identifiers={(DOMAIN, self.cloud_idcloud_id)},
36  manufacturer="Crownstone",
37  model=CROWNSTONE_INCLUDE_TYPES[self.devicedevice.type],
38  name=self.devicedevice.name,
39  sw_version=self.devicedevice.sw_version,
40  )