1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-03 14:14:40 +01:00
Files
core/homeassistant/components/vesync/update.py
T
cdnninja 96d1e3d260 Use runtime_data in VeSync (#159720)
Co-authored-by: Joostlek <joostlek@outlook.com>
2025-12-29 14:40:35 +01:00

69 lines
2.1 KiB
Python

"""Update entity for VeSync.."""
from pyvesync.base_devices.vesyncbasedevice import VeSyncBaseDevice
from pyvesync.device_container import DeviceContainer
from homeassistant.components.update import UpdateDeviceClass, UpdateEntity
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import VS_DEVICES, VS_DISCOVERY
from .coordinator import VesyncConfigEntry, VeSyncDataCoordinator
from .entity import VeSyncBaseEntity
async def async_setup_entry(
hass: HomeAssistant,
config_entry: VesyncConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up update entity."""
coordinator = config_entry.runtime_data
@callback
def discover(devices: list[VeSyncBaseDevice]) -> None:
"""Add new devices to platform."""
_setup_entities(devices, async_add_entities, coordinator)
config_entry.async_on_unload(
async_dispatcher_connect(hass, VS_DISCOVERY.format(VS_DEVICES), discover)
)
_setup_entities(
config_entry.runtime_data.manager.devices, async_add_entities, coordinator
)
@callback
def _setup_entities(
devices: DeviceContainer | list[VeSyncBaseDevice],
async_add_entities: AddConfigEntryEntitiesCallback,
coordinator: VeSyncDataCoordinator,
) -> None:
"""Check if device is a light and add entity."""
async_add_entities(
VeSyncDeviceUpdate(
device=device,
coordinator=coordinator,
)
for device in devices
)
class VeSyncDeviceUpdate(VeSyncBaseEntity, UpdateEntity):
"""Representation of a VeSync device update entity."""
_attr_device_class = UpdateDeviceClass.FIRMWARE
@property
def installed_version(self) -> str | None:
"""Return installed_version."""
return self.device.current_firm_version
@property
def latest_version(self) -> str | None:
"""Return latest_version."""
return self.device.latest_firm_version