Bump python-synology to 0.8.0 + Fix disk space incorrect sensor type (#35068)

* Fix Synology disk space incorrect sensor type

* Review 1
This commit is contained in:
Quentame 2020-05-02 20:31:15 +02:00 committed by GitHub
parent 2f31b8576e
commit e602de55ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 31 deletions

View File

@ -2,6 +2,7 @@
from homeassistant.const import ( from homeassistant.const import (
DATA_MEGABYTES, DATA_MEGABYTES,
DATA_RATE_KILOBYTES_PER_SECOND, DATA_RATE_KILOBYTES_PER_SECOND,
DATA_TERABYTES,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
) )
@ -34,8 +35,8 @@ UTILISATION_SENSORS = {
STORAGE_VOL_SENSORS = { STORAGE_VOL_SENSORS = {
"volume_status": ["Status", None, "mdi:checkbox-marked-circle-outline"], "volume_status": ["Status", None, "mdi:checkbox-marked-circle-outline"],
"volume_device_type": ["Type", None, "mdi:harddisk"], "volume_device_type": ["Type", None, "mdi:harddisk"],
"volume_size_total": ["Total Size", None, "mdi:chart-pie"], "volume_size_total": ["Total Size", DATA_TERABYTES, "mdi:chart-pie"],
"volume_size_used": ["Used Space", None, "mdi:chart-pie"], "volume_size_used": ["Used Space", DATA_TERABYTES, "mdi:chart-pie"],
"volume_percentage_used": ["Volume Used", UNIT_PERCENTAGE, "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_avg": ["Average Disk Temp", None, "mdi:thermometer"],
"volume_disk_temp_max": ["Maximum Disk Temp", None, "mdi:thermometer"], "volume_disk_temp_max": ["Maximum Disk Temp", None, "mdi:thermometer"],

View File

@ -2,7 +2,7 @@
"domain": "synology_dsm", "domain": "synology_dsm",
"name": "Synology DSM", "name": "Synology DSM",
"documentation": "https://www.home-assistant.io/integrations/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"], "codeowners": ["@ProtoThis", "@Quentame"],
"config_flow": true, "config_flow": true,
"ssdp": [ "ssdp": [

View File

@ -7,11 +7,13 @@ from homeassistant.const import (
CONF_DISKS, CONF_DISKS,
DATA_MEGABYTES, DATA_MEGABYTES,
DATA_RATE_KILOBYTES_PER_SECOND, DATA_RATE_KILOBYTES_PER_SECOND,
DATA_TERABYTES,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util.temperature import celsius_to_fahrenheit
from . import SynoApi from . import SynoApi
from .const import ( from .const import (
@ -63,7 +65,7 @@ async def async_setup_entry(
class SynoNasSensor(Entity): class SynoNasSensor(Entity):
"""Representation of a Synology NAS Sensor.""" """Representation of a Synology NAS sensor."""
def __init__( def __init__(
self, self,
@ -142,47 +144,51 @@ class SynoNasSensor(Entity):
class SynoNasUtilSensor(SynoNasSensor): class SynoNasUtilSensor(SynoNasSensor):
"""Representation a Synology Utilisation Sensor.""" """Representation a Synology Utilisation sensor."""
@property @property
def state(self): def state(self):
"""Return the state.""" """Return the state."""
if self._unit == DATA_RATE_KILOBYTES_PER_SECOND or self._unit == DATA_MEGABYTES: attr = getattr(self._api.utilisation, self.sensor_type)
attr = getattr(self._api.utilisation, self.sensor_type)(False) if callable(attr):
attr = attr()
if attr is None: if not attr:
return None return None
# Data (RAM)
if self._unit == DATA_MEGABYTES:
return round(attr / 1024.0 ** 2, 1)
# Network
if self._unit == DATA_RATE_KILOBYTES_PER_SECOND: if self._unit == DATA_RATE_KILOBYTES_PER_SECOND:
return round(attr / 1024.0, 1) return round(attr / 1024.0, 1)
if self._unit == DATA_MEGABYTES:
return round(attr / 1024.0 / 1024.0, 1) return attr
else:
return getattr(self._api.utilisation, self.sensor_type)
class SynoNasStorageSensor(SynoNasSensor): class SynoNasStorageSensor(SynoNasSensor):
"""Representation a Synology Storage Sensor.""" """Representation a Synology Storage sensor."""
@property @property
def state(self): def state(self):
"""Return the state.""" """Return the state."""
if self.monitored_device: attr = getattr(self._api.storage, self.sensor_type)(self.monitored_device)
if self.sensor_type in TEMP_SENSORS_KEYS: if not attr:
attr = getattr(self._api.storage, self.sensor_type)(
self.monitored_device
)
if attr is None:
return None return None
# Data (disk space)
if self._unit == DATA_TERABYTES:
return round(attr / 1024.0 ** 4, 2)
# Temperature
if self._api.temp_unit == TEMP_CELSIUS: if self._api.temp_unit == TEMP_CELSIUS:
# Celsius
return attr 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 attr
return getattr(self._api.storage, self.sensor_type)(self.monitored_device)
return None
@property @property
def device_info(self) -> Dict[str, any]: def device_info(self) -> Dict[str, any]:

View File

@ -1692,7 +1692,7 @@ python-sochain-api==0.0.2
python-songpal==0.11.2 python-songpal==0.11.2
# homeassistant.components.synology_dsm # homeassistant.components.synology_dsm
python-synology==0.7.4 python-synology==0.8.0
# homeassistant.components.tado # homeassistant.components.tado
python-tado==0.8.1 python-tado==0.8.1

View File

@ -662,7 +662,7 @@ python-miio==0.5.0.1
python-nest==4.1.0 python-nest==4.1.0
# homeassistant.components.synology_dsm # homeassistant.components.synology_dsm
python-synology==0.7.4 python-synology==0.8.0
# homeassistant.components.tado # homeassistant.components.tado
python-tado==0.8.1 python-tado==0.8.1