diff --git a/custom_components/asusrouter/const.py b/custom_components/asusrouter/const.py index df913c0..f7064a4 100644 --- a/custom_components/asusrouter/const.py +++ b/custom_components/asusrouter/const.py @@ -950,6 +950,13 @@ ] ) STATIC_BUTTONS: list[ARButtonDescription] = [ + ARButtonDescription( + key="check_update", + name="Check for updates", + icon=ICON_UPDATE, + state=AsusSystem.FIRMWARE_CHECK, + entity_registry_enabled_default=True, + ), ARButtonDescription( key="reboot", name="Reboot", diff --git a/custom_components/asusrouter/light.py b/custom_components/asusrouter/light.py index baa3e32..99a0e62 100644 --- a/custom_components/asusrouter/light.py +++ b/custom_components/asusrouter/light.py @@ -37,6 +37,7 @@ async def async_setup_entry( class ARLightLED(ARBinaryEntity, LightEntity): """AsusRouter LED light.""" + _attr_color_mode = ColorMode.ONOFF _attr_supported_color_modes = {ColorMode.ONOFF} def __init__( diff --git a/custom_components/asusrouter/manifest.json b/custom_components/asusrouter/manifest.json index 290bb49..46ec995 100644 --- a/custom_components/asusrouter/manifest.json +++ b/custom_components/asusrouter/manifest.json @@ -8,6 +8,6 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/Vaskivskyi/ha-asusrouter/issues", "loggers": ["asusrouter"], - "requirements": ["asusrouter==1.7.0"], - "version": "0.29.0" + "requirements": ["asusrouter==1.8.0"], + "version": "0.30.0" } diff --git a/custom_components/asusrouter/update.py b/custom_components/asusrouter/update.py index dc62c3e..70c750c 100644 --- a/custom_components/asusrouter/update.py +++ b/custom_components/asusrouter/update.py @@ -2,7 +2,12 @@ from __future__ import annotations -from homeassistant.components.update import UpdateEntity +import asyncio +import logging +from typing import Any + +from asusrouter.modules.system import AsusSystem +from homeassistant.components.update import UpdateEntity, UpdateEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -13,6 +18,8 @@ from .entity import ARBinaryEntity, async_setup_ar_entry from .router import ARDevice +_LOGGER = logging.getLogger(__name__) + async def async_setup_entry( hass: HomeAssistant, @@ -45,3 +52,40 @@ def __init__( self._attr_installed_version = self.extra_state_attributes.get("current") self._attr_latest_version = self.extra_state_attributes.get("available") self._attr_release_summary = self.extra_state_attributes.get("release_note") + self._attr_in_progress = False + + self._attr_supported_features = ( + UpdateEntityFeature.RELEASE_NOTES + | UpdateEntityFeature.INSTALL + | UpdateEntityFeature.PROGRESS + ) + + def release_notes(self) -> str | None: + """Return the release notes.""" + + return self.extra_state_attributes.get("release_note") + + async def async_install( + self, version: str | None, backup: bool, **kwargs: Any + ) -> None: + """Install the update.""" + try: + _LOGGER.debug( + "Trying to install Firmware update. This might take several minutes." + ) + result = await self.api.async_set_state( + state=AsusSystem.FIRMWARE_UPGRADE, + ) + if not result: + _LOGGER.debug( + "Something went wrong while trying to install the update." + ) + else: + self._attr_in_progress = True + await asyncio.sleep(120) + self._attr_in_progress = False + + except Exception as ex: # pylint: disable=broad-except + _LOGGER.error( + "An exception occurred while trying to install the update: %s", ex + )