2025-01-12 05:19:37 +01:00
|
|
|
from typing import Optional
|
2024-12-15 14:40:03 +01:00
|
|
|
|
|
|
|
from akkudoktoreos.core.coreabc import SingletonMixin
|
2024-12-19 14:50:19 +01:00
|
|
|
from akkudoktoreos.devices.battery import Battery
|
2024-12-15 14:40:03 +01:00
|
|
|
from akkudoktoreos.devices.devicesabc import DevicesBase
|
|
|
|
from akkudoktoreos.devices.generic import HomeAppliance
|
2024-12-16 15:33:00 +01:00
|
|
|
from akkudoktoreos.devices.inverter import Inverter
|
2025-01-12 05:19:37 +01:00
|
|
|
from akkudoktoreos.devices.settings import DevicesCommonSettings
|
2024-12-15 14:40:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Devices(SingletonMixin, DevicesBase):
|
2025-01-12 05:19:37 +01:00
|
|
|
def __init__(self, settings: Optional[DevicesCommonSettings] = None):
|
|
|
|
if hasattr(self, "_initialized"):
|
|
|
|
return
|
|
|
|
super().__init__()
|
|
|
|
if settings is None:
|
|
|
|
settings = self.config.devices
|
|
|
|
if settings is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
# initialize devices
|
|
|
|
if settings.batteries is not None:
|
|
|
|
for battery_params in settings.batteries:
|
|
|
|
self.add_device(Battery(battery_params))
|
|
|
|
if settings.inverters is not None:
|
|
|
|
for inverter_params in settings.inverters:
|
|
|
|
self.add_device(Inverter(inverter_params))
|
|
|
|
if settings.home_appliances is not None:
|
|
|
|
for home_appliance_params in settings.home_appliances:
|
|
|
|
self.add_device(HomeAppliance(home_appliance_params))
|
|
|
|
|
|
|
|
self.post_setup()
|
|
|
|
|
|
|
|
def post_setup(self) -> None:
|
|
|
|
for device in self.devices.values():
|
|
|
|
device.post_setup()
|
|
|
|
|
|
|
|
|
2025-04-23 16:26:04 +02:00
|
|
|
# Initialize the Devices simulation, it is a singleton.
|
|
|
|
devices: Optional[Devices] = None
|
2024-12-15 14:40:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_devices() -> Devices:
|
2025-04-23 16:26:04 +02:00
|
|
|
global devices
|
|
|
|
# Fix circular import at runtime
|
|
|
|
if devices is None:
|
|
|
|
devices = Devices()
|
2024-12-15 14:40:03 +01:00
|
|
|
"""Gets the EOS Devices simulation."""
|
|
|
|
return devices
|