sunlit_solar/helper.py
2025-06-06 08:00:51 +00:00

18 lines
994 B
Python

def get_merged_device_data(coordinator):
"""Fetch and merge data from the coordinator for the given entry."""
ret = {}
for family in coordinator.data:
ret[family['id']] = family.copy() # Use copy to avoid modifying the original family data
_devices = family.get("devices", []).copy() # Use copy to avoid modifying the original list
ret[family['id']]['devices'] = {}
if "devices" not in family:
continue
for device in _devices:
device = {**device, **device.get("statistics", {})} # Merge statistics into device
if device["deviceType"] == "ENERGY_STORAGE_BATTERY":
space = family["spaces"].get(device["spaceId"], {})
device = {**device, **space.get("battery",{})} # Merge statistics into device
device = {**device, **space.get("today", {})} # Merge earnings into device
ret[family['id']]['devices'][device['deviceId']] = device
return ret