Use new SensorDeviceClass and SensorStateClass in velbus (#61339)
This commit is contained in:
parent
11ee0fb1d0
commit
22f71a89e0
1 changed files with 7 additions and 12 deletions
|
@ -4,16 +4,11 @@ from __future__ import annotations
|
|||
from velbusaio.channels import ButtonCounter, LightSensor, SensorNumber, Temperature
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
|
@ -58,19 +53,19 @@ class VelbusSensor(VelbusEntity, SensorEntity):
|
|||
self._attr_name = f"{self._attr_name}-counter"
|
||||
# define the device class
|
||||
if self._is_counter:
|
||||
self._attr_device_class = DEVICE_CLASS_ENERGY
|
||||
self._attr_device_class = SensorDeviceClass.ENERGY
|
||||
elif channel.is_counter_channel():
|
||||
self._attr_device_class = DEVICE_CLASS_POWER
|
||||
self._attr_device_class = SensorDeviceClass.POWER
|
||||
elif channel.is_temperature():
|
||||
self._attr_device_class = DEVICE_CLASS_TEMPERATURE
|
||||
self._attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||
# define the icon
|
||||
if self._is_counter:
|
||||
self._attr_icon = "mdi:counter"
|
||||
# the state class
|
||||
if self._is_counter:
|
||||
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
|
||||
else:
|
||||
self._attr_state_class = STATE_CLASS_MEASUREMENT
|
||||
self._attr_state_class = SensorStateClass.MEASUREMENT
|
||||
# unit
|
||||
if self._is_counter:
|
||||
self._attr_native_unit_of_measurement = channel.get_counter_unit()
|
||||
|
|
Loading…
Add table
Reference in a new issue