Skip to content

Commit

Permalink
Add update platform to myuplink (home-assistant#109786)
Browse files Browse the repository at this point in the history
* Add update platform to myuplink

* Address comments from review
  • Loading branch information
astrandb authored Feb 6, 2024
1 parent 59e9010 commit 9250dd0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion homeassistant/components/myuplink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .const import DOMAIN
from .coordinator import MyUplinkDataCoordinator

PLATFORMS: list[Platform] = [Platform.SENSOR]
PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.UPDATE]


async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
Expand Down
73 changes: 73 additions & 0 deletions homeassistant/components/myuplink/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""Update entity for myUplink."""
from typing import cast

from homeassistant.components.update import (
UpdateDeviceClass,
UpdateEntity,
UpdateEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import MyUplinkDataCoordinator
from .const import DOMAIN
from .entity import MyUplinkEntity

UPDATE_DESCRIPTION = UpdateEntityDescription(
key="update",
device_class=UpdateDeviceClass.FIRMWARE,
)


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up update entity."""
entities: list[UpdateEntity] = []
coordinator: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]

# Setup update entities
for device_id in coordinator.data.devices:
entities.append(
MyUplinkDeviceUpdate(
coordinator=coordinator,
device_id=device_id,
entity_description=UPDATE_DESCRIPTION,
unique_id_suffix="upd",
)
)

async_add_entities(entities)


class MyUplinkDeviceUpdate(MyUplinkEntity, UpdateEntity):
"""Representation of a myUplink device update entity."""

def __init__(
self,
coordinator: MyUplinkDataCoordinator,
device_id: str,
entity_description: UpdateEntityDescription,
unique_id_suffix: str,
) -> None:
"""Initialize the update entity."""
super().__init__(
coordinator=coordinator,
device_id=device_id,
unique_id_suffix=unique_id_suffix,
)

self.entity_description = entity_description

@property
def installed_version(self) -> str | None:
"""Return installed_version."""
return cast(str, self.coordinator.data.devices[self.device_id].firmwareCurrent)

@property
def latest_version(self) -> str | None:
"""Return latest_version."""
return cast(str, self.coordinator.data.devices[self.device_id].firmwareDesired)

0 comments on commit 9250dd0

Please sign in to comment.