Correct sensor state attribute and device class in Velbus sensors (#102099)

This commit is contained in:
Maikel Punie 2023-10-16 14:23:43 +02:00 committed by GitHub
parent 79811e3cd9
commit 4913e7e846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,25 +45,18 @@ class VelbusSensor(VelbusEntity, SensorEntity):
"""Initialize a sensor Velbus entity."""
super().__init__(channel)
self._is_counter: bool = counter
# define the unique id
if self._is_counter:
self._attr_unique_id = f"{self._attr_unique_id}-counter"
# define the name
if self._is_counter:
self._attr_name = f"{self._attr_name}-counter"
# define the device class
if self._is_counter:
self._attr_device_class = SensorDeviceClass.POWER
elif channel.is_counter_channel():
self._attr_device_class = SensorDeviceClass.ENERGY
self._attr_icon = "mdi:counter"
self._attr_name = f"{self._attr_name}-counter"
self._attr_state_class = SensorStateClass.TOTAL_INCREASING
self._attr_unique_id = f"{self._attr_unique_id}-counter"
elif channel.is_counter_channel():
self._attr_device_class = SensorDeviceClass.POWER
self._attr_state_class = SensorStateClass.MEASUREMENT
elif channel.is_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 = SensorStateClass.TOTAL_INCREASING
self._attr_state_class = SensorStateClass.MEASUREMENT
else:
self._attr_state_class = SensorStateClass.MEASUREMENT
# unit