mirror of
https://github.com/home-assistant/core.git
synced 2026-01-25 09:02:38 +01:00
71 lines
2.1 KiB
Python
71 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
|
|
|
|
PARALLEL_UPDATES = 0
|
|
|
|
|
|
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
|