Add the Current consumption attribute to the D-Link smart power plug integration (#182038)

This commit is contained in:
Matej Pramník
2026-09-19 09:19:02 +02:00
committed by GitHub
parent bf34679c7c
commit e0008c39f8
3 changed files with 10 additions and 1 deletions
+1
View File
@@ -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"
+7 -1
View File
@@ -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
+2
View File
@@ -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