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 (
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"],

View file

@ -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": [

View file

@ -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]:

View file

@ -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

View file

@ -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