From 22c129d39131a85bd0a667294e48978ecd9451d5 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 27 Aug 2026 09:56:09 +0200 Subject: [PATCH] Fix WLED estimated current missing with per output limiters (#180359) --- homeassistant/components/wled/sensor.py | 4 +++- tests/components/wled/test_sensor.py | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/wled/sensor.py b/homeassistant/components/wled/sensor.py index a81456dc6846..74aed519c705 100644 --- a/homeassistant/components/wled/sensor.py +++ b/homeassistant/components/wled/sensor.py @@ -49,7 +49,9 @@ SENSORS: tuple[WLEDSensorEntityDescription, ...] = ( state_class=SensorStateClass.MEASUREMENT, entity_category=EntityCategory.DIAGNOSTIC, value_fn=lambda device: device.info.leds.power, - exists_fn=lambda device: bool(device.info.leds.max_power), + # The power budget is only reported for a global current limit, while + # the estimate itself is also reported when limiting per output. + exists_fn=lambda device: bool(device.info.leds.power), ), WLEDSensorEntityDescription( key="info_leds_count", diff --git a/tests/components/wled/test_sensor.py b/tests/components/wled/test_sensor.py index 65ab75fa6ae5..e7065d91c8dc 100644 --- a/tests/components/wled/test_sensor.py +++ b/tests/components/wled/test_sensor.py @@ -93,9 +93,10 @@ async def test_no_current_measurement( mock_config_entry: MockConfigEntry, mock_wled: MagicMock, ) -> None: - """Test missing current information when no max power is defined.""" + """Test missing current information when the device estimates no current.""" device = mock_wled.update.return_value device.info.leds.max_power = 0 + device.info.leds.power = 0 mock_config_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_config_entry.entry_id) @@ -105,6 +106,27 @@ async def test_no_current_measurement( assert hass.states.get("sensor.wled_rgb_light_estimated_current") is None +async def test_current_measurement_with_per_output_limiters( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + mock_wled: MagicMock, +) -> None: + """Test estimated current is available when limiting current per output.""" + # Per output limiters leave the global power budget unset, while the + # device keeps estimating and reporting the current it draws. + device = mock_wled.update.return_value + device.info.leds.max_power = 0 + device.info.leds.power = 3193 + + mock_config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + assert hass.states.get("sensor.wled_rgb_light_max_current") is None + assert (state := hass.states.get("sensor.wled_rgb_light_estimated_current")) + assert state.state == "3193" + + async def test_fail_when_other_device( hass: HomeAssistant, mock_config_entry: MockConfigEntry,