Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion docs/samples/sample_modbus/sample_modbus/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Iterable, Union

from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.common.modbus import ModbusTcpClient_
from modules.devices.sample_modbus.sample_modbus.bat import SampleBat
Expand Down Expand Up @@ -31,7 +32,8 @@ def create_inverter_component(component_config: SampleInverterSetup):
def update_components(components: Iterable[Union[SampleBat, SampleCounter, SampleInverter]]):
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from modules.common import req
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.devices.sample_request_by_device.sample_request_by_device.bat import SampleBat
from modules.devices.sample_request_by_device.sample_request_by_device.config import Sample, SampleBatSetup, SampleCounterSetup, SampleInverterSetup
Expand All @@ -26,7 +27,8 @@ def create_inverter_component(component_config: SampleInverterSetup):
def update_components(components: Iterable[Union[SampleBat, SampleCounter, SampleInverter]]):
response = req.get_http_session().get(device_config.configuration.ip_address, timeout=5).json()
for component in components:
component.update(response)
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update(response)

return ConfigurableDevice(
device_config=device_config,
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/devices/algodue/algodue/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create_counter_component(component_config: AlgodueCounterSetup):
def update_components(components: Iterable[counter.AlgodueCounter]):
with client:
for component in components:
with SingleComponentUpdateContext(component.fault_state):
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/alpha_ess/alpha_ess/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Iterable, Union

from helpermodules.utils.run_command import run_command
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.devices.alpha_ess.alpha_ess.config import (
AlphaEss, AlphaEssBatSetup, AlphaEssCounterSetup, AlphaEssInverterSetup)
Expand Down Expand Up @@ -48,7 +49,8 @@ def update_components(components: Iterable[Union[alpha_ess_component_classes]]):
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/ampere/ampere/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Iterable, Union

from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.common.modbus import ModbusTcpClient_
from modules.devices.ampere.ampere.bat import AmpereBat
Expand Down Expand Up @@ -40,7 +41,8 @@ def create_inverter_component(component_config: AmpereInverterSetup):
def update_components(components: Iterable[Union[AmpereBat, AmpereCounter, AmpereInverter]]):
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/avm/avm/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from helpermodules.pub import Pub
from modules.common import req
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.devices.avm.avm.config import Avm, AvmCounterSetup
from modules.devices.avm.avm.counter import AvmCounter
Expand Down Expand Up @@ -36,7 +37,8 @@ def update_components(components: Iterable[AvmCounter]):
deviceListElementTree = ET.fromstring(response.text.strip())

for component in components:
component.update(deviceListElementTree)
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update(deviceListElementTree)

def get_session_id():
# checking existing sessionID
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/azzurro_zcs/azzurro_zcs/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Iterable, Union

from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.common.modbus import ModbusTcpClient_
from modules.devices.azzurro_zcs.azzurro_zcs.bat import ZCSBat
Expand Down Expand Up @@ -36,7 +37,8 @@ def update_components(components: Iterable[Union[ZCSBat, ZCSCounter, ZCSInverter
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
5 changes: 3 additions & 2 deletions packages/modules/devices/batterx/batterx/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from helpermodules.cli import run_using_positional_cli_args
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import MultiComponentUpdateContext
from modules.common.component_context import MultiComponentUpdateContext, SingleComponentUpdateContext
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.common.store import get_inverter_value_store
from modules.devices.batterx.batterx import bat, external_inverter
Expand Down Expand Up @@ -39,7 +39,8 @@ def update_components(components: Iterable[batterx_component_classes]):
'http://' + device_config.configuration.ip_address + '/api.php?get=currentstate',
timeout=5).json()
for component in components:
component.update(resp_json)
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update(resp_json)

return ConfigurableDevice(
device_config=device_config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import Iterable

from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.devices.carlo_gavazzi.carlo_gavazzi import counter
from modules.devices.carlo_gavazzi.carlo_gavazzi.config import CarloGavazzi, CarloGavazziCounterSetup
Expand All @@ -23,7 +24,8 @@ def update_components(components: Iterable[counter.CarloGavazziCounter]):
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/deye/deye/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from helpermodules.cli import run_using_positional_cli_args
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.common.modbus import ModbusTcpClient_
from modules.devices.deye.deye.bat import DeyeBat
Expand Down Expand Up @@ -34,7 +35,8 @@ def update_components(components: Iterable[Union[DeyeBat, DeyeCounter, DeyeInver
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/e3dc/e3dc/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from helpermodules.cli import run_using_positional_cli_args
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.common import modbus
from modules.devices.e3dc.e3dc.bat import E3dcBat, read_bat
Expand Down Expand Up @@ -59,7 +60,8 @@ def update_components(components: Iterable[Union[E3dcBat, E3dcCounter, E3dcInver
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/enphase/enphase/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from helpermodules.pub import Pub
from modules.common import req
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.devices.enphase.enphase.bat import EnphaseBat
from modules.devices.enphase.enphase.config import (EnphaseVersion,
Expand Down Expand Up @@ -143,7 +144,8 @@ def update_components(components: Iterable[Union[EnphaseBat, EnphaseCounter, Enp
log.error(f"unknown version: {device_config.configuration.version}")
return
for component in components:
component.update(json_response, json_live_data)
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update(json_response, json_live_data)

read_live_data = False
token_tries = 0
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/fox_ess/fox_ess/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Iterable, Union

from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.common.modbus import ModbusTcpClient_
from modules.devices.fox_ess.fox_ess.bat import FoxEssBat
Expand Down Expand Up @@ -32,7 +33,8 @@ def update_components(components: Iterable[Union[FoxEssBat, FoxEssCounter, FoxEs
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/generic/json/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from helpermodules.cli import run_using_positional_cli_args
from modules.common import req
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.devices.generic.json import bat, counter, inverter
from modules.devices.generic.json.bat import JsonBat
Expand Down Expand Up @@ -36,7 +37,8 @@ def create_inverter(component_config: JsonInverterSetup) -> JsonInverter:
def update_components(components: Iterable[JsonComponent]):
response = req.get_http_session().get(device_config.configuration.url, timeout=5).json()
for component in components:
component.update(response)
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update(response)

return ConfigurableDevice(
device_config,
Expand Down
5 changes: 3 additions & 2 deletions packages/modules/devices/generic/mqtt/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def initialize(self) -> None:
self.store = get_bat_value_store(self.component_config.id)

def update(self, received_topics: Dict) -> None:
# [] für erforderliche Topics, .get() für optionale Topics
currents = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/currents")
power = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/power")
soc = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/soc")
power = received_topics[f"openWB/mqtt/bat/{self.component_config.id}/get/power"]
soc = received_topics[f"openWB/mqtt/bat/{self.component_config.id}/get/soc"]
if (received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/imported") and
received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/exported")):
imported = received_topics.get(f"openWB/mqtt/bat/{self.component_config.id}/get/imported")
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/generic/mqtt/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def initialize(self) -> None:
self.store = get_counter_value_store(self.component_config.id)

def update(self, received_topics: Dict) -> None:
# [] für erforderliche Topics, .get() für optionale Topics
currents = received_topics.get(f"openWB/mqtt/counter/{self.component_config.id}/get/currents")
power = received_topics.get(f"openWB/mqtt/counter/{self.component_config.id}/get/power")
power = received_topics[f"openWB/mqtt/counter/{self.component_config.id}/get/power"]
frequency = received_topics.get(f"openWB/mqtt/counter/{self.component_config.id}/get/frequency")
power_factors = received_topics.get(f"openWB/mqtt/counter/{self.component_config.id}/get/power_factors")
powers = received_topics.get(f"openWB/mqtt/counter/{self.component_config.id}/get/powers")
Expand Down
10 changes: 9 additions & 1 deletion packages/modules/devices/generic/mqtt/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from helpermodules.broker import BrokerClient
from helpermodules.utils.topic_parser import decode_payload
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.component_type import type_to_topic_mapping
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.devices.generic.mqtt import bat, counter, inverter
Expand Down Expand Up @@ -38,7 +39,14 @@ def on_message(client, userdata, message):
if received_topics:
log.debug(f"Empfange MQTT Daten für Gerät {device_config.id}: {received_topics}")
for component in components:
component.update(received_topics)
with SingleComponentUpdateContext(component.fault_state, update_always=False):
try:
component.update(received_topics)
except KeyError:
raise KeyError(
"Fehlende MQTT-Daten: Stelle sicher, dass Du Werte an die erforderlichen Topics "
"(beschrieben in den Komponenten-Einstellungen) veröffentlichst (Publish)."
)
else:
for component in components:
component.fault_state.warning(
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/generic/mqtt/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def initialize(self) -> None:
self.store = get_inverter_value_store(self.component_config.id)

def update(self, received_topics: Dict) -> None:
power = received_topics.get(f"openWB/mqtt/pv/{self.component_config.id}/get/power")
# [] für erforderliche Topics, .get() für optionale Topics
power = received_topics[f"openWB/mqtt/pv/{self.component_config.id}/get/power"]
if received_topics.get(f"openWB/mqtt/pv/{self.component_config.id}/get/exported"):
exported = received_topics.get(f"openWB/mqtt/pv/{self.component_config.id}/get/exported")
else:
Expand Down
5 changes: 3 additions & 2 deletions packages/modules/devices/good_we/good_we/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from modules.common import modbus
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.devices.good_we.good_we import bat
from modules.devices.good_we.good_we import counter
Expand Down Expand Up @@ -49,8 +50,8 @@ def update_components(components: Iterable[good_we_component_classes]):
nonlocal client
with client:
for component in components:

component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/growatt/growatt/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from helpermodules.utils.run_command import run_command
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.common.modbus import ModbusTcpClient_
from modules.devices.growatt.growatt.bat import GrowattBat
Expand Down Expand Up @@ -44,7 +45,8 @@ def update_components(components: Iterable[Union[GrowattBat, GrowattCounter, Gro
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/huawei/huawei/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from helpermodules.utils.run_command import run_command
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.common.modbus import ModbusTcpClient_
from modules.devices.huawei.huawei.bat import HuaweiBat
Expand Down Expand Up @@ -47,7 +48,8 @@ def update_components(components: Iterable[Union[HuaweiBat, HuaweiCounter, Huawe
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/huawei/huawei_smartlogger/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from modules.common.abstract_device import DeviceDescriptor
from modules.common import modbus
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.devices.huawei.huawei_smartlogger import counter
from modules.devices.huawei.huawei_smartlogger import inverter
Expand Down Expand Up @@ -40,7 +41,8 @@ def update_components(components: Iterable[huawei_smartlogger_component_classes]
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
4 changes: 3 additions & 1 deletion packages/modules/devices/janitza/janitza/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from typing import Iterable, Union

from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
from modules.common import modbus
from modules.common.abstract_device import DeviceDescriptor
Expand Down Expand Up @@ -34,7 +35,8 @@ def update_components(components: Iterable[Union[counter.JanitzaCounter, inverte
nonlocal client
with client:
for component in components:
component.update()
with SingleComponentUpdateContext(component.fault_state, update_always=False):
component.update()

def initializer():
nonlocal client
Expand Down
Loading