Use DATA_SIZE device class in integrations (#83895)

This commit is contained in:
epenet 2022-12-13 10:17:56 +01:00 committed by GitHub
parent 677f0dc335
commit 69bc95a715
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 319 additions and 169 deletions

View file

@ -15,12 +15,7 @@ from homeassistant.components.sensor import (
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DATA_BYTES,
DATA_GIGABYTES,
DATA_KILOBYTES,
DATA_MEGABYTES,
)
from homeassistant.const import UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -35,7 +30,7 @@ from .coordinator import RadarrDataUpdateCoordinator, T
def get_space(data: list[Diskspace], name: str) -> str:
"""Get space."""
space = [
mount.freeSpace / 1024 ** BYTE_SIZES.index(DATA_GIGABYTES)
mount.freeSpace / 1024 ** BYTE_SIZES.index(UnitOfInformation.GIGABYTES)
for mount in data
if name in mount.path
]
@ -76,7 +71,8 @@ SENSOR_TYPES: dict[str, RadarrSensorEntityDescription[Any]] = {
"disk_space": RadarrSensorEntityDescription(
key="disk_space",
name="Disk space",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:harddisk",
value_fn=get_space,
description_fn=get_modified_description,
@ -100,10 +96,10 @@ SENSOR_TYPES: dict[str, RadarrSensorEntityDescription[Any]] = {
}
BYTE_SIZES = [
DATA_BYTES,
DATA_KILOBYTES,
DATA_MEGABYTES,
DATA_GIGABYTES,
UnitOfInformation.BYTES,
UnitOfInformation.KILOBYTES,
UnitOfInformation.MEGABYTES,
UnitOfInformation.GIGABYTES,
]
PARALLEL_UPDATES = 1