Use HA SensorDeviceClass in ruuvitag-ble (#82321)

* Use HA SensorDeviceClass in ruuvitag-ble

Refs https://github.com/home-assistant/core/pull/81327#discussion_r1024565439

* Use HA SensorDeviceClass even more
This commit is contained in:
Aarni Koskela 2022-11-20 17:58:37 +02:00 committed by GitHub
parent adff01876a
commit 6ec8c63b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ from typing import Optional, Union
from sensor_state_data import (
DeviceKey,
SensorDescription,
SensorDeviceClass,
SensorDeviceClass as SSDSensorDeviceClass,
SensorUpdate,
Units,
)
@ -20,6 +20,7 @@ from homeassistant.components.bluetooth.passive_update_processor import (
PassiveBluetoothProcessorEntity,
)
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
@ -31,46 +32,45 @@ from homeassistant.helpers.sensor import sensor_device_info_to_hass_device_info
from .const import DOMAIN
SENSOR_DESCRIPTIONS = {
(SensorDeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
key=f"{SensorDeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
(SSDSensorDeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
key=f"{SSDSensorDeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=const.TEMP_CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
(SensorDeviceClass.HUMIDITY, Units.PERCENTAGE): SensorEntityDescription(
key=f"{SensorDeviceClass.HUMIDITY}_{Units.PERCENTAGE}",
(SSDSensorDeviceClass.HUMIDITY, Units.PERCENTAGE): SensorEntityDescription(
key=f"{SSDSensorDeviceClass.HUMIDITY}_{Units.PERCENTAGE}",
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=const.PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
(SensorDeviceClass.PRESSURE, Units.PRESSURE_HPA): SensorEntityDescription(
key=f"{SensorDeviceClass.PRESSURE}_{Units.PRESSURE_HPA}",
(SSDSensorDeviceClass.PRESSURE, Units.PRESSURE_HPA): SensorEntityDescription(
key=f"{SSDSensorDeviceClass.PRESSURE}_{Units.PRESSURE_HPA}",
device_class=SensorDeviceClass.PRESSURE,
native_unit_of_measurement=const.PRESSURE_HPA,
state_class=SensorStateClass.MEASUREMENT,
),
(
SensorDeviceClass.VOLTAGE,
SSDSensorDeviceClass.VOLTAGE,
Units.ELECTRIC_POTENTIAL_MILLIVOLT,
): SensorEntityDescription(
key=f"{SensorDeviceClass.VOLTAGE}_{Units.ELECTRIC_POTENTIAL_MILLIVOLT}",
key=f"{SSDSensorDeviceClass.VOLTAGE}_{Units.ELECTRIC_POTENTIAL_MILLIVOLT}",
device_class=SensorDeviceClass.VOLTAGE,
native_unit_of_measurement=const.ELECTRIC_POTENTIAL_MILLIVOLT,
state_class=SensorStateClass.MEASUREMENT,
),
(
SensorDeviceClass.SIGNAL_STRENGTH,
SSDSensorDeviceClass.SIGNAL_STRENGTH,
Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
): SensorEntityDescription(
key=f"{SensorDeviceClass.SIGNAL_STRENGTH}_{Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT}",
key=f"{SSDSensorDeviceClass.SIGNAL_STRENGTH}_{Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT}",
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=const.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
(SensorDeviceClass.COUNT, None): SensorEntityDescription(
(SSDSensorDeviceClass.COUNT, None): SensorEntityDescription(
key="movement_counter",
device_class=SensorDeviceClass.COUNT,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
@ -86,7 +86,7 @@ def _device_key_to_bluetooth_entity_key(
def _to_sensor_key(
description: SensorDescription,
) -> tuple[SensorDeviceClass, Units | None]:
) -> tuple[SSDSensorDeviceClass, Units | None]:
assert description.device_class is not None
return (description.device_class, description.native_unit_of_measurement)