diff --git a/.coveragerc b/.coveragerc index 04fa795c966..bd9995d1c10 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1179,6 +1179,7 @@ omit = homeassistant/components/synology_dsm/sensor.py homeassistant/components/synology_dsm/service.py homeassistant/components/synology_dsm/switch.py + homeassistant/components/synology_dsm/update.py homeassistant/components/synology_srm/device_tracker.py homeassistant/components/syslog/notify.py homeassistant/components/system_bridge/__init__.py diff --git a/homeassistant/components/synology_dsm/const.py b/homeassistant/components/synology_dsm/const.py index 37100f1a759..78f1a1b916d 100644 --- a/homeassistant/components/synology_dsm/const.py +++ b/homeassistant/components/synology_dsm/const.py @@ -38,6 +38,7 @@ PLATFORMS = [ Platform.CAMERA, Platform.SENSOR, Platform.SWITCH, + Platform.UPDATE, ] COORDINATOR_CAMERAS = "coordinator_cameras" COORDINATOR_CENTRAL = "coordinator_central" @@ -112,9 +113,11 @@ class SynologyDSMSwitchEntityDescription( # Binary sensors UPGRADE_BINARY_SENSORS: tuple[SynologyDSMBinarySensorEntityDescription, ...] = ( SynologyDSMBinarySensorEntityDescription( + # Deprecated, scheduled to be removed in 2022.6 (#68664) api_key=SynoCoreUpgrade.API_KEY, key="update_available", name="Update Available", + entity_registry_enabled_default=False, device_class=BinarySensorDeviceClass.UPDATE, entity_category=EntityCategory.DIAGNOSTIC, ), diff --git a/homeassistant/components/synology_dsm/manifest.json b/homeassistant/components/synology_dsm/manifest.json index 1c9df126a89..7dcf7cf702a 100644 --- a/homeassistant/components/synology_dsm/manifest.json +++ b/homeassistant/components/synology_dsm/manifest.json @@ -2,7 +2,7 @@ "domain": "synology_dsm", "name": "Synology DSM", "documentation": "https://www.home-assistant.io/integrations/synology_dsm", - "requirements": ["py-synologydsm-api==1.0.7"], + "requirements": ["py-synologydsm-api==1.0.8"], "codeowners": ["@hacf-fr", "@Quentame", "@mib1185"], "config_flow": true, "ssdp": [ diff --git a/homeassistant/components/synology_dsm/update.py b/homeassistant/components/synology_dsm/update.py new file mode 100644 index 00000000000..a4a958b8c1a --- /dev/null +++ b/homeassistant/components/synology_dsm/update.py @@ -0,0 +1,82 @@ +"""Support for Synology DSM update platform.""" +from __future__ import annotations + +from dataclasses import dataclass +from typing import Final + +from synology_dsm.api.core.upgrade import SynoCoreUpgrade +from yarl import URL + +from homeassistant.components.update import UpdateEntity, UpdateEntityDescription +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity import EntityCategory +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from . import SynoApi, SynologyDSMBaseEntity +from .const import COORDINATOR_CENTRAL, DOMAIN, SYNO_API, SynologyDSMEntityDescription + + +@dataclass +class SynologyDSMUpdateEntityEntityDescription( + UpdateEntityDescription, SynologyDSMEntityDescription +): + """Describes Synology DSM update entity.""" + + +UPDATE_ENTITIES: Final = [ + SynologyDSMUpdateEntityEntityDescription( + api_key=SynoCoreUpgrade.API_KEY, + key="update", + name="DSM Update", + entity_category=EntityCategory.DIAGNOSTIC, + ) +] + + +async def async_setup_entry( + hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback +) -> None: + """Set up Synology DSM update entities.""" + data = hass.data[DOMAIN][entry.unique_id] + api: SynoApi = data[SYNO_API] + coordinator = data[COORDINATOR_CENTRAL] + + async_add_entities( + SynoDSMUpdateEntity(api, coordinator, description) + for description in UPDATE_ENTITIES + ) + + +class SynoDSMUpdateEntity(SynologyDSMBaseEntity, UpdateEntity): + """Mixin for update entity specific attributes.""" + + entity_description: SynologyDSMUpdateEntityEntityDescription + _attr_title = "Synology DSM" + + @property + def current_version(self) -> str | None: + """Version currently in use.""" + return self._api.information.version_string # type: ignore[no-any-return] + + @property + def latest_version(self) -> str | None: + """Latest version available for install.""" + if not self._api.upgrade.update_available: + return self.current_version + return self._api.upgrade.available_version # type: ignore[no-any-return] + + @property + def release_url(self) -> str | None: + """URL to the full release notes of the latest version available.""" + if (details := self._api.upgrade.available_version_details) is None: + return None + + url = URL("http://update.synology.com/autoupdate/whatsnew.php") + query = {"model": self._api.information.model} + if details.get("nano") > 0: + query["update_version"] = f"{details['buildnumber']}-{details['nano']}" + else: + query["update_version"] = details["buildnumber"] + + return url.update_query(query).human_repr() diff --git a/requirements_all.txt b/requirements_all.txt index 670dfc05b1a..d334ddb070f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1285,7 +1285,7 @@ py-nightscout==1.2.2 py-schluter==0.1.7 # homeassistant.components.synology_dsm -py-synologydsm-api==1.0.7 +py-synologydsm-api==1.0.8 # homeassistant.components.zabbix py-zabbix==1.1.7 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 40960451ac9..bc8d89d806a 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -855,7 +855,7 @@ py-melissa-climate==2.1.4 py-nightscout==1.2.2 # homeassistant.components.synology_dsm -py-synologydsm-api==1.0.7 +py-synologydsm-api==1.0.8 # homeassistant.components.seventeentrack py17track==2021.12.2