Use device classes in mysensors (#83653)

This commit is contained in:
epenet 2022-12-09 16:20:06 +01:00 committed by GitHub
parent b44e8673a8
commit 55b996f5db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 21 deletions

View File

@ -15,22 +15,20 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONDUCTIVITY, CONDUCTIVITY,
DEGREE, DEGREE,
ELECTRIC_POTENTIAL_MILLIVOLT,
ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR,
FREQUENCY_HERTZ,
LENGTH_METERS,
LIGHT_LUX, LIGHT_LUX,
MASS_KILOGRAMS,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
VOLUME_CUBIC_METERS,
Platform, Platform,
UnitOfApparentPower, UnitOfApparentPower,
UnitOfElectricCurrent, UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfFrequency,
UnitOfLength,
UnitOfMass,
UnitOfPower,
UnitOfSoundPressure, UnitOfSoundPressure,
UnitOfTemperature,
UnitOfVolume,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -94,12 +92,12 @@ SENSORS: dict[str, SensorEntityDescription] = {
), ),
"V_WEIGHT": SensorEntityDescription( "V_WEIGHT": SensorEntityDescription(
key="V_WEIGHT", key="V_WEIGHT",
native_unit_of_measurement=MASS_KILOGRAMS, native_unit_of_measurement=UnitOfMass.KILOGRAMS,
device_class=SensorDeviceClass.WEIGHT, device_class=SensorDeviceClass.WEIGHT,
), ),
"V_DISTANCE": SensorEntityDescription( "V_DISTANCE": SensorEntityDescription(
key="V_DISTANCE", key="V_DISTANCE",
native_unit_of_measurement=LENGTH_METERS, native_unit_of_measurement=UnitOfLength.METERS,
device_class=SensorDeviceClass.DISTANCE, device_class=SensorDeviceClass.DISTANCE,
), ),
"V_IMPEDANCE": SensorEntityDescription( "V_IMPEDANCE": SensorEntityDescription(
@ -108,13 +106,13 @@ SENSORS: dict[str, SensorEntityDescription] = {
), ),
"V_WATT": SensorEntityDescription( "V_WATT": SensorEntityDescription(
key="V_WATT", key="V_WATT",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
"V_KWH": SensorEntityDescription( "V_KWH": SensorEntityDescription(
key="V_KWH", key="V_KWH",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
@ -125,12 +123,14 @@ SENSORS: dict[str, SensorEntityDescription] = {
), ),
"V_FLOW": SensorEntityDescription( "V_FLOW": SensorEntityDescription(
key="V_FLOW", key="V_FLOW",
native_unit_of_measurement=LENGTH_METERS, native_unit_of_measurement=UnitOfLength.METERS,
icon="mdi:gauge", icon="mdi:gauge",
device_class=SensorDeviceClass.DISTANCE,
), ),
"V_VOLUME": SensorEntityDescription( "V_VOLUME": SensorEntityDescription(
key="V_VOLUME", key="V_VOLUME",
native_unit_of_measurement=VOLUME_CUBIC_METERS, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
device_class=SensorDeviceClass.VOLUME,
), ),
"V_LEVEL_S_SOUND": SensorEntityDescription( "V_LEVEL_S_SOUND": SensorEntityDescription(
key="V_LEVEL_S_SOUND", key="V_LEVEL_S_SOUND",
@ -139,7 +139,7 @@ SENSORS: dict[str, SensorEntityDescription] = {
), ),
"V_LEVEL_S_VIBRATION": SensorEntityDescription( "V_LEVEL_S_VIBRATION": SensorEntityDescription(
key="V_LEVEL_S_VIBRATION", key="V_LEVEL_S_VIBRATION",
native_unit_of_measurement=FREQUENCY_HERTZ, native_unit_of_measurement=UnitOfFrequency.HERTZ,
), ),
"V_LEVEL_S_LIGHT_LEVEL": SensorEntityDescription( "V_LEVEL_S_LIGHT_LEVEL": SensorEntityDescription(
key="V_LEVEL_S_LIGHT_LEVEL", key="V_LEVEL_S_LIGHT_LEVEL",
@ -154,7 +154,7 @@ SENSORS: dict[str, SensorEntityDescription] = {
), ),
"V_VOLTAGE": SensorEntityDescription( "V_VOLTAGE": SensorEntityDescription(
key="V_VOLTAGE", key="V_VOLTAGE",
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, native_unit_of_measurement=UnitOfElectricPotential.VOLT,
device_class=SensorDeviceClass.VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -170,7 +170,8 @@ SENSORS: dict[str, SensorEntityDescription] = {
), ),
"V_ORP": SensorEntityDescription( "V_ORP": SensorEntityDescription(
key="V_ORP", key="V_ORP",
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT, native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
device_class=SensorDeviceClass.VOLTAGE,
), ),
"V_EC": SensorEntityDescription( "V_EC": SensorEntityDescription(
key="V_EC", key="V_EC",
@ -245,8 +246,8 @@ class MySensorsSensor(mysensors.device.MySensorsEntity, SensorEntity):
if set_req(self.value_type) == set_req.V_TEMP: if set_req(self.value_type) == set_req.V_TEMP:
if self.hass.config.units is METRIC_SYSTEM: if self.hass.config.units is METRIC_SYSTEM:
return TEMP_CELSIUS return UnitOfTemperature.CELSIUS
return TEMP_FAHRENHEIT return UnitOfTemperature.FAHRENHEIT
if hasattr(self, "entity_description"): if hasattr(self, "entity_description"):
return self.entity_description.native_unit_of_measurement return self.entity_description.native_unit_of_measurement