Home Assistant Unofficial Reference 2024.12.1
update.py
Go to the documentation of this file.
1 """Airgradient Update platform."""
2 
3 from datetime import timedelta
4 
5 from propcache import cached_property
6 
7 from homeassistant.components.update import UpdateDeviceClass, UpdateEntity
8 from homeassistant.core import HomeAssistant
9 from homeassistant.helpers.entity_platform import AddEntitiesCallback
10 
11 from . import AirGradientConfigEntry, AirGradientCoordinator
12 from .entity import AirGradientEntity
13 
14 SCAN_INTERVAL = timedelta(hours=1)
15 
16 
18  hass: HomeAssistant,
19  config_entry: AirGradientConfigEntry,
20  async_add_entities: AddEntitiesCallback,
21 ) -> None:
22  """Set up Airgradient update platform."""
23 
24  coordinator = config_entry.runtime_data
25 
26  async_add_entities([AirGradientUpdate(coordinator)], True)
27 
28 
30  """Representation of Airgradient Update."""
31 
32  _attr_device_class = UpdateDeviceClass.FIRMWARE
33 
34  def __init__(self, coordinator: AirGradientCoordinator) -> None:
35  """Initialize the entity."""
36  super().__init__(coordinator)
37  self._attr_unique_id_attr_unique_id = f"{coordinator.serial_number}-update"
38 
39  @cached_property
40  def should_poll(self) -> bool:
41  """Return True because we need to poll the latest version."""
42  return True
43 
44  @property
45  def installed_version(self) -> str:
46  """Return the installed version of the entity."""
47  return self.coordinator.data.measures.firmware_version
48 
49  async def async_update(self) -> None:
50  """Update the entity."""
51  self._attr_latest_version_attr_latest_version = (
52  await self.coordinator.client.get_latest_firmware_version(
53  self.coordinator.serial_number
54  )
55  )
None __init__(self, AirGradientCoordinator coordinator)
Definition: update.py:34
None async_setup_entry(HomeAssistant hass, AirGradientConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: update.py:21