Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 2 deletions homeassistant/components/synology_dsm/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from homeassistant.const import (
DATA_MEGABYTES,
DATA_RATE_KILOBYTES_PER_SECOND,
DATA_TERABYTES,
UNIT_PERCENTAGE,
)

Expand Down Expand Up @@ -34,8 +35,8 @@
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"],
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/synology_dsm/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
55 changes: 29 additions & 26 deletions homeassistant/components/synology_dsm/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
CONF_DISKS,
DATA_MEGABYTES,
DATA_RATE_KILOBYTES_PER_SECOND,
DATA_TERABYTES,
TEMP_CELSIUS,
)
from homeassistant.helpers.dispatcher import async_dispatcher_connect
Expand Down Expand Up @@ -63,7 +64,7 @@ async def async_setup_entry(


class SynoNasSensor(Entity):
"""Representation of a Synology NAS Sensor."""
"""Representation of a Synology NAS sensor."""

def __init__(
self,
Expand Down Expand Up @@ -142,47 +143,49 @@ async def async_will_remove_from_hass(self):


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 / 1024.0, 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 / 1024.0 / 1024.0 / 1024.0, 2)

if self._api.temp_unit == TEMP_CELSIUS:
return attr

return round(attr * 1.8 + 32.0, 1)
# Temperature
if self._api.temp_unit == TEMP_CELSIUS:
return attr
if self.sensor_type in TEMP_SENSORS_KEYS:
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]:
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down