From 6299e8cb7758a9caf2eea9dd67835a8fefebfa35 Mon Sep 17 00:00:00 2001 From: Nic Eggert Date: Mon, 23 Feb 2026 06:29:20 -0600 Subject: [PATCH] Add support for current sensors to egauge integration (#163728) --- homeassistant/components/egauge/sensor.py | 16 ++++- tests/components/egauge/conftest.py | 3 + .../egauge/snapshots/test_sensor.ambr | 59 ++++++++++++++++++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/egauge/sensor.py b/homeassistant/components/egauge/sensor.py index 2abd1c6886d..743bc34a429 100644 --- a/homeassistant/components/egauge/sensor.py +++ b/homeassistant/components/egauge/sensor.py @@ -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, + ), ) diff --git a/tests/components/egauge/conftest.py b/tests/components/egauge/conftest.py index c78ee0a7233..d12a10a5c17 100644 --- a/tests/components/egauge/conftest.py +++ b/tests/components/egauge/conftest.py @@ -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 diff --git a/tests/components/egauge/snapshots/test_sensor.ambr b/tests/components/egauge/snapshots/test_sensor.ambr index 9a939b1419d..74b3d029b60 100644 --- a/tests/components/egauge/snapshots/test_sensor.ambr +++ b/tests/components/egauge/snapshots/test_sensor.ambr @@ -1,5 +1,5 @@ # serializer version: 1 -# name: test_sensors.10 +# name: test_sensors.12 DeviceRegistryEntrySnapshot({ 'area_id': None, 'config_entries': , @@ -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': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + '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': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Current', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + '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': , + }) +# --- +# name: test_sensors[sensor.egauge_home_s1_current-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'current', + 'friendly_name': 'egauge-home S1 Current', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.egauge_home_s1_current', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '1.2', + }) +# --- # name: test_sensors[sensor.egauge_home_solar_energy-entry] EntityRegistryEntrySnapshot({ 'aliases': set({