Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Support for Volvo On Call."""
2 
3 from homeassistant.helpers.device_registry import DeviceInfo
4 from homeassistant.helpers.update_coordinator import CoordinatorEntity
5 
6 from .const import DOMAIN
7 from .coordinator import VolvoUpdateCoordinator
8 
9 
10 class VolvoEntity(CoordinatorEntity[VolvoUpdateCoordinator]):
11  """Base class for all VOC entities."""
12 
13  def __init__(
14  self,
15  vin: str,
16  component: str,
17  attribute: str,
18  slug_attr: str,
19  coordinator: VolvoUpdateCoordinator,
20  ) -> None:
21  """Initialize the entity."""
22  super().__init__(coordinator)
23 
24  self.vinvin = vin
25  self.componentcomponent = component
26  self.attributeattribute = attribute
27  self.slug_attrslug_attr = slug_attr
28 
29  @property
30  def instrument(self):
31  """Return corresponding instrument."""
32  return self.coordinator.volvo_data.instrument(
33  self.vinvin, self.componentcomponent, self.attributeattribute, self.slug_attrslug_attr
34  )
35 
36  @property
37  def icon(self):
38  """Return the icon."""
39  return self.instrumentinstrument.icon
40 
41  @property
42  def vehicle(self):
43  """Return vehicle."""
44  return self.instrumentinstrument.vehicle
45 
46  @property
47  def _entity_name(self):
48  return self.instrumentinstrument.name
49 
50  @property
51  def _vehicle_name(self):
52  return self.coordinator.volvo_data.vehicle_name(self.vehiclevehicle)
53 
54  @property
55  def name(self):
56  """Return full name of the entity."""
57  return f"{self._vehicle_name} {self._entity_name}"
58 
59  @property
60  def assumed_state(self):
61  """Return true if unable to access real state of entity."""
62  return True
63 
64  @property
65  def device_info(self) -> DeviceInfo:
66  """Return a inique set of attributes for each vehicle."""
67  return DeviceInfo(
68  identifiers={(DOMAIN, self.vehiclevehicle.vin)},
69  name=self._vehicle_name_vehicle_name,
70  model=self.vehiclevehicle.vehicle_type,
71  manufacturer="Volvo",
72  )
73 
74  @property
76  """Return device specific state attributes."""
77  return dict(
78  self.instrumentinstrument.attributes,
79  model=f"{self.vehicle.vehicle_type}/{self.vehicle.model_year}",
80  )
81 
82  @property
83  def unique_id(self) -> str:
84  """Return a unique ID."""
85  slug_override = ""
86  if self.instrumentinstrument.slug_override is not None:
87  slug_override = f"-{self.instrument.slug_override}"
88  return f"{self.vin}-{self.component}-{self.attribute}{slug_override}"
None __init__(self, str vin, str component, str attribute, str slug_attr, VolvoUpdateCoordinator coordinator)
Definition: entity.py:20