mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Add update entity to Synology DSM (#68664)
This commit is contained in:
parent
96c607d50d
commit
61f8af8b58
@ -1179,6 +1179,7 @@ omit =
|
|||||||
homeassistant/components/synology_dsm/sensor.py
|
homeassistant/components/synology_dsm/sensor.py
|
||||||
homeassistant/components/synology_dsm/service.py
|
homeassistant/components/synology_dsm/service.py
|
||||||
homeassistant/components/synology_dsm/switch.py
|
homeassistant/components/synology_dsm/switch.py
|
||||||
|
homeassistant/components/synology_dsm/update.py
|
||||||
homeassistant/components/synology_srm/device_tracker.py
|
homeassistant/components/synology_srm/device_tracker.py
|
||||||
homeassistant/components/syslog/notify.py
|
homeassistant/components/syslog/notify.py
|
||||||
homeassistant/components/system_bridge/__init__.py
|
homeassistant/components/system_bridge/__init__.py
|
||||||
|
@ -38,6 +38,7 @@ PLATFORMS = [
|
|||||||
Platform.CAMERA,
|
Platform.CAMERA,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
Platform.SWITCH,
|
Platform.SWITCH,
|
||||||
|
Platform.UPDATE,
|
||||||
]
|
]
|
||||||
COORDINATOR_CAMERAS = "coordinator_cameras"
|
COORDINATOR_CAMERAS = "coordinator_cameras"
|
||||||
COORDINATOR_CENTRAL = "coordinator_central"
|
COORDINATOR_CENTRAL = "coordinator_central"
|
||||||
@ -112,9 +113,11 @@ class SynologyDSMSwitchEntityDescription(
|
|||||||
# Binary sensors
|
# Binary sensors
|
||||||
UPGRADE_BINARY_SENSORS: tuple[SynologyDSMBinarySensorEntityDescription, ...] = (
|
UPGRADE_BINARY_SENSORS: tuple[SynologyDSMBinarySensorEntityDescription, ...] = (
|
||||||
SynologyDSMBinarySensorEntityDescription(
|
SynologyDSMBinarySensorEntityDescription(
|
||||||
|
# Deprecated, scheduled to be removed in 2022.6 (#68664)
|
||||||
api_key=SynoCoreUpgrade.API_KEY,
|
api_key=SynoCoreUpgrade.API_KEY,
|
||||||
key="update_available",
|
key="update_available",
|
||||||
name="Update Available",
|
name="Update Available",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
device_class=BinarySensorDeviceClass.UPDATE,
|
device_class=BinarySensorDeviceClass.UPDATE,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "synology_dsm",
|
"domain": "synology_dsm",
|
||||||
"name": "Synology DSM",
|
"name": "Synology DSM",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/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"],
|
"codeowners": ["@hacf-fr", "@Quentame", "@mib1185"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"ssdp": [
|
"ssdp": [
|
||||||
|
82
homeassistant/components/synology_dsm/update.py
Normal file
82
homeassistant/components/synology_dsm/update.py
Normal file
@ -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()
|
@ -1285,7 +1285,7 @@ py-nightscout==1.2.2
|
|||||||
py-schluter==0.1.7
|
py-schluter==0.1.7
|
||||||
|
|
||||||
# homeassistant.components.synology_dsm
|
# homeassistant.components.synology_dsm
|
||||||
py-synologydsm-api==1.0.7
|
py-synologydsm-api==1.0.8
|
||||||
|
|
||||||
# homeassistant.components.zabbix
|
# homeassistant.components.zabbix
|
||||||
py-zabbix==1.1.7
|
py-zabbix==1.1.7
|
||||||
|
@ -855,7 +855,7 @@ py-melissa-climate==2.1.4
|
|||||||
py-nightscout==1.2.2
|
py-nightscout==1.2.2
|
||||||
|
|
||||||
# homeassistant.components.synology_dsm
|
# homeassistant.components.synology_dsm
|
||||||
py-synologydsm-api==1.0.7
|
py-synologydsm-api==1.0.8
|
||||||
|
|
||||||
# homeassistant.components.seventeentrack
|
# homeassistant.components.seventeentrack
|
||||||
py17track==2021.12.2
|
py17track==2021.12.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user