Skip to content

Commit 1ae2ceb

Browse files
Support for hierarchy of individual energy devices (#132616)
* Support for hierarchy of individual energy devices * update DeviceConsumption dict * change name parent to 'included_in' * Break comment --------- Co-authored-by: Martin Hjelmare <[email protected]>
1 parent 75cd32b commit 1ae2ceb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

homeassistant/components/energy/data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ class DeviceConsumption(TypedDict):
139139
# An optional custom name for display in energy graphs
140140
name: str | None
141141

142+
# An optional statistic_id identifying a device
143+
# that includes this device's consumption in its total
144+
included_in_stat: str | None
145+
142146

143147
class EnergyPreferences(TypedDict):
144148
"""Dictionary holding the energy data."""
@@ -291,6 +295,7 @@ def check_type_limits(value: list[SourceType]) -> list[SourceType]:
291295
{
292296
vol.Required("stat_consumption"): str,
293297
vol.Optional("name"): str,
298+
vol.Optional("included_in_stat"): str,
294299
}
295300
)
296301

tests/components/energy/test_websocket_api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ async def test_save_preferences(
149149
"stat_energy_to": "my_battery_charging",
150150
},
151151
],
152-
"device_consumption": [{"stat_consumption": "some_device_usage"}],
152+
"device_consumption": [
153+
{
154+
"stat_consumption": "some_device_usage",
155+
"name": "My Device",
156+
"included_in_stat": "sensor.some_other_device",
157+
}
158+
],
153159
}
154160

155161
await client.send_json({"id": 6, "type": "energy/save_prefs", **new_prefs})

0 commit comments

Comments
 (0)