Home Assistant Unofficial Reference 2024.12.1
update.py
Go to the documentation of this file.
1 """Update platform for Sensibo integration."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Callable
6 from dataclasses import dataclass
7 
8 from pysensibo.model import SensiboDevice
9 
11  UpdateDeviceClass,
12  UpdateEntity,
13  UpdateEntityDescription,
14 )
15 from homeassistant.const import EntityCategory
16 from homeassistant.core import HomeAssistant
17 from homeassistant.helpers.entity_platform import AddEntitiesCallback
18 
19 from . import SensiboConfigEntry
20 from .coordinator import SensiboDataUpdateCoordinator
21 from .entity import SensiboDeviceBaseEntity
22 
23 PARALLEL_UPDATES = 0
24 
25 
26 @dataclass(frozen=True, kw_only=True)
28  """Describes Sensibo Update entity."""
29 
30  value_version: Callable[[SensiboDevice], str | None]
31  value_available: Callable[[SensiboDevice], str | None]
32 
33 
34 DEVICE_SENSOR_TYPES: tuple[SensiboDeviceUpdateEntityDescription, ...] = (
36  key="fw_ver_available",
37  device_class=UpdateDeviceClass.FIRMWARE,
38  entity_category=EntityCategory.DIAGNOSTIC,
39  value_version=lambda data: data.fw_ver,
40  value_available=lambda data: data.fw_ver_available,
41  ),
42 )
43 
44 
46  hass: HomeAssistant,
47  entry: SensiboConfigEntry,
48  async_add_entities: AddEntitiesCallback,
49 ) -> None:
50  """Set up Sensibo Update platform."""
51 
52  coordinator = entry.runtime_data
53 
55  SensiboDeviceUpdate(coordinator, device_id, description)
56  for description in DEVICE_SENSOR_TYPES
57  for device_id, device_data in coordinator.data.parsed.items()
58  if description.value_available(device_data) is not None
59  )
60 
61 
63  """Representation of a Sensibo Device Update."""
64 
65  entity_description: SensiboDeviceUpdateEntityDescription
66 
67  def __init__(
68  self,
69  coordinator: SensiboDataUpdateCoordinator,
70  device_id: str,
71  entity_description: SensiboDeviceUpdateEntityDescription,
72  ) -> None:
73  """Initiate Sensibo Device Update."""
74  super().__init__(coordinator, device_id)
75  self.entity_descriptionentity_description = entity_description
76  self._attr_unique_id_attr_unique_id = f"{device_id}-{entity_description.key}"
77  self._attr_title_attr_title = self.device_datadevice_data.model
78 
79  @property
80  def installed_version(self) -> str | None:
81  """Return version currently installed."""
82  return self.entity_descriptionentity_description.value_version(self.device_datadevice_data)
83 
84  @property
85  def latest_version(self) -> str | None:
86  """Return latest available version."""
87  return self.entity_descriptionentity_description.value_available(self.device_datadevice_data)
None __init__(self, SensiboDataUpdateCoordinator coordinator, str device_id, SensiboDeviceUpdateEntityDescription entity_description)
Definition: update.py:72
None async_setup_entry(HomeAssistant hass, SensiboConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: update.py:49