Use entity_class 'safety' in synology_dsm storage sensors (#39757)

* Use entity_class: 'safety' in storage sensors

and more meaningful icons then 'mdi:test-tube', not sure if these are even necessary, given the device_class that defines the icons too?

* Set device_class, not icon

Still, the temperature sensors have both set, should I take these out in this go too? While we're at it....

* added device_class temperature to temp sensors

and removed explicit icons
do we need to set a D_c also on the Status sensor? line 187

* revert device_class Safety

which is now set in const.py
following up on https://github.com/home-assistant/core/pull/39757#pullrequestreview-483705147

* Use DEVICE_CLASS_SAFETY from const

+ revert temp to avoid conflict

* const from binary

* reverted non binary status sensors

to use: "mdi:checkbox-marked-circle-outline" and set None to device_class

Co-authored-by: Quentame <polletquentin74@me.com>
This commit is contained in:
Marius 2020-09-10 09:21:51 +02:00 committed by GitHub
parent b57f97b954
commit a6a011ec19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 17 deletions

View File

@ -1,10 +1,7 @@
"""Support for Synology DSM binary sensors.""" """Support for Synology DSM binary sensors."""
from typing import Dict from typing import Dict
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import BinarySensorEntity
DEVICE_CLASS_SAFETY,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_DISKS from homeassistant.const import CONF_DISKS
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
@ -17,8 +14,6 @@ from .const import (
SYNO_API, SYNO_API,
) )
DEFAULT_DEVICE_CLASS = DEVICE_CLASS_SAFETY
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
@ -76,8 +71,3 @@ class SynoDSMStorageBinarySensor(SynologyDSMDeviceEntity, BinarySensorEntity):
if attr is None: if attr is None:
return None return None
return attr return attr
@property
def device_class(self):
"""Return the device class of this binary sensor."""
return DEFAULT_DEVICE_CLASS

View File

@ -4,6 +4,7 @@ from synology_dsm.api.core.security import SynoCoreSecurity
from synology_dsm.api.core.utilization import SynoCoreUtilization from synology_dsm.api.core.utilization import SynoCoreUtilization
from synology_dsm.api.storage.storage import SynoStorage from synology_dsm.api.storage.storage import SynoStorage
from homeassistant.components.binary_sensor import DEVICE_CLASS_SAFETY
from homeassistant.const import ( from homeassistant.const import (
DATA_MEGABYTES, DATA_MEGABYTES,
DATA_RATE_KILOBYTES_PER_SECOND, DATA_RATE_KILOBYTES_PER_SECOND,
@ -41,15 +42,15 @@ STORAGE_DISK_BINARY_SENSORS = {
f"{SynoStorage.API_KEY}:disk_exceed_bad_sector_thr": { f"{SynoStorage.API_KEY}:disk_exceed_bad_sector_thr": {
ENTITY_NAME: "Exceeded Max Bad Sectors", ENTITY_NAME: "Exceeded Max Bad Sectors",
ENTITY_UNIT: None, ENTITY_UNIT: None,
ENTITY_ICON: "mdi:test-tube", ENTITY_ICON: None,
ENTITY_CLASS: None, ENTITY_CLASS: DEVICE_CLASS_SAFETY,
ENTITY_ENABLE: True, ENTITY_ENABLE: True,
}, },
f"{SynoStorage.API_KEY}:disk_below_remain_life_thr": { f"{SynoStorage.API_KEY}:disk_below_remain_life_thr": {
ENTITY_NAME: "Below Min Remaining Life", ENTITY_NAME: "Below Min Remaining Life",
ENTITY_UNIT: None, ENTITY_UNIT: None,
ENTITY_ICON: "mdi:test-tube", ENTITY_ICON: None,
ENTITY_CLASS: None, ENTITY_CLASS: DEVICE_CLASS_SAFETY,
ENTITY_ENABLE: True, ENTITY_ENABLE: True,
}, },
} }
@ -58,8 +59,8 @@ SECURITY_BINARY_SENSORS = {
f"{SynoCoreSecurity.API_KEY}:status": { f"{SynoCoreSecurity.API_KEY}:status": {
ENTITY_NAME: "Security status", ENTITY_NAME: "Security status",
ENTITY_UNIT: None, ENTITY_UNIT: None,
ENTITY_ICON: "mdi:checkbox-marked-circle-outline", ENTITY_ICON: None,
ENTITY_CLASS: "safety", ENTITY_CLASS: DEVICE_CLASS_SAFETY,
ENTITY_ENABLE: True, ENTITY_ENABLE: True,
}, },
} }