mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 09:23:17 -04:00
Add the Current consumption attribute to the D-Link smart power plug integration (#182038)
This commit is contained in:
@@ -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"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user