-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
""" | ||
Support for Bayernluefter update. | ||
""" | ||
|
||
import logging | ||
from typing import Any | ||
|
||
from homeassistant.components.update import ( | ||
UpdateEntity, | ||
UpdateEntityDescription, | ||
UpdateEntityFeature, | ||
UpdateDeviceClass, | ||
) | ||
|
||
from pyernluefter import UpdateTarget | ||
|
||
from . import ( | ||
BayernluefterEntity, | ||
BayernluefterDataUpdateCoordinator as DataUpdateCoordinator, | ||
) | ||
|
||
from .const import DOMAIN | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
"""Set up update entries.""" | ||
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id] | ||
entities = [BayernluefterUpdate(coordinator)] | ||
async_add_entities(entities) | ||
|
||
|
||
class BayernluefterUpdate(BayernluefterEntity, UpdateEntity): | ||
"""An update implementation for Bayernluefter devices.""" | ||
|
||
entity_description = UpdateEntityDescription( | ||
key="FW_WiFi", device_class=UpdateDeviceClass.FIRMWARE | ||
) | ||
|
||
target = UpdateTarget.WLAN32 | ||
|
||
# These update specific attributes are not (yet) part of UpdateEntityDescription | ||
_attr_supported_features = UpdateEntityFeature.INSTALL | ||
|
||
def __init__( | ||
self, | ||
coordinator: DataUpdateCoordinator, | ||
) -> None: | ||
"""Initialize an update entity for a Bayernluefter device.""" | ||
super().__init__(coordinator, self.entity_description) | ||
self._attr_release_url = self._device.release_url(self.target) | ||
|
||
@property | ||
def available(self) -> bool: | ||
return ( | ||
self._coordinator.last_update_success | ||
and self._device.installed_version(self.target) is not None | ||
) | ||
|
||
@property | ||
def latest_version(self) -> str: | ||
return self._device.latest_version(self.target) | ||
|
||
@property | ||
def installed_version(self) -> str: | ||
return self._device.installed_version(self.target) | ||
|
||
async def async_install( | ||
self, version: str | None, backup: bool, **kwargs: Any | ||
) -> None: | ||
"""Install the latest firmware version.""" | ||
await self._device.update_check(self.target) |