1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-27 05:14:39 +00:00

Add support for current sensors to egauge integration (#163728)

This commit is contained in:
Nic Eggert
2026-02-23 06:29:20 -06:00
committed by GitHub
parent 0f6a3a8328
commit 6299e8cb77
3 changed files with 76 additions and 2 deletions

View File

@@ -13,7 +13,12 @@ from homeassistant.components.sensor import (
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import UnitOfElectricPotential, UnitOfEnergy, UnitOfPower
from homeassistant.const import (
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfPower,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@@ -59,6 +64,15 @@ SENSORS: tuple[EgaugeSensorEntityDescription, ...] = (
available_fn=lambda data, register: register in data.measurements,
supported_fn=lambda register_info: register_info.type == RegisterType.VOLTAGE,
),
EgaugeSensorEntityDescription(
key="current",
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
native_value_fn=lambda data, register: data.measurements[register],
available_fn=lambda data, register: register in data.measurements,
supported_fn=lambda register_info: register_info.type == RegisterType.CURRENT,
),
)

View File

@@ -66,6 +66,7 @@ def mock_egauge_client() -> Generator[MagicMock]:
name="Temp", type=RegisterType.TEMPERATURE, idx=2, did=None
),
"L1": RegisterInfo(name="L1", type=RegisterType.VOLTAGE, idx=3, did=None),
"S1": RegisterInfo(name="S1", type=RegisterType.CURRENT, idx=4, did=None),
}
# Dynamic measurements
@@ -74,12 +75,14 @@ def mock_egauge_client() -> Generator[MagicMock]:
"Solar": -2500.0,
"Temp": 45.0,
"L1": 123.4,
"S1": 1.2,
}
client.get_current_counters.return_value = {
"Grid": 450000000.0, # 125 kWh in Ws
"Solar": 315000000.0, # 87.5 kWh in Ws
"Temp": 0.0,
"L1": 12345678.0,
"S1": 12345.0,
}
yield client

View File

@@ -1,5 +1,5 @@
# serializer version: 1
# name: test_sensors.10
# name: test_sensors.12
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
@@ -204,6 +204,63 @@
'state': '123.4',
})
# ---
# name: test_sensors[sensor.egauge_home_s1_current-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.egauge_home_s1_current',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': 'Current',
'options': dict({
'sensor': dict({
'suggested_display_precision': 2,
}),
}),
'original_device_class': <SensorDeviceClass.CURRENT: 'current'>,
'original_icon': None,
'original_name': 'Current',
'platform': 'egauge',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': 'ABC123456_S1_current',
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
})
# ---
# name: test_sensors[sensor.egauge_home_s1_current-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'current',
'friendly_name': 'egauge-home S1 Current',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfElectricCurrent.AMPERE: 'A'>,
}),
'context': <ANY>,
'entity_id': 'sensor.egauge_home_s1_current',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '1.2',
})
# ---
# name: test_sensors[sensor.egauge_home_solar_energy-entry]
EntityRegistryEntrySnapshot({
'aliases': set({