Use new SensorDeviceClass and SensorStateClass in velbus (#61339)

This commit is contained in:
Maikel Punie 2021-12-09 10:28:51 +01:00 committed by GitHub
parent 11ee0fb1d0
commit 22f71a89e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,16 +4,11 @@ from __future__ import annotations
from velbusaio.channels import ButtonCounter, LightSensor, SensorNumber, Temperature from velbusaio.channels import ButtonCounter, LightSensor, SensorNumber, Temperature
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT, SensorDeviceClass,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity, SensorEntity,
SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry 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.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -58,19 +53,19 @@ class VelbusSensor(VelbusEntity, SensorEntity):
self._attr_name = f"{self._attr_name}-counter" self._attr_name = f"{self._attr_name}-counter"
# define the device class # define the device class
if self._is_counter: if self._is_counter:
self._attr_device_class = DEVICE_CLASS_ENERGY self._attr_device_class = SensorDeviceClass.ENERGY
elif channel.is_counter_channel(): elif channel.is_counter_channel():
self._attr_device_class = DEVICE_CLASS_POWER self._attr_device_class = SensorDeviceClass.POWER
elif channel.is_temperature(): elif channel.is_temperature():
self._attr_device_class = DEVICE_CLASS_TEMPERATURE self._attr_device_class = SensorDeviceClass.TEMPERATURE
# define the icon # define the icon
if self._is_counter: if self._is_counter:
self._attr_icon = "mdi:counter" self._attr_icon = "mdi:counter"
# the state class # the state class
if self._is_counter: if self._is_counter:
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING self._attr_state_class = SensorStateClass.TOTAL_INCREASING
else: else:
self._attr_state_class = STATE_CLASS_MEASUREMENT self._attr_state_class = SensorStateClass.MEASUREMENT
# unit # unit
if self._is_counter: if self._is_counter:
self._attr_native_unit_of_measurement = channel.get_counter_unit() self._attr_native_unit_of_measurement = channel.get_counter_unit()