From 4913e7e84699a57f5ec5f5e4ff687cd14787d53d Mon Sep 17 00:00:00 2001 From: Maikel Punie Date: Mon, 16 Oct 2023 14:23:43 +0200 Subject: [PATCH] Correct sensor state attribute and device class in Velbus sensors (#102099) --- homeassistant/components/velbus/sensor.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/velbus/sensor.py b/homeassistant/components/velbus/sensor.py index 0805ae2699a..8e1f8bba74a 100644 --- a/homeassistant/components/velbus/sensor.py +++ b/homeassistant/components/velbus/sensor.py @@ -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