Add install UniFi device update feature (#75302)

* Add install UniFi device update feature

* Add tests for install UniFi device update feature

* Fix type error

* Process review feedback

* Process review feedback
This commit is contained in:
Jelte Zeilstra 2022-07-16 20:39:11 +02:00 committed by GitHub
parent b9c8d65940
commit 514e826fed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 118 additions and 60 deletions

View file

@ -2,6 +2,7 @@
from __future__ import annotations
import logging
from typing import Any
from homeassistant.components.update import (
DOMAIN,
@ -71,7 +72,6 @@ class UniFiDeviceUpdateEntity(UniFiBase, UpdateEntity):
DOMAIN = DOMAIN
TYPE = DEVICE_UPDATE
_attr_device_class = UpdateDeviceClass.FIRMWARE
_attr_supported_features = UpdateEntityFeature.PROGRESS
def __init__(self, device, controller):
"""Set up device update entity."""
@ -79,6 +79,11 @@ class UniFiDeviceUpdateEntity(UniFiBase, UpdateEntity):
self.device = self._item
self._attr_supported_features = UpdateEntityFeature.PROGRESS
if self.controller.site_role == "admin":
self._attr_supported_features |= UpdateEntityFeature.INSTALL
@property
def name(self) -> str:
"""Return the name of the device."""
@ -126,3 +131,9 @@ class UniFiDeviceUpdateEntity(UniFiBase, UpdateEntity):
async def options_updated(self) -> None:
"""No action needed."""
async def async_install(
self, version: str | None, backup: bool, **kwargs: Any
) -> None:
"""Install an update."""
await self.controller.api.devices.upgrade(self.device.mac)