Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 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 Down Expand Up @@ -340,6 +344,7 @@ def _fetch_device_configuration(self):
self.information = self.dsm.information
self.network = self.dsm.network
self.network.update()
self.upgrade = self.dsm.upgrade

if self._with_security:
self.security = self.dsm.security
Expand Down
17 changes: 17 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,12 @@ 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.
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