Use DATA_SIZE device class in integrations (#83895)

pull/83915/head
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

@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_GIGABYTES, TEMP_CELSIUS, UnitOfDataRate
from homeassistant.const import TEMP_CELSIUS, UnitOfDataRate, UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -74,7 +74,8 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
name="Download",
icon="mdi:download",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
factor=1000000000,
),
@ -83,7 +84,8 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
name="Upload",
icon="mdi:upload",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
factor=1000000000,
),

View File

@ -7,12 +7,13 @@ import re
from typing import Any, cast
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_KILOBYTES, DATA_MEGABYTES, TIME_DAYS
from homeassistant.const import TIME_DAYS, UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
@ -36,21 +37,24 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
key="usedMb",
name="Data used",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:network",
),
SensorValueEntityDescription(
key="downloadedMb",
name="Downloaded",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download-network",
),
SensorValueEntityDescription(
key="uploadedMb",
name="Uploaded",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload-network",
),
# Mobile Phone Services sensors
@ -86,7 +90,8 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
key="internet",
name="Data used",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_KILOBYTES,
native_unit_of_measurement=UnitOfInformation.KILOBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:network",
value=lambda x: x.get("kbytes"),
),

View File

@ -9,10 +9,11 @@ import voluptuous as vol
from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import CONF_SENSORS, DATA_GIGABYTES, PERCENTAGE
from homeassistant.const import CONF_SENSORS, PERCENTAGE, UnitOfInformation
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -65,14 +66,16 @@ SENSOR_TYPES: tuple[DovadoSensorEntityDescription, ...] = (
identifier=SENSOR_UPLOAD,
key="traffic modem tx",
name="Sent",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:cloud-upload",
),
DovadoSensorEntityDescription(
identifier=SENSOR_DOWNLOAD,
key="traffic modem rx",
name="Received",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:cloud-download",
),
)

View File

@ -14,6 +14,7 @@ import voluptuous as vol
from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
@ -22,9 +23,9 @@ from homeassistant.const import (
CONF_NAME,
CONF_PASSWORD,
CONF_USERNAME,
DATA_GIGABITS,
PERCENTAGE,
TIME_DAYS,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
@ -61,7 +62,8 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="limit",
name="Data limit",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
@ -73,55 +75,64 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="before_offpeak_download",
name="Download before offpeak",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="before_offpeak_upload",
name="Upload before offpeak",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
),
SensorEntityDescription(
key="before_offpeak_total",
name="Total before offpeak",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="offpeak_download",
name="Offpeak download",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="offpeak_upload",
name="Offpeak Upload",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
),
SensorEntityDescription(
key="offpeak_total",
name="Offpeak Total",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="download",
name="Download",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="upload",
name="Upload",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
),
SensorEntityDescription(
key="total",
name="Total",
native_unit_of_measurement=DATA_GIGABITS,
native_unit_of_measurement=UnitOfInformation.GIGABITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
)

View File

@ -15,6 +15,7 @@ import voluptuous as vol
from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
@ -23,8 +24,8 @@ from homeassistant.const import (
CONF_NAME,
CONF_PASSWORD,
CONF_USERNAME,
DATA_KILOBITS,
TIME_MINUTES,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -59,19 +60,22 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="data_used",
name="Data used",
native_unit_of_measurement=DATA_KILOBITS,
native_unit_of_measurement=UnitOfInformation.KILOBITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="data_limit",
name="Data limit",
native_unit_of_measurement=DATA_KILOBITS,
native_unit_of_measurement=UnitOfInformation.KILOBITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="data_remaining",
name="Data remaining",
native_unit_of_measurement=DATA_KILOBITS,
native_unit_of_measurement=UnitOfInformation.KILOBITS,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(

View File

@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_FILE_PATH, DATA_BYTES, DATA_MEGABYTES
from homeassistant.const import CONF_FILE_PATH, UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
@ -36,7 +36,8 @@ SENSOR_TYPES = (
key="file",
icon=ICON,
name="Size",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
@ -44,7 +45,8 @@ SENSOR_TYPES = (
entity_registry_enabled_default=False,
icon=ICON,
name="Size bytes",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
),

View File

@ -17,7 +17,11 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_GIGABYTES, SIGNAL_STRENGTH_DECIBELS, UnitOfDataRate
from homeassistant.const import (
SIGNAL_STRENGTH_DECIBELS,
UnitOfDataRate,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -217,7 +221,8 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
key="gb_sent",
name="GB sent",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
value_fn=_retrieve_gb_sent_state,
),
@ -225,7 +230,8 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
key="gb_received",
name="GB received",
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
value_fn=_retrieve_gb_received_state,
),

View File

@ -12,7 +12,7 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_MEGABYTES, PERCENTAGE
from homeassistant.const import PERCENTAGE, UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -62,7 +62,8 @@ SENSORS: tuple[FullySensorEntityDescription, ...] = (
key="internalStorageFreeSpace",
name="Internal storage free space",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
state_fn=round_storage,
),
@ -70,7 +71,8 @@ SENSORS: tuple[FullySensorEntityDescription, ...] = (
key="internalStorageTotalSpace",
name="Internal storage total space",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
state_fn=round_storage,
),
@ -78,7 +80,8 @@ SENSORS: tuple[FullySensorEntityDescription, ...] = (
key="ramFreeMemory",
name="Free memory",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
state_fn=round_storage,
),
@ -86,7 +89,8 @@ SENSORS: tuple[FullySensorEntityDescription, ...] = (
key="ramTotalMemory",
name="Total memory",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
state_fn=round_storage,
),

View File

@ -13,13 +13,12 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_NAME,
DATA_GIBIBYTES,
DATA_MEBIBYTES,
PERCENTAGE,
REVOLUTIONS_PER_MINUTE,
STATE_UNAVAILABLE,
TEMP_CELSIUS,
Platform,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry
@ -59,7 +58,8 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
key="disk_use",
type="fs",
name_suffix="used",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:harddisk",
state_class=SensorStateClass.MEASUREMENT,
),
@ -67,7 +67,8 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
key="disk_free",
type="fs",
name_suffix="free",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:harddisk",
state_class=SensorStateClass.MEASUREMENT,
),
@ -83,7 +84,8 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
key="memory_use",
type="mem",
name_suffix="RAM used",
native_unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
@ -91,7 +93,8 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
key="memory_free",
type="mem",
name_suffix="RAM free",
native_unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
@ -107,7 +110,8 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
key="swap_use",
type="memswap",
name_suffix="Swap used",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
@ -115,7 +119,8 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
key="swap_free",
type="memswap",
name_suffix="Swap free",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
@ -213,7 +218,8 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
key="docker_memory_use",
type="docker",
name_suffix="Containers RAM used",
native_unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:docker",
state_class=SensorStateClass.MEASUREMENT,
),

View File

@ -16,10 +16,10 @@ from homeassistant.components.sensor import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DATA_MEGABYTES,
PERCENTAGE,
TIME_MILLISECONDS,
UnitOfDataRate,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory
@ -89,35 +89,40 @@ SENSOR_TRAFFIC_TYPES = [
key="NewTodayUpload",
name="Upload today",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
),
NetgearSensorEntityDescription(
key="NewTodayDownload",
name="Download today",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
NetgearSensorEntityDescription(
key="NewYesterdayUpload",
name="Upload yesterday",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
),
NetgearSensorEntityDescription(
key="NewYesterdayDownload",
name="Download yesterday",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
NetgearSensorEntityDescription(
key="NewWeekUpload",
name="Upload week",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
index=0,
value=lambda data: data[0],
@ -126,7 +131,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewWeekUpload",
name="Upload week average",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
index=1,
value=lambda data: data[1],
@ -135,7 +141,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewWeekDownload",
name="Download week",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
index=0,
value=lambda data: data[0],
@ -144,7 +151,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewWeekDownload",
name="Download week average",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
index=1,
value=lambda data: data[1],
@ -153,7 +161,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewMonthUpload",
name="Upload month",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
index=0,
value=lambda data: data[0],
@ -162,7 +171,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewMonthUpload",
name="Upload month average",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
index=1,
value=lambda data: data[1],
@ -171,7 +181,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewMonthDownload",
name="Download month",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
index=0,
value=lambda data: data[0],
@ -180,7 +191,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewMonthDownload",
name="Download month average",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
index=1,
value=lambda data: data[1],
@ -189,7 +201,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewLastMonthUpload",
name="Upload last month",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
index=0,
value=lambda data: data[0],
@ -198,7 +211,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewLastMonthUpload",
name="Upload last month average",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
index=1,
value=lambda data: data[1],
@ -207,7 +221,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewLastMonthDownload",
name="Download last month",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
index=0,
value=lambda data: data[0],
@ -216,7 +231,8 @@ SENSOR_TRAFFIC_TYPES = [
key="NewLastMonthDownload",
name="Download last month average",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
index=1,
value=lambda data: data[1],

View File

@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME, DATA_MEGABYTES, UnitOfDataRate
from homeassistant.const import CONF_NAME, UnitOfDataRate, UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.dt import utcnow
@ -25,7 +25,8 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="ArticleCacheMB",
name="Article Cache",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
),
SensorEntityDescription(
key="AverageDownloadRate",
@ -46,12 +47,14 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="DownloadedSizeMB",
name="Size",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
),
SensorEntityDescription(
key="FreeDiskSpaceMB",
name="Disk Free",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
),
SensorEntityDescription(
key="PostJobCount",
@ -65,7 +68,8 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="RemainingSizeMB",
name="Queue Size",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
),
SensorEntityDescription(
key="UpTimeSec",

View File

@ -23,10 +23,10 @@ from homeassistant.const import (
CONF_TIMEOUT,
CONF_USERNAME,
CONF_VERIFY_SSL,
DATA_GIBIBYTES,
PERCENTAGE,
TEMP_CELSIUS,
UnitOfDataRate,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
@ -96,13 +96,15 @@ _MEMORY_MON_COND: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="memory_free",
name="Memory Available",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
),
SensorEntityDescription(
key="memory_used",
name="Memory Used",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
),
SensorEntityDescription(
@ -150,13 +152,15 @@ _VOLUME_MON_COND: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="volume_size_used",
name="Used Space",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:chart-pie",
),
SensorEntityDescription(
key="volume_size_free",
name="Free Space",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:chart-pie",
),
SensorEntityDescription(
@ -374,7 +378,7 @@ class QNAPMemorySensor(QNAPSensor):
if self._api.data:
data = self._api.data["system_stats"]["memory"]
size = round_nicely(float(data["total"]) / 1024)
return {ATTR_MEMORY_SIZE: f"{size} {DATA_GIBIBYTES}"}
return {ATTR_MEMORY_SIZE: f"{size} {UnitOfInformation.GIBIBYTES}"}
class QNAPNetworkSensor(QNAPSensor):
@ -501,4 +505,6 @@ class QNAPVolumeSensor(QNAPSensor):
data = self._api.data["volumes"][self.monitor_device]
total_gb = int(data["total_size"]) / 1024 / 1024 / 1024
return {ATTR_VOLUME_SIZE: f"{round_nicely(total_gb)} {DATA_GIBIBYTES}"}
return {
ATTR_VOLUME_SIZE: f"{round_nicely(total_gb)} {UnitOfInformation.GIBIBYTES}"
}

View File

@ -31,7 +31,12 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_BYTES, TEMP_CELSIUS, TIME_SECONDS, UnitOfDataRate
from homeassistant.const import (
TEMP_CELSIUS,
TIME_SECONDS,
UnitOfDataRate,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -78,10 +83,11 @@ SENSOR_TYPES: Final[tuple[QswSensorEntityDescription, ...]] = (
),
QswSensorEntityDescription(
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download-network",
key=QSD_PORTS_STATISTICS,
name="RX",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
state_class=SensorStateClass.TOTAL_INCREASING,
subkey=QSD_RX_OCTETS,
),
@ -117,10 +123,11 @@ SENSOR_TYPES: Final[tuple[QswSensorEntityDescription, ...]] = (
),
QswSensorEntityDescription(
entity_registry_enabled_default=False,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload-network",
key=QSD_PORTS_STATISTICS,
name="TX",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
state_class=SensorStateClass.TOTAL_INCREASING,
subkey=QSD_TX_OCTETS,
),

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

View File

@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_GIGABYTES, DATA_MEGABYTES, UnitOfDataRate
from homeassistant.const import UnitOfDataRate, UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -50,25 +50,29 @@ SENSOR_TYPES: tuple[SabnzbdSensorEntityDescription, ...] = (
SabnzbdSensorEntityDescription(
key="mb",
name="Queue",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
),
SabnzbdSensorEntityDescription(
key="mbleft",
name="Left",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
),
SabnzbdSensorEntityDescription(
key="diskspacetotal1",
name="Disk",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
),
SabnzbdSensorEntityDescription(
key="diskspace1",
name="Disk Free",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
),
SabnzbdSensorEntityDescription(
@ -79,28 +83,32 @@ SENSOR_TYPES: tuple[SabnzbdSensorEntityDescription, ...] = (
SabnzbdSensorEntityDescription(
key="day_size",
name="Daily Total",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SabnzbdSensorEntityDescription(
key="week_size",
name="Weekly Total",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SabnzbdSensorEntityDescription(
key="month_size",
name="Monthly Total",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SabnzbdSensorEntityDescription(
key="total_size",
name="Total",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.TOTAL_INCREASING,
),
)

View File

@ -14,9 +14,13 @@ from aiopyarr import (
SonarrWantedMissing,
)
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_GIGABYTES
from homeassistant.const import UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
@ -49,7 +53,9 @@ def get_disk_space_attr(disks: list[Diskspace]) -> dict[str, str]:
free = disk.freeSpace / 1024**3
total = disk.totalSpace / 1024**3
usage = free / total * 100
attrs[disk.path] = f"{free:.2f}/{total:.2f}{DATA_GIGABYTES} ({usage:.2f}%)"
attrs[
disk.path
] = f"{free:.2f}/{total:.2f}{UnitOfInformation.GIGABYTES} ({usage:.2f}%)"
return attrs
@ -93,7 +99,8 @@ SENSOR_TYPES: dict[str, SonarrSensorEntityDescription[Any]] = {
key="diskspace",
name="Disk space",
icon="mdi:harddisk",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
value_fn=lambda data: f"{sum(disk.freeSpace for disk in data) / 1024**3:.2f}",
attributes_fn=get_disk_space_attr,

View File

@ -12,6 +12,7 @@ import xmltodict
from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
@ -19,8 +20,8 @@ from homeassistant.const import (
CONF_API_KEY,
CONF_MONITORED_VARIABLES,
CONF_NAME,
DATA_GIGABYTES,
PERCENTAGE,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
@ -47,67 +48,78 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="usage_gb",
name="Usage",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="limit",
name="Data limit",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="used_download",
name="Used Download",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="used_upload",
name="Used Upload",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
),
SensorEntityDescription(
key="used_total",
name="Used Total",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="grace_download",
name="Grace Download",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="grace_upload",
name="Grace Upload",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:upload",
),
SensorEntityDescription(
key="grace_total",
name="Grace Total",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="total_download",
name="Total Download",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="total_upload",
name="Total Upload",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
SensorEntityDescription(
key="used_remaining",
name="Remaining",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:download",
),
)

View File

@ -18,11 +18,10 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_DISKS,
DATA_MEGABYTES,
DATA_TERABYTES,
PERCENTAGE,
TEMP_CELSIUS,
UnitOfDataRate,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
@ -116,7 +115,8 @@ UTILISATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
api_key=SynoCoreUtilization.API_KEY,
key="memory_size",
name="Memory Size",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
@ -125,7 +125,8 @@ UTILISATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
api_key=SynoCoreUtilization.API_KEY,
key="memory_cached",
name="Memory Cached",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
@ -134,7 +135,8 @@ UTILISATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
api_key=SynoCoreUtilization.API_KEY,
key="memory_available_swap",
name="Memory Available (Swap)",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
@ -142,7 +144,8 @@ UTILISATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
api_key=SynoCoreUtilization.API_KEY,
key="memory_available_real",
name="Memory Available (Real)",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
@ -150,7 +153,8 @@ UTILISATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
api_key=SynoCoreUtilization.API_KEY,
key="memory_total_swap",
name="Memory Total (Swap)",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
@ -158,7 +162,8 @@ UTILISATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
api_key=SynoCoreUtilization.API_KEY,
key="memory_total_real",
name="Memory Total (Real)",
native_unit_of_measurement=DATA_MEGABYTES,
native_unit_of_measurement=UnitOfInformation.MEGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
@ -192,7 +197,8 @@ STORAGE_VOL_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
api_key=SynoStorage.API_KEY,
key="volume_size_total",
name="Total Size",
native_unit_of_measurement=DATA_TERABYTES,
native_unit_of_measurement=UnitOfInformation.TERABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:chart-pie",
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
@ -201,7 +207,8 @@ STORAGE_VOL_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
api_key=SynoStorage.API_KEY,
key="volume_size_used",
name="Used Space",
native_unit_of_measurement=DATA_TERABYTES,
native_unit_of_measurement=UnitOfInformation.TERABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:chart-pie",
state_class=SensorStateClass.MEASUREMENT,
),
@ -349,7 +356,7 @@ class SynoDSMUtilSensor(SynoDSMSensor):
return None
# Data (RAM)
if self.native_unit_of_measurement == DATA_MEGABYTES:
if self.native_unit_of_measurement == UnitOfInformation.MEGABYTES:
return round(attr / 1024.0**2, 1)
# Network
@ -391,7 +398,7 @@ class SynoDSMStorageSensor(SynologyDSMDeviceEntity, SynoDSMSensor):
return None
# Data (disk space)
if self.native_unit_of_measurement == DATA_TERABYTES:
if self.native_unit_of_measurement == UnitOfInformation.TERABYTES:
return round(attr / 1024.0**4, 2)
return attr

View File

@ -15,7 +15,6 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_PORT,
DATA_GIGABYTES,
ELECTRIC_POTENTIAL_VOLT,
FREQUENCY_GIGAHERTZ,
FREQUENCY_HERTZ,
@ -23,6 +22,7 @@ from homeassistant.const import (
PERCENTAGE,
REVOLUTIONS_PER_MINUTE,
TEMP_CELSIUS,
UnitOfInformation,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
@ -171,7 +171,8 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
key="memory_free",
name="Memory Free",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
value=memory_free,
),
@ -188,7 +189,8 @@ BASE_SENSOR_TYPES: tuple[SystemBridgeSensorEntityDescription, ...] = (
name="Memory Used",
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
value=memory_used,
),
@ -399,7 +401,8 @@ async def async_setup_entry(
key=f"gpu_{index}_memory_free",
name=f"{gpu['name']} Memory Free",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
value=lambda data, k=gpu["key"]: gpu_memory_free(data, k),
),
@ -426,7 +429,8 @@ async def async_setup_entry(
name=f"{gpu['name']} Memory Used",
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
value=lambda data, k=gpu["key"]: gpu_memory_used(data, k),
),

View File

@ -25,14 +25,13 @@ from homeassistant.const import (
CONF_RESOURCES,
CONF_SCAN_INTERVAL,
CONF_TYPE,
DATA_GIBIBYTES,
DATA_MEBIBYTES,
EVENT_HOMEASSISTANT_STOP,
PERCENTAGE,
STATE_OFF,
STATE_ON,
TEMP_CELSIUS,
UnitOfDataRate,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
@ -76,14 +75,16 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
"disk_free": SysMonitorSensorEntityDescription(
key="disk_free",
name="Disk free",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:harddisk",
state_class=SensorStateClass.MEASUREMENT,
),
"disk_use": SysMonitorSensorEntityDescription(
key="disk_use",
name="Disk use",
native_unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=UnitOfInformation.GIBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:harddisk",
state_class=SensorStateClass.MEASUREMENT,
),
@ -132,14 +133,16 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
"memory_free": SysMonitorSensorEntityDescription(
key="memory_free",
name="Memory free",
native_unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
"memory_use": SysMonitorSensorEntityDescription(
key="memory_use",
name="Memory use",
native_unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:memory",
state_class=SensorStateClass.MEASUREMENT,
),
@ -153,7 +156,8 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
"network_in": SysMonitorSensorEntityDescription(
key="network_in",
name="Network in",
native_unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:server-network",
state_class=SensorStateClass.TOTAL_INCREASING,
mandatory_arg=True,
@ -161,7 +165,8 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
"network_out": SysMonitorSensorEntityDescription(
key="network_out",
name="Network out",
native_unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:server-network",
state_class=SensorStateClass.TOTAL_INCREASING,
mandatory_arg=True,
@ -220,14 +225,16 @@ SENSOR_TYPES: dict[str, SysMonitorSensorEntityDescription] = {
"swap_free": SysMonitorSensorEntityDescription(
key="swap_free",
name="Swap free",
native_unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:harddisk",
state_class=SensorStateClass.MEASUREMENT,
),
"swap_use": SysMonitorSensorEntityDescription(
key="swap_use",
name="Swap use",
native_unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=UnitOfInformation.MEBIBYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:harddisk",
state_class=SensorStateClass.MEASUREMENT,
),

View File

@ -13,12 +13,13 @@ from pytautulli import (
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import DATA_KILOBITS, PERCENTAGE
from homeassistant.const import PERCENTAGE, UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory, EntityDescription
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -101,7 +102,8 @@ SENSOR_TYPES: tuple[TautulliSensorEntityDescription, ...] = (
key="total_bandwidth",
name="Total bandwidth",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_KILOBITS,
native_unit_of_measurement=UnitOfInformation.KILOBITS,
device_class=SensorDeviceClass.DATA_SIZE,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda home_stats, activity, _: cast(int, activity.total_bandwidth),
),
@ -109,7 +111,8 @@ SENSOR_TYPES: tuple[TautulliSensorEntityDescription, ...] = (
key="lan_bandwidth",
name="LAN bandwidth",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_KILOBITS,
native_unit_of_measurement=UnitOfInformation.KILOBITS,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda home_stats, activity, _: cast(int, activity.lan_bandwidth),
@ -118,7 +121,8 @@ SENSOR_TYPES: tuple[TautulliSensorEntityDescription, ...] = (
key="wan_bandwidth",
name="WAN bandwidth",
entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=DATA_KILOBITS,
native_unit_of_measurement=UnitOfInformation.KILOBITS,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda home_stats, activity, _: cast(int, activity.wan_bandwidth),

View File

@ -7,7 +7,7 @@ from datetime import datetime, timedelta
from homeassistant.components.sensor import DOMAIN, SensorDeviceClass, SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_MEGABYTES
from homeassistant.const import UnitOfInformation
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
@ -90,8 +90,9 @@ class UniFiBandwidthSensor(UniFiClient, SensorEntity):
DOMAIN = DOMAIN
_attr_device_class = SensorDeviceClass.DATA_SIZE
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_native_unit_of_measurement = DATA_MEGABYTES
_attr_native_unit_of_measurement = UnitOfInformation.MEGABYTES
@property
def name(self) -> str:

View File

@ -26,7 +26,6 @@ from homeassistant.components.sensor import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DATA_BYTES,
ELECTRIC_POTENTIAL_VOLT,
LIGHT_LUX,
PERCENTAGE,
@ -34,6 +33,7 @@ from homeassistant.const import (
TEMP_CELSIUS,
TIME_SECONDS,
UnitOfDataRate,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -172,7 +172,8 @@ CAMERA_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
ProtectSensorEntityDescription(
key="storage_used",
name="Storage Used",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_category=EntityCategory.DIAGNOSTIC,
state_class=SensorStateClass.MEASUREMENT,
ufp_value="stats.storage.used",
@ -269,7 +270,8 @@ CAMERA_DISABLED_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
ProtectSensorEntityDescription(
key="stats_rx",
name="Received Data",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
state_class=SensorStateClass.TOTAL_INCREASING,
@ -278,7 +280,8 @@ CAMERA_DISABLED_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
ProtectSensorEntityDescription(
key="stats_tx",
name="Transferred Data",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
entity_category=EntityCategory.DIAGNOSTIC,
state_class=SensorStateClass.TOTAL_INCREASING,

View File

@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_BYTES, TIME_SECONDS, UnitOfDataRate
from homeassistant.const import TIME_SECONDS, UnitOfDataRate, UnitOfInformation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -44,18 +44,20 @@ class UpnpSensorEntityDescription(UpnpEntityDescription, SensorEntityDescription
SENSOR_DESCRIPTIONS: tuple[UpnpSensorEntityDescription, ...] = (
UpnpSensorEntityDescription(
key=BYTES_RECEIVED,
name=f"{DATA_BYTES} received",
name=f"{UnitOfInformation.BYTES} received",
icon="mdi:server-network",
native_unit_of_measurement=DATA_BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
native_unit_of_measurement=UnitOfInformation.BYTES,
format="d",
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,
),
UpnpSensorEntityDescription(
key=BYTES_SENT,
name=f"{DATA_BYTES} sent",
name=f"{UnitOfInformation.BYTES} sent",
icon="mdi:server-network",
native_unit_of_measurement=DATA_BYTES,
device_class=SensorDeviceClass.DATA_SIZE,
native_unit_of_measurement=UnitOfInformation.BYTES,
format="d",
entity_registry_enabled_default=False,
state_class=SensorStateClass.TOTAL_INCREASING,

View File

@ -7,10 +7,11 @@ import voluptuous as vol
from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME, DATA_GIGABYTES
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME, UnitOfInformation
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -30,7 +31,8 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key=ATTR_CURRENT_BANDWIDTH_USED,
name="Current Bandwidth Used",
native_unit_of_measurement=DATA_GIGABYTES,
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
icon="mdi:chart-histogram",
),
SensorEntityDescription(

View File

@ -15,10 +15,10 @@ from homeassistant.components.sensor import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DATA_BYTES,
PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
UnitOfElectricCurrent,
UnitOfInformation,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
@ -85,8 +85,9 @@ SENSORS: tuple[WLEDSensorEntityDescription, ...] = (
key="free_heap",
name="Free memory",
icon="mdi:memory",
native_unit_of_measurement=DATA_BYTES,
native_unit_of_measurement=UnitOfInformation.BYTES,
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.DATA_SIZE,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
value_fn=lambda device: device.info.free_heap,

View File

@ -74,7 +74,7 @@ async def test_sensors_sensors(
state = hass.states.get("sensor.amazon_fire_internal_storage_free_space")
assert state
assert state.state == "11675.5"
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATA_SIZE
assert (
state.attributes.get(ATTR_FRIENDLY_NAME)
== "Amazon Fire Internal storage free space"
@ -89,7 +89,7 @@ async def test_sensors_sensors(
state = hass.states.get("sensor.amazon_fire_internal_storage_total_space")
assert state
assert state.state == "12938.5"
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATA_SIZE
assert (
state.attributes.get(ATTR_FRIENDLY_NAME)
== "Amazon Fire Internal storage total space"
@ -104,7 +104,7 @@ async def test_sensors_sensors(
state = hass.states.get("sensor.amazon_fire_free_memory")
assert state
assert state.state == "362.4"
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATA_SIZE
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Amazon Fire Free memory"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
@ -116,7 +116,7 @@ async def test_sensors_sensors(
state = hass.states.get("sensor.amazon_fire_total_memory")
assert state
assert state.state == "1440.1"
assert state.attributes.get(ATTR_DEVICE_CLASS) is None
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DATA_SIZE
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Amazon Fire Total memory"
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT

View File

@ -25,7 +25,12 @@ async def test_sensors(hass, nzbget_api) -> None:
uptime = now - timedelta(seconds=600)
sensors = {
"article_cache": ("ArticleCacheMB", "64", DATA_MEGABYTES, None),
"article_cache": (
"ArticleCacheMB",
"64",
DATA_MEGABYTES,
SensorDeviceClass.DATA_SIZE,
),
"average_speed": (
"AverageDownloadRate",
"1.19",
@ -39,11 +44,26 @@ async def test_sensors(hass, nzbget_api) -> None:
DATA_RATE_MEGABYTES_PER_SECOND,
SensorDeviceClass.DATA_RATE,
),
"size": ("DownloadedSizeMB", "256", DATA_MEGABYTES, None),
"disk_free": ("FreeDiskSpaceMB", "1024", DATA_MEGABYTES, None),
"size": (
"DownloadedSizeMB",
"256",
DATA_MEGABYTES,
SensorDeviceClass.DATA_SIZE,
),
"disk_free": (
"FreeDiskSpaceMB",
"1024",
DATA_MEGABYTES,
SensorDeviceClass.DATA_SIZE,
),
"post_processing_jobs": ("PostJobCount", "2", "Jobs", None),
"post_processing_paused": ("PostPaused", "False", None, None),
"queue_size": ("RemainingSizeMB", "512", DATA_MEGABYTES, None),
"queue_size": (
"RemainingSizeMB",
"512",
DATA_MEGABYTES,
SensorDeviceClass.DATA_SIZE,
),
"uptime": ("UpTimeSec", uptime.isoformat(), None, SensorDeviceClass.TIMESTAMP),
"speed_limit": (
"DownloadLimit",