From e0008c39f87818c2dbd8557aa1ebc8a57f7f3403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Pramn=C3=ADk?= Date: Sat, 19 Sep 2026 09:19:02 +0200 Subject: [PATCH] Add the Current consumption attribute to the D-Link smart power plug integration (#182038) --- homeassistant/components/dlink/const.py | 1 + homeassistant/components/dlink/switch.py | 8 +++++++- tests/components/dlink/test_switch.py | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/dlink/const.py b/homeassistant/components/dlink/const.py index b39cd8be4765..0828c2e4ee13 100644 --- a/homeassistant/components/dlink/const.py +++ b/homeassistant/components/dlink/const.py @@ -2,6 +2,7 @@ ATTRIBUTION = "Data provided by D-Link" ATTR_TOTAL_CONSUMPTION = "total_consumption" +ATTR_CURRENT_CONSUMPTION = "current_consumption" CONF_USE_LEGACY_PROTOCOL = "use_legacy_protocol" diff --git a/homeassistant/components/dlink/switch.py b/homeassistant/components/dlink/switch.py index 19b255984182..371cccda2b46 100644 --- a/homeassistant/components/dlink/switch.py +++ b/homeassistant/components/dlink/switch.py @@ -9,7 +9,7 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from . import DLinkConfigEntry -from .const import ATTR_TOTAL_CONSUMPTION +from .const import ATTR_CURRENT_CONSUMPTION, ATTR_TOTAL_CONSUMPTION from .entity import DLinkEntity SCAN_INTERVAL = timedelta(minutes=2) @@ -49,9 +49,15 @@ class SmartPlugSwitch(DLinkEntity, SwitchEntity): except ValueError: total_consumption = None + try: + current_consumption = float(self.data.current_consumption) + except ValueError: + current_consumption = None + return { ATTR_TOTAL_CONSUMPTION: total_consumption, ATTR_TEMPERATURE: temperature, + ATTR_CURRENT_CONSUMPTION: current_consumption, } @property diff --git a/tests/components/dlink/test_switch.py b/tests/components/dlink/test_switch.py index 0460a6a918f3..7069a03c75d7 100644 --- a/tests/components/dlink/test_switch.py +++ b/tests/components/dlink/test_switch.py @@ -34,6 +34,7 @@ async def test_switch_state(hass: HomeAssistant, mocked_plug: AsyncMock) -> None assert state.state == STATE_OFF assert state.attributes["total_consumption"] == 1040.0 assert state.attributes["temperature"] == 33 + assert state.attributes["current_consumption"] == 50.0 await hass.services.async_call( SWITCH_DOMAIN, SERVICE_TURN_ON, @@ -67,3 +68,4 @@ async def test_switch_no_value( assert state.state == STATE_OFF assert state.attributes["total_consumption"] is None assert state.attributes["temperature"] is None + assert state.attributes["current_consumption"] is None