From f03fd725142ea99224aaf91c15fd0a255d017d18 Mon Sep 17 00:00:00 2001 From: WilliamCoenen <57435489+WilliamCoenen@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:31:41 +0100 Subject: [PATCH] Fix missing units on Velbus electricity counter sensors (#191120) --- homeassistant/components/velbus/sensor.py | 6 +++--- tests/components/velbus/snapshots/test_sensor.ambr | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/velbus/sensor.py b/homeassistant/components/velbus/sensor.py index 5a380f93586f..04f30a2ce276 100644 --- a/homeassistant/components/velbus/sensor.py +++ b/homeassistant/components/velbus/sensor.py @@ -13,7 +13,7 @@ from homeassistant.components.sensor import ( SensorEntityDescription, SensorStateClass, ) -from homeassistant.const import UnitOfVolume +from homeassistant.const import UnitOfEnergy, UnitOfPower, UnitOfVolume from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback @@ -41,8 +41,8 @@ SENSOR_DESCRIPTIONS: dict[str, VelbusSensorEntityDescription] = { key="power", device_class=SensorDeviceClass.POWER, state_class=SensorStateClass.MEASUREMENT, + native_unit_of_measurement=UnitOfPower.WATT, value_fn=lambda channel: float(channel.get_counter_state()), - unit_fn=lambda channel: channel.get_unit(), ), "flow": VelbusSensorEntityDescription( key="flow", @@ -67,12 +67,12 @@ SENSOR_DESCRIPTIONS: dict[str, VelbusSensorEntityDescription] = { device_class=SensorDeviceClass.ENERGY, icon="mdi:counter", state_class=SensorStateClass.TOTAL_INCREASING, + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, value_fn=lambda channel: ( float(channel.energy) if hasattr(channel, "energy") and channel.energy is not None else None ), - unit_fn=lambda channel: channel.get_counter_unit(), unique_id_suffix="-counter", ), "gas": VelbusSensorEntityDescription( diff --git a/tests/components/velbus/snapshots/test_sensor.ambr b/tests/components/velbus/snapshots/test_sensor.ambr index b24e439a7392..067a696ee06f 100644 --- a/tests/components/velbus/snapshots/test_sensor.ambr +++ b/tests/components/velbus/snapshots/test_sensor.ambr @@ -38,7 +38,7 @@ 'supported_features': 0, 'translation_key': None, 'unique_id': 'a1b2c3d4e5f6-2', - 'unit_of_measurement': 'W', + 'unit_of_measurement': , }) # --- # name: test_entities[sensor.input_buttoncounter-state] @@ -47,7 +47,7 @@ : 'power', : 'Input ButtonCounter', : , - : 'W', + : , }), 'context': , 'entity_id': 'sensor.input_buttoncounter', @@ -96,7 +96,7 @@ 'supported_features': 0, 'translation_key': None, 'unique_id': 'a1b2c3d4e5f6-2-counter', - 'unit_of_measurement': 'kWh', + 'unit_of_measurement': , }) # --- # name: test_entities[sensor.input_buttoncounter_counter-state] @@ -106,7 +106,7 @@ : 'Input ButtonCounter-counter', : 'mdi:counter', : , - : 'kWh', + : , }), 'context': , 'entity_id': 'sensor.input_buttoncounter_counter',