Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions homeassistant/components/synology_dsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from synology_dsm import SynologyDSM
from synology_dsm.api.core.security import SynoCoreSecurity
from synology_dsm.api.core.upgrade import SynoCoreUpgrade
from synology_dsm.api.core.utilization import SynoCoreUtilization
from synology_dsm.api.dsm.information import SynoDSMInformation
from synology_dsm.api.dsm.network import SynoDSMNetwork
Expand Down Expand Up @@ -230,6 +231,7 @@ def __init__(self, hass: HomeAssistantType, entry: ConfigEntry):
self.information: SynoDSMInformation = None
self.network: SynoDSMNetwork = None
self.security: SynoCoreSecurity = None
self.upgrade: SynoCoreUpgrade = None
self.storage: SynoStorage = None
self.utilisation: SynoCoreUtilization = None
self.surveillance_station: SynoSurveillanceStation = None
Expand All @@ -238,6 +240,7 @@ def __init__(self, hass: HomeAssistantType, entry: ConfigEntry):
self._fetching_entities = {}
self._with_security = True
self._with_storage = True
self._with_upgrade = True
self._with_utilisation = True
self._with_information = True
self._with_surveillance_station = True
Expand Down Expand Up @@ -308,6 +311,7 @@ def _async_setup_api_requests(self):
self._fetching_entities.get(SynoCoreSecurity.API_KEY)
)
self._with_storage = bool(self._fetching_entities.get(SynoStorage.API_KEY))
self._with_upgrade = bool(self._fetching_entities.get(SynoCoreUpgrade.API_KEY))
self._with_utilisation = bool(
self._fetching_entities.get(SynoCoreUtilization.API_KEY)
)
Expand All @@ -327,6 +331,10 @@ def _async_setup_api_requests(self):
self.dsm.reset(self.storage)
self.storage = None

if not self._with_upgrade:
self.dsm.reset(self.upgrade)
self.upgrade = None

if not self._with_utilisation:
self.dsm.reset(self.utilisation)
self.utilisation = None
Expand All @@ -347,6 +355,9 @@ def _fetch_device_configuration(self):
if self._with_storage:
self.storage = self.dsm.storage

if self._with_upgrade:
self.upgrade = self.dsm.upgrade

if self._with_utilisation:
self.utilisation = self.dsm.utilisation

Expand Down
22 changes: 22 additions & 0 deletions homeassistant/components/synology_dsm/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
SECURITY_BINARY_SENSORS,
STORAGE_DISK_BINARY_SENSORS,
SYNO_API,
UPGRADE_BINARY_SENSORS,
)


Expand All @@ -29,6 +30,13 @@ async def async_setup_entry(
for sensor_type in SECURITY_BINARY_SENSORS
]

entities += [
SynoDSMUpgradeBinarySensor(
api, sensor_type, UPGRADE_BINARY_SENSORS[sensor_type]
)
for sensor_type in UPGRADE_BINARY_SENSORS
]

# Handle all disks
if api.storage.disks_ids:
for disk in entry.data.get(CONF_DISKS, api.storage.disks_ids):
Expand Down Expand Up @@ -68,3 +76,17 @@ class SynoDSMStorageBinarySensor(SynologyDSMDeviceEntity, BinarySensorEntity):
def is_on(self) -> bool:
"""Return the state."""
return getattr(self._api.storage, self.entity_type)(self._device_id)


class SynoDSMUpgradeBinarySensor(SynologyDSMEntity, BinarySensorEntity):
"""Representation a Synology Upgrade binary sensor."""

@property
def is_on(self) -> bool:
"""Return the state."""
return getattr(self._api.upgrade, self.entity_type)
Comment thread
Quentame marked this conversation as resolved.

@property
def available(self) -> bool:
"""Return True if entity is available."""
return bool(self._api.upgrade)
11 changes: 11 additions & 0 deletions homeassistant/components/synology_dsm/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Constants for Synology DSM."""

from synology_dsm.api.core.security import SynoCoreSecurity
from synology_dsm.api.core.upgrade import SynoCoreUpgrade
from synology_dsm.api.core.utilization import SynoCoreUtilization
from synology_dsm.api.dsm.information import SynoDSMInformation
from synology_dsm.api.storage.storage import SynoStorage
Expand Down Expand Up @@ -43,6 +44,16 @@
# Entity keys should start with the API_KEY to fetch

# Binary sensors
UPGRADE_BINARY_SENSORS = {
f"{SynoCoreUpgrade.API_KEY}:update_available": {
ENTITY_NAME: "Update available",
ENTITY_UNIT: None,
ENTITY_ICON: "mdi:update",
ENTITY_CLASS: None,
ENTITY_ENABLE: True,
},
}

SECURITY_BINARY_SENSORS = {
f"{SynoCoreSecurity.API_KEY}:status": {
ENTITY_NAME: "Security status",
Expand Down