Use DataRate unit and device class in integrations (#83610)

This commit is contained in:
epenet 2022-12-10 11:41:44 +01:00 committed by GitHub
parent 3970da0ad3
commit 535aba10ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 132 additions and 111 deletions

View file

@ -6,12 +6,13 @@ from dataclasses import dataclass
from typing import Any
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DATA_RATE_KILOBYTES_PER_SECOND, STATE_IDLE, Platform
from homeassistant.const import STATE_IDLE, Platform, UnitOfDataRate
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_platform
from homeassistant.helpers.typing import StateType
@ -53,14 +54,16 @@ SENSOR_TYPES: tuple[DelugeSensorEntityDescription, ...] = (
DelugeSensorEntityDescription(
key=DOWNLOAD_SPEED,
name="Down speed",
native_unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
native_unit_of_measurement=UnitOfDataRate.KILOBYTES_PER_SECOND,
state_class=SensorStateClass.MEASUREMENT,
value=lambda data: get_state(data, DOWNLOAD_SPEED),
),
DelugeSensorEntityDescription(
key=UPLOAD_SPEED,
name="Up speed",
native_unit_of_measurement=DATA_RATE_KILOBYTES_PER_SECOND,
device_class=SensorDeviceClass.DATA_RATE,
native_unit_of_measurement=UnitOfDataRate.KILOBYTES_PER_SECOND,
state_class=SensorStateClass.MEASUREMENT,
value=lambda data: get_state(data, UPLOAD_SPEED),
),