mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Fix missing units on Velbus electricity counter sensors (#191120)
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'a1b2c3d4e5f6-2',
|
||||
'unit_of_measurement': 'W',
|
||||
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_entities[sensor.input_buttoncounter-state]
|
||||
@@ -47,7 +47,7 @@
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'power',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Input ButtonCounter',
|
||||
<SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
<EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: 'W',
|
||||
<EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: <UnitOfPower.WATT: 'W'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'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': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_entities[sensor.input_buttoncounter_counter-state]
|
||||
@@ -106,7 +106,7 @@
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Input ButtonCounter-counter',
|
||||
<EntityStateAttribute.ICON: 'icon'>: 'mdi:counter',
|
||||
<SensorEntityCapabilityAttribute.STATE_CLASS: 'state_class'>: <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
<EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: 'kWh',
|
||||
<EntityStateAttribute.UNIT_OF_MEASUREMENT: 'unit_of_measurement'>: <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.input_buttoncounter_counter',
|
||||
|
||||
Reference in New Issue
Block a user