mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Add device_class for LCN sensors (#127921)
* Add device_class for lcn sensor * Rename device_class mapping dictionary
This commit is contained in:
parent
9d9b5af97f
commit
017ba509a6
@ -7,7 +7,11 @@ from typing import cast
|
|||||||
|
|
||||||
import pypck
|
import pypck
|
||||||
|
|
||||||
from homeassistant.components.sensor import DOMAIN as DOMAIN_SENSOR, SensorEntity
|
from homeassistant.components.sensor import (
|
||||||
|
DOMAIN as DOMAIN_SENSOR,
|
||||||
|
SensorDeviceClass,
|
||||||
|
SensorEntity,
|
||||||
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_DOMAIN,
|
CONF_DOMAIN,
|
||||||
@ -32,6 +36,17 @@ from .const import (
|
|||||||
from .entity import LcnEntity
|
from .entity import LcnEntity
|
||||||
from .helpers import InputType
|
from .helpers import InputType
|
||||||
|
|
||||||
|
DEVICE_CLASS_MAPPING = {
|
||||||
|
pypck.lcn_defs.VarUnit.CELSIUS: SensorDeviceClass.TEMPERATURE,
|
||||||
|
pypck.lcn_defs.VarUnit.KELVIN: SensorDeviceClass.TEMPERATURE,
|
||||||
|
pypck.lcn_defs.VarUnit.FAHRENHEIT: SensorDeviceClass.TEMPERATURE,
|
||||||
|
pypck.lcn_defs.VarUnit.LUX_T: SensorDeviceClass.ILLUMINANCE,
|
||||||
|
pypck.lcn_defs.VarUnit.LUX_I: SensorDeviceClass.ILLUMINANCE,
|
||||||
|
pypck.lcn_defs.VarUnit.METERPERSECOND: SensorDeviceClass.SPEED,
|
||||||
|
pypck.lcn_defs.VarUnit.VOLT: SensorDeviceClass.VOLTAGE,
|
||||||
|
pypck.lcn_defs.VarUnit.AMPERE: SensorDeviceClass.CURRENT,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def add_lcn_entities(
|
def add_lcn_entities(
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
@ -87,7 +102,9 @@ class LcnVariableSensor(LcnEntity, SensorEntity):
|
|||||||
self.unit = pypck.lcn_defs.VarUnit.parse(
|
self.unit = pypck.lcn_defs.VarUnit.parse(
|
||||||
config[CONF_DOMAIN_DATA][CONF_UNIT_OF_MEASUREMENT]
|
config[CONF_DOMAIN_DATA][CONF_UNIT_OF_MEASUREMENT]
|
||||||
)
|
)
|
||||||
|
|
||||||
self._attr_native_unit_of_measurement = cast(str, self.unit.value)
|
self._attr_native_unit_of_measurement = cast(str, self.unit.value)
|
||||||
|
self._attr_device_class = DEVICE_CLASS_MAPPING.get(self.unit, None)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Run when entity about to be added to hass."""
|
"""Run when entity about to be added to hass."""
|
||||||
|
@ -113,7 +113,7 @@
|
|||||||
'name': None,
|
'name': None,
|
||||||
'options': dict({
|
'options': dict({
|
||||||
}),
|
}),
|
||||||
'original_device_class': None,
|
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'Sensor_Setpoint1',
|
'original_name': 'Sensor_Setpoint1',
|
||||||
'platform': 'lcn',
|
'platform': 'lcn',
|
||||||
@ -121,14 +121,15 @@
|
|||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': None,
|
'translation_key': None,
|
||||||
'unique_id': 'lcn/config_entry_pchk.json-m000007-r1varsetpoint',
|
'unique_id': 'lcn/config_entry_pchk.json-m000007-r1varsetpoint',
|
||||||
'unit_of_measurement': '°C',
|
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_setup_lcn_sensor[sensor.sensor_setpoint1-state]
|
# name: test_setup_lcn_sensor[sensor.sensor_setpoint1-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'temperature',
|
||||||
'friendly_name': 'Sensor_Setpoint1',
|
'friendly_name': 'Sensor_Setpoint1',
|
||||||
'unit_of_measurement': '°C',
|
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.sensor_setpoint1',
|
'entity_id': 'sensor.sensor_setpoint1',
|
||||||
@ -160,7 +161,7 @@
|
|||||||
'name': None,
|
'name': None,
|
||||||
'options': dict({
|
'options': dict({
|
||||||
}),
|
}),
|
||||||
'original_device_class': None,
|
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': 'Sensor_Var1',
|
'original_name': 'Sensor_Var1',
|
||||||
'platform': 'lcn',
|
'platform': 'lcn',
|
||||||
@ -168,14 +169,15 @@
|
|||||||
'supported_features': 0,
|
'supported_features': 0,
|
||||||
'translation_key': None,
|
'translation_key': None,
|
||||||
'unique_id': 'lcn/config_entry_pchk.json-m000007-var1',
|
'unique_id': 'lcn/config_entry_pchk.json-m000007-var1',
|
||||||
'unit_of_measurement': '°C',
|
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_setup_lcn_sensor[sensor.sensor_var1-state]
|
# name: test_setup_lcn_sensor[sensor.sensor_var1-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'temperature',
|
||||||
'friendly_name': 'Sensor_Var1',
|
'friendly_name': 'Sensor_Var1',
|
||||||
'unit_of_measurement': '°C',
|
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
|
||||||
}),
|
}),
|
||||||
'context': <ANY>,
|
'context': <ANY>,
|
||||||
'entity_id': 'sensor.sensor_var1',
|
'entity_id': 'sensor.sensor_var1',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user