diff --git a/homeassistant/components/synology_dsm/const.py b/homeassistant/components/synology_dsm/const.py index 8c17de5e997..b3c9f66c8da 100644 --- a/homeassistant/components/synology_dsm/const.py +++ b/homeassistant/components/synology_dsm/const.py @@ -2,6 +2,7 @@ from homeassistant.const import ( DATA_MEGABYTES, DATA_RATE_KILOBYTES_PER_SECOND, + DATA_TERABYTES, UNIT_PERCENTAGE, ) @@ -34,8 +35,8 @@ UTILISATION_SENSORS = { STORAGE_VOL_SENSORS = { "volume_status": ["Status", None, "mdi:checkbox-marked-circle-outline"], "volume_device_type": ["Type", None, "mdi:harddisk"], - "volume_size_total": ["Total Size", None, "mdi:chart-pie"], - "volume_size_used": ["Used Space", None, "mdi:chart-pie"], + "volume_size_total": ["Total Size", DATA_TERABYTES, "mdi:chart-pie"], + "volume_size_used": ["Used Space", DATA_TERABYTES, "mdi:chart-pie"], "volume_percentage_used": ["Volume Used", UNIT_PERCENTAGE, "mdi:chart-pie"], "volume_disk_temp_avg": ["Average Disk Temp", None, "mdi:thermometer"], "volume_disk_temp_max": ["Maximum Disk Temp", None, "mdi:thermometer"], diff --git a/homeassistant/components/synology_dsm/manifest.json b/homeassistant/components/synology_dsm/manifest.json index 4a538606ecb..f57f1843f45 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": ["python-synology==0.7.4"], + "requirements": ["python-synology==0.8.0"], "codeowners": ["@ProtoThis", "@Quentame"], "config_flow": true, "ssdp": [ diff --git a/homeassistant/components/synology_dsm/sensor.py b/homeassistant/components/synology_dsm/sensor.py index 6e5a486ab89..b6a88fe5a5a 100644 --- a/homeassistant/components/synology_dsm/sensor.py +++ b/homeassistant/components/synology_dsm/sensor.py @@ -7,11 +7,13 @@ from homeassistant.const import ( CONF_DISKS, DATA_MEGABYTES, DATA_RATE_KILOBYTES_PER_SECOND, + DATA_TERABYTES, TEMP_CELSIUS, ) from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import Entity from homeassistant.helpers.typing import HomeAssistantType +from homeassistant.util.temperature import celsius_to_fahrenheit from . import SynoApi from .const import ( @@ -63,7 +65,7 @@ async def async_setup_entry( class SynoNasSensor(Entity): - """Representation of a Synology NAS Sensor.""" + """Representation of a Synology NAS sensor.""" def __init__( self, @@ -142,47 +144,51 @@ class SynoNasSensor(Entity): class SynoNasUtilSensor(SynoNasSensor): - """Representation a Synology Utilisation Sensor.""" + """Representation a Synology Utilisation sensor.""" @property def state(self): """Return the state.""" - if self._unit == DATA_RATE_KILOBYTES_PER_SECOND or self._unit == DATA_MEGABYTES: - attr = getattr(self._api.utilisation, self.sensor_type)(False) + attr = getattr(self._api.utilisation, self.sensor_type) + if callable(attr): + attr = attr() + if not attr: + return None - if attr is None: - return None + # Data (RAM) + if self._unit == DATA_MEGABYTES: + return round(attr / 1024.0 ** 2, 1) - if self._unit == DATA_RATE_KILOBYTES_PER_SECOND: - return round(attr / 1024.0, 1) - if self._unit == DATA_MEGABYTES: - return round(attr / 1024.0 / 1024.0, 1) - else: - return getattr(self._api.utilisation, self.sensor_type) + # Network + if self._unit == DATA_RATE_KILOBYTES_PER_SECOND: + return round(attr / 1024.0, 1) + + return attr class SynoNasStorageSensor(SynoNasSensor): - """Representation a Synology Storage Sensor.""" + """Representation a Synology Storage sensor.""" @property def state(self): """Return the state.""" - if self.monitored_device: - if self.sensor_type in TEMP_SENSORS_KEYS: - attr = getattr(self._api.storage, self.sensor_type)( - self.monitored_device - ) + attr = getattr(self._api.storage, self.sensor_type)(self.monitored_device) + if not attr: + return None - if attr is None: - return None + # Data (disk space) + if self._unit == DATA_TERABYTES: + return round(attr / 1024.0 ** 4, 2) - if self._api.temp_unit == TEMP_CELSIUS: - return attr + # Temperature + if self._api.temp_unit == TEMP_CELSIUS: + # Celsius + return attr + if self.sensor_type in TEMP_SENSORS_KEYS: + # Fahrenheit + return celsius_to_fahrenheit(attr) - return round(attr * 1.8 + 32.0, 1) - - return getattr(self._api.storage, self.sensor_type)(self.monitored_device) - return None + return attr @property def device_info(self) -> Dict[str, any]: diff --git a/requirements_all.txt b/requirements_all.txt index b1347e7582a..9226c01a42f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1692,7 +1692,7 @@ python-sochain-api==0.0.2 python-songpal==0.11.2 # homeassistant.components.synology_dsm -python-synology==0.7.4 +python-synology==0.8.0 # homeassistant.components.tado python-tado==0.8.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 65433039238..fa570aedda9 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -662,7 +662,7 @@ python-miio==0.5.0.1 python-nest==4.1.0 # homeassistant.components.synology_dsm -python-synology==0.7.4 +python-synology==0.8.0 # homeassistant.components.tado python-tado==0.8.1