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 <marhje52@gmail.com>
This commit is contained in:
karwosts 2025-03-24 04:37:55 -07:00 committed by GitHub
parent 75cd32b742
commit 1ae2cebeb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -139,6 +139,10 @@ class DeviceConsumption(TypedDict):
# An optional custom name for display in energy graphs
name: str | None
# An optional statistic_id identifying a device
# that includes this device's consumption in its total
included_in_stat: str | None
class EnergyPreferences(TypedDict):
"""Dictionary holding the energy data."""
@ -291,6 +295,7 @@ DEVICE_CONSUMPTION_SCHEMA = vol.Schema(
{
vol.Required("stat_consumption"): str,
vol.Optional("name"): str,
vol.Optional("included_in_stat"): str,
}
)

View File

@ -149,7 +149,13 @@ async def test_save_preferences(
"stat_energy_to": "my_battery_charging",
},
],
"device_consumption": [{"stat_consumption": "some_device_usage"}],
"device_consumption": [
{
"stat_consumption": "some_device_usage",
"name": "My Device",
"included_in_stat": "sensor.some_other_device",
}
],
}
await client.send_json({"id": 6, "type": "energy/save_prefs", **new_prefs})