Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/modules/devices/rct/rct/device.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/env python3
import logging
import time
from typing import Callable
from typing import Iterable, Union

from modules.common.abstract_device import DeviceDescriptor
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, IndependentComponentUpdater
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.devices.rct.rct import rct_lib
from modules.devices.rct.rct.bat import RctBat
from modules.devices.rct.rct.config import Rct, RctBatSetup, RctCounterSetup, RctInverterSetup
Expand All @@ -24,13 +25,14 @@ def create_counter_component(component_config: RctCounterSetup):
def create_inverter_component(component_config: RctInverterSetup):
return RctInverter(component_config)

def update_component(update_func: Callable[[rct_lib.RCT], None]):
def update_components(components: Iterable[Union[RctBat, RctCounter, RctInverter]]):
# Verbindungsfehler betrifft alle Komponenten, ein Fehler pro Komponente nur diese eine.
rct = rct_lib.RCT(device_config.configuration.ip_address)
try:
rct = rct_lib.RCT(device_config.configuration.ip_address)
if rct.connect_to_server():
update_func(rct)
except Exception:
raise
rct.connect_to_server()
for component in components:
with SingleComponentUpdateContext(component.fault_state):
component.update(rct)
finally:
rct.close()
time.sleep(0.5)
Expand All @@ -42,7 +44,7 @@ def update_component(update_func: Callable[[rct_lib.RCT], None]):
counter=create_counter_component,
inverter=create_inverter_component,
),
component_updater=IndependentComponentUpdater(lambda component: update_component(component.update)),
component_updater=MultiComponentUpdater(update_components),
)


Expand Down
Loading