Skip to content

Commit e602de5

Browse files
authored
Bump python-synology to 0.8.0 + Fix disk space incorrect sensor type (#35068)
* Fix Synology disk space incorrect sensor type * Review 1
1 parent 2f31b85 commit e602de5

File tree

5 files changed

+40
-33
lines changed

5 files changed

+40
-33
lines changed

homeassistant/components/synology_dsm/const.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from homeassistant.const import (
33
DATA_MEGABYTES,
44
DATA_RATE_KILOBYTES_PER_SECOND,
5+
DATA_TERABYTES,
56
UNIT_PERCENTAGE,
67
)
78

@@ -34,8 +35,8 @@
3435
STORAGE_VOL_SENSORS = {
3536
"volume_status": ["Status", None, "mdi:checkbox-marked-circle-outline"],
3637
"volume_device_type": ["Type", None, "mdi:harddisk"],
37-
"volume_size_total": ["Total Size", None, "mdi:chart-pie"],
38-
"volume_size_used": ["Used Space", None, "mdi:chart-pie"],
38+
"volume_size_total": ["Total Size", DATA_TERABYTES, "mdi:chart-pie"],
39+
"volume_size_used": ["Used Space", DATA_TERABYTES, "mdi:chart-pie"],
3940
"volume_percentage_used": ["Volume Used", UNIT_PERCENTAGE, "mdi:chart-pie"],
4041
"volume_disk_temp_avg": ["Average Disk Temp", None, "mdi:thermometer"],
4142
"volume_disk_temp_max": ["Maximum Disk Temp", None, "mdi:thermometer"],

homeassistant/components/synology_dsm/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"domain": "synology_dsm",
33
"name": "Synology DSM",
44
"documentation": "https://www.home-assistant.io/integrations/synology_dsm",
5-
"requirements": ["python-synology==0.7.4"],
5+
"requirements": ["python-synology==0.8.0"],
66
"codeowners": ["@ProtoThis", "@Quentame"],
77
"config_flow": true,
88
"ssdp": [

homeassistant/components/synology_dsm/sensor.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
CONF_DISKS,
88
DATA_MEGABYTES,
99
DATA_RATE_KILOBYTES_PER_SECOND,
10+
DATA_TERABYTES,
1011
TEMP_CELSIUS,
1112
)
1213
from homeassistant.helpers.dispatcher import async_dispatcher_connect
1314
from homeassistant.helpers.entity import Entity
1415
from homeassistant.helpers.typing import HomeAssistantType
16+
from homeassistant.util.temperature import celsius_to_fahrenheit
1517

1618
from . import SynoApi
1719
from .const import (
@@ -63,7 +65,7 @@ async def async_setup_entry(
6365

6466

6567
class SynoNasSensor(Entity):
66-
"""Representation of a Synology NAS Sensor."""
68+
"""Representation of a Synology NAS sensor."""
6769

6870
def __init__(
6971
self,
@@ -142,47 +144,51 @@ async def async_will_remove_from_hass(self):
142144

143145

144146
class SynoNasUtilSensor(SynoNasSensor):
145-
"""Representation a Synology Utilisation Sensor."""
147+
"""Representation a Synology Utilisation sensor."""
146148

147149
@property
148150
def state(self):
149151
"""Return the state."""
150-
if self._unit == DATA_RATE_KILOBYTES_PER_SECOND or self._unit == DATA_MEGABYTES:
151-
attr = getattr(self._api.utilisation, self.sensor_type)(False)
152+
attr = getattr(self._api.utilisation, self.sensor_type)
153+
if callable(attr):
154+
attr = attr()
155+
if not attr:
156+
return None
152157

153-
if attr is None:
154-
return None
158+
# Data (RAM)
159+
if self._unit == DATA_MEGABYTES:
160+
return round(attr / 1024.0 ** 2, 1)
155161

156-
if self._unit == DATA_RATE_KILOBYTES_PER_SECOND:
157-
return round(attr / 1024.0, 1)
158-
if self._unit == DATA_MEGABYTES:
159-
return round(attr / 1024.0 / 1024.0, 1)
160-
else:
161-
return getattr(self._api.utilisation, self.sensor_type)
162+
# Network
163+
if self._unit == DATA_RATE_KILOBYTES_PER_SECOND:
164+
return round(attr / 1024.0, 1)
165+
166+
return attr
162167

163168

164169
class SynoNasStorageSensor(SynoNasSensor):
165-
"""Representation a Synology Storage Sensor."""
170+
"""Representation a Synology Storage sensor."""
166171

167172
@property
168173
def state(self):
169174
"""Return the state."""
170-
if self.monitored_device:
171-
if self.sensor_type in TEMP_SENSORS_KEYS:
172-
attr = getattr(self._api.storage, self.sensor_type)(
173-
self.monitored_device
174-
)
175-
176-
if attr is None:
177-
return None
178-
179-
if self._api.temp_unit == TEMP_CELSIUS:
180-
return attr
181-
182-
return round(attr * 1.8 + 32.0, 1)
175+
attr = getattr(self._api.storage, self.sensor_type)(self.monitored_device)
176+
if not attr:
177+
return None
178+
179+
# Data (disk space)
180+
if self._unit == DATA_TERABYTES:
181+
return round(attr / 1024.0 ** 4, 2)
182+
183+
# Temperature
184+
if self._api.temp_unit == TEMP_CELSIUS:
185+
# Celsius
186+
return attr
187+
if self.sensor_type in TEMP_SENSORS_KEYS:
188+
# Fahrenheit
189+
return celsius_to_fahrenheit(attr)
183190

184-
return getattr(self._api.storage, self.sensor_type)(self.monitored_device)
185-
return None
191+
return attr
186192

187193
@property
188194
def device_info(self) -> Dict[str, any]:

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ python-sochain-api==0.0.2
16921692
python-songpal==0.11.2
16931693

16941694
# homeassistant.components.synology_dsm
1695-
python-synology==0.7.4
1695+
python-synology==0.8.0
16961696

16971697
# homeassistant.components.tado
16981698
python-tado==0.8.1

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ python-miio==0.5.0.1
662662
python-nest==4.1.0
663663

664664
# homeassistant.components.synology_dsm
665-
python-synology==0.7.4
665+
python-synology==0.8.0
666666

667667
# homeassistant.components.tado
668668
python-tado==0.8.1

0 commit comments

Comments
 (0)