From 912510f789d9e7cb5b33ea1220ee93814a2be2f1 Mon Sep 17 00:00:00 2001 From: Lutz Bender Date: Tue, 7 Jul 2026 12:46:10 +0200 Subject: [PATCH 1/2] flake8 upgrade --- .github/workflows/github-actions-python.yml | 4 +- .../sample_modbus/sample_modbus/device.py | 6 +-- .../sample_request_by_component/bat.py | 2 +- .../sample_request_by_component/device.py | 4 +- .../sample_request_by_device/device.py | 4 +- .../control/chargepoint/chargepoint_data.py | 2 +- packages/control/data.py | 1 - packages/helpermodules/logger.py | 3 -- .../modules/devices/algodue/algodue/device.py | 3 -- .../devices/alpha_ess/alpha_ess/device.py | 4 -- .../modules/devices/ampere/ampere/device.py | 3 -- .../devices/anker/anker_solix/device.py | 4 -- .../devices/azzurro_zcs/azzurro_zcs/device.py | 4 -- .../azzurro_zcs/azzurro_zcs_3p/device.py | 2 - .../carlo_gavazzi/carlo_gavazzi/device.py | 2 - .../modules/devices/chint/chint/device.py | 1 - packages/modules/devices/deye/deye/device.py | 4 -- .../devices/deye/deye_solarman/device.py | 4 -- packages/modules/devices/e3dc/e3dc/device.py | 5 --- .../modules/devices/elgris/elgris/device.py | 3 -- packages/modules/devices/fems/fems/device.py | 3 -- .../modules/devices/fox_ess/fox_ess/device.py | 4 -- .../modules/devices/good_we/good_we/device.py | 4 -- .../modules/devices/growatt/growatt/device.py | 4 -- .../modules/devices/huawei/huawei/device.py | 4 -- .../devices/huawei/huawei_emma/device.py | 4 -- .../huawei/huawei_smartlogger/device.py | 4 -- packages/modules/devices/idm/idm/device.py | 1 - .../modules/devices/janitza/janitza/device.py | 4 -- .../modules/devices/kaco/kaco_tx/device.py | 2 - .../devices/kostal/kostal_piko_ci/device.py | 3 -- .../kostal/kostal_plenticore/device.py | 4 -- .../devices/kostal/kostal_sem/device.py | 1 - .../devices/marstek/venus_c_e/device.py | 1 - packages/modules/devices/mtec/mtec/device.py | 4 -- packages/modules/devices/nibe/nibe/device.py | 1 - .../devices/openwb/openwb_bat_kit/device.py | 2 - .../devices/openwb/openwb_evu_kit/device.py | 4 -- .../devices/openwb/openwb_flex/device.py | 4 -- .../devices/openwb/openwb_pv_kit/device.py | 2 - packages/modules/devices/orno/orno/device.py | 1 - .../devices/powerdog/powerdog/device.py | 3 -- .../modules/devices/qcells/qcells/device.py | 4 -- .../devices/saxpower/saxpower/device.py | 2 - .../modules/devices/shelly/shelly/device.py | 3 -- .../modules/devices/siemens/siemens/device.py | 4 -- .../devices/siemens/siemens_sentron/device.py | 4 -- .../devices/sigenergy/sigenergy/device.py | 4 -- .../devices/sma/sma_shm/speedwire_listener.py | 5 ++- .../devices/sma/sma_sunny_boy/device.py | 4 -- .../devices/sma/sma_sunny_island/device.py | 2 - .../modules/devices/sofar/sofar/device.py | 4 -- .../devices/solakon/solakon_one/device.py | 3 -- .../devices/solaredge/solaredge/device.py | 5 --- .../devices/solarmax/solarmax/device.py | 5 --- .../modules/devices/solax/solax/device.py | 1 - .../modules/devices/solis/solis/device.py | 4 -- .../modules/devices/studer/studer/device.py | 3 -- .../devices/sungrow/sungrow_ihm/device.py | 3 -- .../devices/sungrow/sungrow_micro/device.py | 1 - .../devices/sungrow/sungrow_sg/device.py | 2 - .../devices/sungrow/sungrow_sh/device.py | 3 -- .../modules/devices/tesla/tesla/device.py | 1 - .../modules/devices/thermia/thermia/device.py | 1 - .../modules/devices/upower/upower/device.py | 3 -- .../modules/devices/varta/varta/device.py | 4 -- .../modules/devices/victron/victron/device.py | 4 -- .../devices/victron/victron_3p75ct/device.py | 2 - packages/modules/io_devices/dimm_kit/api.py | 2 - packages/modules/io_devices/eebus/api.py | 2 - packages/modules/smarthome/mqtt/off.py | 2 +- packages/modules/smarthome/mqtt/on.py | 2 +- packages/modules/smarthome/mqtt/watt.py | 2 - packages/modules/vehicles/kia/api.py | 4 -- packages/smarthome/smartcommon.py | 15 ------- simpleAPI/simpleAPI_mqtt.py | 40 +++++++++---------- 76 files changed, 37 insertions(+), 242 deletions(-) diff --git a/.github/workflows/github-actions-python.yml b/.github/workflows/github-actions-python.yml index c3f0634f7f..87b55c8029 100644 --- a/.github/workflows/github-actions-python.yml +++ b/.github/workflows/github-actions-python.yml @@ -18,12 +18,12 @@ jobs: uses: TrueBrain/actions-flake8@v2.1 with: path: packages - flake8_version: 5.0.4 + flake8_version: "7.3.0" - name: Flake8 with annotations in runs folder uses: TrueBrain/actions-flake8@v2.1 with: path: runs - flake8_version: 5.0.4 + flake8_version: "7.3.0" - name: Test with pytest run: | PYTHONPATH=packages python -m pytest packages --log-cli-level=DEBUG diff --git a/docs/samples/sample_modbus/sample_modbus/device.py b/docs/samples/sample_modbus/sample_modbus/device.py index f78bc2f76a..02ec9ec674 100644 --- a/docs/samples/sample_modbus/sample_modbus/device.py +++ b/docs/samples/sample_modbus/sample_modbus/device.py @@ -7,7 +7,8 @@ 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 -from modules.devices.sample_modbus.sample_modbus.config import Sample, SampleBatSetup, SampleCounterSetup, SampleInverterSetup +from modules.devices.sample_modbus.sample_modbus.config import (Sample, SampleBatSetup, SampleCounterSetup, + SampleInverterSetup) from modules.devices.sample_modbus.sample_modbus.counter import SampleCounter from modules.devices.sample_modbus.sample_modbus.inverter import SampleInverter @@ -18,15 +19,12 @@ def create_device(device_config: Sample): client = None def create_bat_component(component_config: SampleBatSetup): - nonlocal client return SampleBat(component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: SampleCounterSetup): - nonlocal client return SampleCounter(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: SampleInverterSetup): - nonlocal client return SampleInverter(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[SampleBat, SampleCounter, SampleInverter]]): diff --git a/docs/samples/sample_request_by_component/sample_request_by_component/bat.py b/docs/samples/sample_request_by_component/sample_request_by_component/bat.py index 4f56f852f0..f5d01f6f4d 100644 --- a/docs/samples/sample_request_by_component/sample_request_by_component/bat.py +++ b/docs/samples/sample_request_by_component/sample_request_by_component/bat.py @@ -7,7 +7,7 @@ from modules.common.fault_state import ComponentInfo, FaultState from modules.common.simcount import SimCounter from modules.common.store import get_bat_value_store -from modules.devices.sample_request_by_component.sample_request_by_component.config import SampleBatSetup, SampleConfiguration +from modules.devices.sample_request_by_component.sample_request_by_component.config import SampleBatSetup from modules.common.utils.peak_filter import PeakFilter from modules.common.component_type import ComponentType diff --git a/docs/samples/sample_request_by_component/sample_request_by_component/device.py b/docs/samples/sample_request_by_component/sample_request_by_component/device.py index 508546fbc9..7104f152d6 100644 --- a/docs/samples/sample_request_by_component/sample_request_by_component/device.py +++ b/docs/samples/sample_request_by_component/sample_request_by_component/device.py @@ -4,7 +4,9 @@ from modules.common.abstract_device import DeviceDescriptor from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, IndependentComponentUpdater from modules.devices.sample_request_by_component.sample_request_by_component.bat import SampleBat -from modules.devices.sample_request_by_component.sample_request_by_component.config import Sample, SampleBatSetup, SampleCounterSetup, SampleInverterSetup +from modules.devices.sample_request_by_component.sample_request_by_component.config import (Sample, SampleBatSetup, + SampleCounterSetup, + SampleInverterSetup) from modules.devices.sample_request_by_component.sample_request_by_component.counter import SampleCounter from modules.devices.sample_request_by_component.sample_request_by_component.inverter import SampleInverter diff --git a/docs/samples/sample_request_by_device/sample_request_by_device/device.py b/docs/samples/sample_request_by_device/sample_request_by_device/device.py index 0a0f912dde..60414b65f5 100644 --- a/docs/samples/sample_request_by_device/sample_request_by_device/device.py +++ b/docs/samples/sample_request_by_device/sample_request_by_device/device.py @@ -7,7 +7,9 @@ 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 +from modules.devices.sample_request_by_device.sample_request_by_device.config import (Sample, SampleBatSetup, + SampleCounterSetup, + SampleInverterSetup) from modules.devices.sample_request_by_device.sample_request_by_device.counter import SampleCounter from modules.devices.sample_request_by_device.sample_request_by_device.inverter import SampleInverter diff --git a/packages/control/chargepoint/chargepoint_data.py b/packages/control/chargepoint/chargepoint_data.py index cb3362968e..0f41753cfb 100644 --- a/packages/control/chargepoint/chargepoint_data.py +++ b/packages/control/chargepoint/chargepoint_data.py @@ -178,7 +178,7 @@ class Set: @dataclass class Config: configuration: Dict = field(default_factory=empty_dict_factory) - ev: int = 0 + _ev: int = 0 name: str = "neuer Ladepunkt" color: str = DEFAULT_COLORS.CHARGEPOINT.value type: Optional[str] = None diff --git a/packages/control/data.py b/packages/control/data.py index 1d7c779d01..298ced12f5 100644 --- a/packages/control/data.py +++ b/packages/control/data.py @@ -472,7 +472,6 @@ def __init__(self, event_module_update_completed): self.event_module_update_completed = event_module_update_completed def __enter__(self): - global data try: timeout = data.general_data.data.control_interval/2 except KeyError: diff --git a/packages/helpermodules/logger.py b/packages/helpermodules/logger.py index 73d4a24d05..cdffc44691 100644 --- a/packages/helpermodules/logger.py +++ b/packages/helpermodules/logger.py @@ -156,7 +156,6 @@ def clear(self): def clear_in_memory_log_handler(logger_name: str = None) -> None: - global in_memory_log_handlers if logger_name is None: # Clear all in-memory log handlers for handler in in_memory_log_handlers.values(): @@ -168,8 +167,6 @@ def clear_in_memory_log_handler(logger_name: str = None) -> None: def write_logs_to_file(logger_name: str = None) -> None: - global in_memory_log_handlers - def rotate_logs(base_path: str, name: str): # Rotate the log files for i in range(NUMBER_OF_LOGFILES-1, 0, -1): diff --git a/packages/modules/devices/algodue/algodue/device.py b/packages/modules/devices/algodue/algodue/device.py index e1f3ce1a6f..66e72ff785 100644 --- a/packages/modules/devices/algodue/algodue/device.py +++ b/packages/modules/devices/algodue/algodue/device.py @@ -16,17 +16,14 @@ def create_device(device_config: Algodue): client = None def create_counter_component(component_config: AlgodueCounterSetup): - nonlocal client return counter.AlgodueCounter(component_config=component_config, device_id=device_config.id, tcp_client=client, modbus_id=device_config.configuration.modbus_id) def create_inverter_component(component_config: AlgodueInverterSetup): - nonlocal client return inverter.AlgodueInverter(component_config=component_config, device_id=device_config.id, tcp_client=client, modbus_id=device_config.configuration.modbus_id) def create_bat_component(component_config: AlgodueBatSetup): - nonlocal client return bat.AlgodueBat(component_config=component_config, device_id=device_config.id, tcp_client=client, modbus_id=device_config.configuration.modbus_id) diff --git a/packages/modules/devices/alpha_ess/alpha_ess/device.py b/packages/modules/devices/alpha_ess/alpha_ess/device.py index 9983e11da0..ec3b69a825 100644 --- a/packages/modules/devices/alpha_ess/alpha_ess/device.py +++ b/packages/modules/devices/alpha_ess/alpha_ess/device.py @@ -24,21 +24,18 @@ def create_device(device_config: AlphaEss): client = None def create_bat_component(component_config: AlphaEssBatSetup): - nonlocal client return bat.AlphaEssBat(component_config, device_id=device_config.id, tcp_client=client, modbus_id=device_config.configuration.modbus_id) def create_counter_component(component_config: AlphaEssCounterSetup): - nonlocal client return counter.AlphaEssCounter(component_config, tcp_client=client, device_config=device_config.configuration, modbus_id=device_config.configuration.modbus_id) def create_inverter_component(component_config: AlphaEssInverterSetup): - nonlocal client return inverter.AlphaEssInverter(component_config=component_config, device_id=device_config.id, tcp_client=client, @@ -46,7 +43,6 @@ def create_inverter_component(component_config: AlphaEssInverterSetup): modbus_id=device_config.configuration.modbus_id) def update_components(components: Iterable[Union[alpha_ess_component_classes]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/ampere/ampere/device.py b/packages/modules/devices/ampere/ampere/device.py index 42310bc708..703f9c1fe0 100644 --- a/packages/modules/devices/ampere/ampere/device.py +++ b/packages/modules/devices/ampere/ampere/device.py @@ -18,21 +18,18 @@ def create_device(device_config: Ampere): client = None def create_bat_component(component_config: AmpereBatSetup): - nonlocal client return AmpereBat(component_config=component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def create_counter_component(component_config: AmpereCounterSetup): - nonlocal client return AmpereCounter(component_config=component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def create_inverter_component(component_config: AmpereInverterSetup): - nonlocal client return AmpereInverter(component_config=component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, diff --git a/packages/modules/devices/anker/anker_solix/device.py b/packages/modules/devices/anker/anker_solix/device.py index 5000adee4f..f12f5c1bdb 100644 --- a/packages/modules/devices/anker/anker_solix/device.py +++ b/packages/modules/devices/anker/anker_solix/device.py @@ -18,19 +18,15 @@ def create_device(device_config: Anker): client = None def create_bat_component(component_config: AnkerBatSetup): - nonlocal client return AnkerBat(component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: AnkerCounterSetup): - nonlocal client return AnkerCounter(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: AnkerInverterSetup): - nonlocal client return AnkerInverter(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[AnkerBat, AnkerCounter, AnkerInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/azzurro_zcs/azzurro_zcs/device.py b/packages/modules/devices/azzurro_zcs/azzurro_zcs/device.py index 126d40f774..28e17272fe 100644 --- a/packages/modules/devices/azzurro_zcs/azzurro_zcs/device.py +++ b/packages/modules/devices/azzurro_zcs/azzurro_zcs/device.py @@ -18,23 +18,19 @@ def create_device(device_config: ZCS): client = None def create_bat_component(component_config: ZCSBatSetup): - nonlocal client return ZCSBat(component_config=component_config, modbus_id=device_config.configuration.modbus_id, client=client) def create_counter_component(component_config: ZCSCounterSetup): - nonlocal client return ZCSCounter(component_config=component_config, modbus_id=device_config.configuration.modbus_id, client=client) def create_inverter_component(component_config: ZCSInverterSetup): - nonlocal client return ZCSInverter(component_config=component_config, modbus_id=device_config.configuration.modbus_id, client=client) def update_components(components: Iterable[Union[ZCSBat, ZCSCounter, ZCSInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/azzurro_zcs/azzurro_zcs_3p/device.py b/packages/modules/devices/azzurro_zcs/azzurro_zcs_3p/device.py index a276877b47..e3c02e2088 100644 --- a/packages/modules/devices/azzurro_zcs/azzurro_zcs_3p/device.py +++ b/packages/modules/devices/azzurro_zcs/azzurro_zcs_3p/device.py @@ -16,13 +16,11 @@ def create_device(device_config: ZCS3P): client = None def create_pv_inverter_component(component_config: ZCSPvInverterSetup): - nonlocal client return ZCSPvInverter(component_config=component_config, modbus_id=device_config.configuration.modbus_id, client=client) def update_components(components: Iterable[ZCSPvInverter]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/carlo_gavazzi/carlo_gavazzi/device.py b/packages/modules/devices/carlo_gavazzi/carlo_gavazzi/device.py index 341b49772f..5ef78fbd24 100644 --- a/packages/modules/devices/carlo_gavazzi/carlo_gavazzi/device.py +++ b/packages/modules/devices/carlo_gavazzi/carlo_gavazzi/device.py @@ -16,12 +16,10 @@ def create_device(device_config: CarloGavazzi): client = None def create_counter_component(component_config: CarloGavazziCounterSetup): - nonlocal client return counter.CarloGavazziCounter(component_config=component_config, device_id=device_config.id, tcp_client=client, modbus_id=device_config.configuration.modbus_id) def update_components(components: Iterable[counter.CarloGavazziCounter]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/chint/chint/device.py b/packages/modules/devices/chint/chint/device.py index ff7b982add..31545a56d4 100644 --- a/packages/modules/devices/chint/chint/device.py +++ b/packages/modules/devices/chint/chint/device.py @@ -16,7 +16,6 @@ def create_device(device_config: CHINT): client = None def create_counter_component(component_config: CHINTCounterSetup): - nonlocal client return CHINTCounter(component_config=component_config, client=client) def update_components(components: Iterable[Union[CHINTCounter]]): diff --git a/packages/modules/devices/deye/deye/device.py b/packages/modules/devices/deye/deye/device.py index 486e6fe217..feba6592da 100644 --- a/packages/modules/devices/deye/deye/device.py +++ b/packages/modules/devices/deye/deye/device.py @@ -20,19 +20,15 @@ def create_device(device_config: Deye): client = None def create_bat_component(component_config: DeyeBatSetup): - nonlocal client return DeyeBat(component_config=component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: DeyeCounterSetup): - nonlocal client return DeyeCounter(component_config=component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: DeyeInverterSetup): - nonlocal client return DeyeInverter(component_config=component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[DeyeBat, DeyeCounter, DeyeInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/deye/deye_solarman/device.py b/packages/modules/devices/deye/deye_solarman/device.py index b5b9c533ad..bfb8250653 100644 --- a/packages/modules/devices/deye/deye_solarman/device.py +++ b/packages/modules/devices/deye/deye_solarman/device.py @@ -19,19 +19,15 @@ def create_device(device_config: DeyeSolarman): client = None def create_bat_component(component_config: DeyeSolarmanBatSetup): - nonlocal client return DeyeSolarmanBat(component_config=component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: DeyeSolarmanCounterSetup): - nonlocal client return DeyeSolarmanCounter(component_config=component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: DeyeSolarmanInverterSetup): - nonlocal client return DeyeSolarmanInverter(component_config=component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[DeyeSolarmanBat, DeyeSolarmanCounter, DeyeSolarmanInverter]]): - nonlocal client for component in components: with SingleComponentUpdateContext(component.fault_state): component.update() diff --git a/packages/modules/devices/e3dc/e3dc/device.py b/packages/modules/devices/e3dc/e3dc/device.py index 1e1992e658..cc56477ed9 100644 --- a/packages/modules/devices/e3dc/e3dc/device.py +++ b/packages/modules/devices/e3dc/e3dc/device.py @@ -28,28 +28,24 @@ def create_device(device_config: E3dc) -> ConfigurableDevice: client = None def create_bat_component(component_config: E3dcBatSetup) -> E3dcBat: - nonlocal client return E3dcBat(component_config=component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def create_counter_component(component_config: E3dcCounterSetup) -> E3dcCounter: - nonlocal client return E3dcCounter(component_config=component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def create_inverter_component(component_config: E3dcInverterSetup) -> E3dcInverter: - nonlocal client return E3dcInverter(component_config=component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def create_external_inverter_component(component_config: E3dcExternalInverterSetup) -> E3dcExternalInverter: - nonlocal client return E3dcExternalInverter(component_config=component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, @@ -57,7 +53,6 @@ def create_external_inverter_component(component_config: E3dcExternalInverterSet def update_components(components: Iterable[Union[E3dcBat, E3dcCounter, E3dcInverter, E3dcExternalInverter]]) -> None: - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/elgris/elgris/device.py b/packages/modules/devices/elgris/elgris/device.py index 2c8a93c3cc..9046bf3044 100644 --- a/packages/modules/devices/elgris/elgris/device.py +++ b/packages/modules/devices/elgris/elgris/device.py @@ -17,17 +17,14 @@ def create_device(device_config: Elgris): client = None def create_bat_component(component_config: ElgrisBatSetup): - nonlocal client return bat.ElgrisBat(component_config=component_config, tcp_client=client, modbus_id=device_config.configuration.modbus_id) def create_counter_component(component_config: ElgrisCounterSetup): - nonlocal client return counter.ElgrisCounter(component_config=component_config, tcp_client=client, modbus_id=device_config.configuration.modbus_id) def create_inverter_component(component_config: ElgrisInverterSetup): - nonlocal client return inverter.ElgrisInverter(component_config=component_config, tcp_client=client, modbus_id=device_config.configuration.modbus_id) diff --git a/packages/modules/devices/fems/fems/device.py b/packages/modules/devices/fems/fems/device.py index 9e1781ee71..a5ac9c9c46 100644 --- a/packages/modules/devices/fems/fems/device.py +++ b/packages/modules/devices/fems/fems/device.py @@ -16,15 +16,12 @@ def create_device(device_config: Fems): session = None def create_bat_component(component_config: FemsBatSetup): - nonlocal session return bat.FemsBat(component_config, ip_address=device_config.configuration.ip_address, session=session) def create_counter_component(component_config: FemsCounterSetup): - nonlocal session return counter.FemsCounter(component_config, ip_address=device_config.configuration.ip_address, session=session) def create_inverter_component(component_config: FemsInverterSetup): - nonlocal session return inverter.FemsInverter(component_config, ip_address=device_config.configuration.ip_address, session=session) diff --git a/packages/modules/devices/fox_ess/fox_ess/device.py b/packages/modules/devices/fox_ess/fox_ess/device.py index 8505073342..17b02d70eb 100644 --- a/packages/modules/devices/fox_ess/fox_ess/device.py +++ b/packages/modules/devices/fox_ess/fox_ess/device.py @@ -18,19 +18,15 @@ def create_device(device_config: FoxEss): client = None def create_bat_component(component_config: FoxEssBatSetup): - nonlocal client return FoxEssBat(component_config=component_config, client=client) def create_counter_component(component_config: FoxEssCounterSetup): - nonlocal client return FoxEssCounter(component_config=component_config, client=client) def create_inverter_component(component_config: FoxEssInverterSetup): - nonlocal client return FoxEssInverter(component_config=component_config, client=client) def update_components(components: Iterable[Union[FoxEssBat, FoxEssCounter, FoxEssInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/good_we/good_we/device.py b/packages/modules/devices/good_we/good_we/device.py index bcfbcc65ad..57365ce35f 100644 --- a/packages/modules/devices/good_we/good_we/device.py +++ b/packages/modules/devices/good_we/good_we/device.py @@ -21,7 +21,6 @@ def create_device(device_config: GoodWe): client = None def create_bat_component(component_config: GoodWeBatSetup): - nonlocal client return bat.GoodWeBat(component_config=component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, @@ -30,7 +29,6 @@ def create_bat_component(component_config: GoodWeBatSetup): client=client) def create_counter_component(component_config: GoodWeCounterSetup): - nonlocal client return counter.GoodWeCounter(component_config=component_config, modbus_id=device_config.configuration.modbus_id, version=GoodWeVersion(device_config.configuration.version), @@ -39,7 +37,6 @@ def create_counter_component(component_config: GoodWeCounterSetup): device_id=device_config.id) def create_inverter_component(component_config: GoodWeInverterSetup): - nonlocal client return inverter.GoodWeInverter(component_config=component_config, modbus_id=device_config.configuration.modbus_id, version=GoodWeVersion(device_config.configuration.version), @@ -47,7 +44,6 @@ def create_inverter_component(component_config: GoodWeInverterSetup): client=client) def update_components(components: Iterable[good_we_component_classes]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/growatt/growatt/device.py b/packages/modules/devices/growatt/growatt/device.py index cc4764173a..c6f95a2ae5 100644 --- a/packages/modules/devices/growatt/growatt/device.py +++ b/packages/modules/devices/growatt/growatt/device.py @@ -21,28 +21,24 @@ def create_device(device_config: Growatt): client = None def create_bat_component(component_config: GrowattBatSetup): - nonlocal client return GrowattBat(component_config=component_config, modbus_id=device_config.configuration.modbus_id, version=GrowattVersion(device_config.configuration.version), client=client) def create_counter_component(component_config: GrowattCounterSetup): - nonlocal client return GrowattCounter(component_config=component_config, modbus_id=device_config.configuration.modbus_id, version=GrowattVersion(device_config.configuration.version), client=client) def create_inverter_component(component_config: GrowattInverterSetup): - nonlocal client return GrowattInverter(component_config=component_config, modbus_id=device_config.configuration.modbus_id, version=GrowattVersion(device_config.configuration.version), client=client) def update_components(components: Iterable[Union[GrowattBat, GrowattCounter, GrowattInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/huawei/huawei/device.py b/packages/modules/devices/huawei/huawei/device.py index 500aa524a4..f9924eece5 100644 --- a/packages/modules/devices/huawei/huawei/device.py +++ b/packages/modules/devices/huawei/huawei/device.py @@ -21,7 +21,6 @@ def create_device(device_config: Huawei): client = None def create_bat_component(component_config: HuaweiBatSetup): - nonlocal client return HuaweiBat(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, @@ -29,7 +28,6 @@ def create_bat_component(component_config: HuaweiBatSetup): client=client) def create_counter_component(component_config: HuaweiCounterSetup): - nonlocal client return HuaweiCounter(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, @@ -37,7 +35,6 @@ def create_counter_component(component_config: HuaweiCounterSetup): client=client) def create_inverter_component(component_config: HuaweiInverterSetup): - nonlocal client return HuaweiInverter(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, @@ -45,7 +42,6 @@ def create_inverter_component(component_config: HuaweiInverterSetup): client=client) def update_components(components: Iterable[Union[HuaweiBat, HuaweiCounter, HuaweiInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/huawei/huawei_emma/device.py b/packages/modules/devices/huawei/huawei_emma/device.py index d31699e6db..657b285650 100644 --- a/packages/modules/devices/huawei/huawei_emma/device.py +++ b/packages/modules/devices/huawei/huawei_emma/device.py @@ -21,28 +21,24 @@ def create_device(device_config: Huawei_Emma): client = None def create_bat_component(component_config: Huawei_EmmaBatSetup): - nonlocal client return Huawei_EmmaBat(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def create_counter_component(component_config: Huawei_EmmaCounterSetup): - nonlocal client return Huawei_EmmaCounter(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def create_inverter_component(component_config: Huawei_EmmaInverterSetup): - nonlocal client return Huawei_EmmaInverter(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def update_components(components: Iterable[Union[Huawei_EmmaBat, Huawei_EmmaCounter, Huawei_EmmaInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/huawei/huawei_smartlogger/device.py b/packages/modules/devices/huawei/huawei_smartlogger/device.py index 92ad36aff2..344146abb7 100644 --- a/packages/modules/devices/huawei/huawei_smartlogger/device.py +++ b/packages/modules/devices/huawei/huawei_smartlogger/device.py @@ -26,19 +26,15 @@ def create_device(device_config: Huawei_Smartlogger): client = None def create_bat_component(component_config: Huawei_SmartloggerBatSetup): - nonlocal client return bat.Huawei_SmartloggerBat(component_config, device_id=device_config.id, tcp_client=client) def create_counter_component(component_config: Huawei_SmartloggerCounterSetup): - nonlocal client return counter.Huawei_SmartloggerCounter(component_config, device_id=device_config.id, tcp_client=client) def create_inverter_component(component_config: Huawei_SmartloggerInverterSetup): - nonlocal client return inverter.Huawei_SmartloggerInverter(component_config, device_id=device_config.id, tcp_client=client) def update_components(components: Iterable[huawei_smartlogger_component_classes]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/idm/idm/device.py b/packages/modules/devices/idm/idm/device.py index c7c2983201..29fd755822 100644 --- a/packages/modules/devices/idm/idm/device.py +++ b/packages/modules/devices/idm/idm/device.py @@ -16,7 +16,6 @@ def create_device(device_config: IDM): client = None def create_counter_component(component_config: IDMCounterSetup): - nonlocal client return IDMCounter(component_config, device_id=device_config.id, client=client, diff --git a/packages/modules/devices/janitza/janitza/device.py b/packages/modules/devices/janitza/janitza/device.py index 0a0cda0501..ea7c889b88 100644 --- a/packages/modules/devices/janitza/janitza/device.py +++ b/packages/modules/devices/janitza/janitza/device.py @@ -16,23 +16,19 @@ def create_device(device_config: Janitza): client = None def create_counter_component(component_config: JanitzaCounterSetup): - nonlocal client return counter.JanitzaCounter(component_config, device_id=device_config.id, tcp_client=client, modbus_id=device_config.configuration.modbus_id) def create_inverter_component(component_config: JanitzaInverterSetup): - nonlocal client return inverter.JanitzaInverter(component_config, device_id=device_config.id, tcp_client=client, modbus_id=device_config.configuration.modbus_id) def create_bat_component(component_config: JanitzaBatSetup): - nonlocal client return bat.JanitzaBat(component_config, device_id=device_config.id, tcp_client=client, modbus_id=device_config.configuration.modbus_id) def update_components(components: Iterable[Union[counter.JanitzaCounter, inverter.JanitzaInverter, bat.JanitzaBat]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/kaco/kaco_tx/device.py b/packages/modules/devices/kaco/kaco_tx/device.py index 60e917b3b9..7acabc7932 100644 --- a/packages/modules/devices/kaco/kaco_tx/device.py +++ b/packages/modules/devices/kaco/kaco_tx/device.py @@ -18,11 +18,9 @@ def create_device(device_config: Kaco): client = None def create_inverter_component(component_config: KacoInverterSetup): - nonlocal client return KacoInverter(component_config, client=client) def update_components(components: Iterable[KacoInverter]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/kostal/kostal_piko_ci/device.py b/packages/modules/devices/kostal/kostal_piko_ci/device.py index 85e57d2a1c..ada894ba05 100644 --- a/packages/modules/devices/kostal/kostal_piko_ci/device.py +++ b/packages/modules/devices/kostal/kostal_piko_ci/device.py @@ -18,15 +18,12 @@ def create_device(device_config: KostalPikoCi): client = None def create_counter_component(component_config: KostalPikoCiCounterSetup): - nonlocal client return KostalPikoCiCounter(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: KostalPikoCiInverterSetup): - nonlocal client return KostalPikoCiInverter(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[KostalPikoCiCounter, KostalPikoCiInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/kostal/kostal_plenticore/device.py b/packages/modules/devices/kostal/kostal_plenticore/device.py index e911c90a4d..09f8d1d23e 100644 --- a/packages/modules/devices/kostal/kostal_plenticore/device.py +++ b/packages/modules/devices/kostal/kostal_plenticore/device.py @@ -20,7 +20,6 @@ def create_device(device_config: KostalPlenticore): endianess = None def create_bat_component(component_config: KostalPlenticoreBatSetup): - nonlocal client return KostalPlenticoreBat(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, @@ -28,7 +27,6 @@ def create_bat_component(component_config: KostalPlenticoreBatSetup): client=client) def create_counter_component(component_config: KostalPlenticoreCounterSetup): - nonlocal client return KostalPlenticoreCounter(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, @@ -36,7 +34,6 @@ def create_counter_component(component_config: KostalPlenticoreCounterSetup): client=client) def create_inverter_component(component_config: KostalPlenticoreInverterSetup): - nonlocal client return KostalPlenticoreInverter(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, @@ -45,7 +42,6 @@ def create_inverter_component(component_config: KostalPlenticoreInverterSetup): def update_components( components: Iterable[Union[KostalPlenticoreBat, KostalPlenticoreCounter, KostalPlenticoreInverter]]): - nonlocal client with client: for component in components: component.update() diff --git a/packages/modules/devices/kostal/kostal_sem/device.py b/packages/modules/devices/kostal/kostal_sem/device.py index 75416056f4..72f770f684 100644 --- a/packages/modules/devices/kostal/kostal_sem/device.py +++ b/packages/modules/devices/kostal/kostal_sem/device.py @@ -9,7 +9,6 @@ def create_device(device_config: KostalSem): client = None def create_counter_component(component_config: KostalSemCounterSetup): - nonlocal client return KostalSemCounter(component_config, client=client, modbus_id=device_config.configuration.modbus_id) def initializer(): diff --git a/packages/modules/devices/marstek/venus_c_e/device.py b/packages/modules/devices/marstek/venus_c_e/device.py index 6b402bad0e..b6641d065e 100644 --- a/packages/modules/devices/marstek/venus_c_e/device.py +++ b/packages/modules/devices/marstek/venus_c_e/device.py @@ -16,7 +16,6 @@ def create_device(device_config: VenusCE): client = None def create_bat_component(component_config: VenusCEBatSetup): - nonlocal client return VenusCEBat(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[VenusCEBat]): diff --git a/packages/modules/devices/mtec/mtec/device.py b/packages/modules/devices/mtec/mtec/device.py index 47581ff939..735ff14484 100644 --- a/packages/modules/devices/mtec/mtec/device.py +++ b/packages/modules/devices/mtec/mtec/device.py @@ -18,19 +18,15 @@ def create_device(device_config: MTec): client = None def create_bat_component(component_config: MTecBatSetup): - nonlocal client return MTecBat(component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: MTecCounterSetup): - nonlocal client return MTecCounter(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: MTecInverterSetup): - nonlocal client return MTecInverter(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[MTecBat, MTecCounter, MTecInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/nibe/nibe/device.py b/packages/modules/devices/nibe/nibe/device.py index 6a03378060..22c32ddef6 100644 --- a/packages/modules/devices/nibe/nibe/device.py +++ b/packages/modules/devices/nibe/nibe/device.py @@ -16,7 +16,6 @@ def create_device(device_config: Nibe): client = None def create_counter_component(component_config: NibeCounterSetup): - nonlocal client return NibeCounter(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[NibeCounter]): diff --git a/packages/modules/devices/openwb/openwb_bat_kit/device.py b/packages/modules/devices/openwb/openwb_bat_kit/device.py index cebed73e88..a96e875e57 100644 --- a/packages/modules/devices/openwb/openwb_bat_kit/device.py +++ b/packages/modules/devices/openwb/openwb_bat_kit/device.py @@ -17,11 +17,9 @@ def create_device(device_config: BatKitSetup): client = None def create_bat_component(component_config: BatKitBatSetup): - nonlocal client return BatKit(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[BatKit]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/openwb/openwb_evu_kit/device.py b/packages/modules/devices/openwb/openwb_evu_kit/device.py index f975a0c801..1ad536188b 100644 --- a/packages/modules/devices/openwb/openwb_evu_kit/device.py +++ b/packages/modules/devices/openwb/openwb_evu_kit/device.py @@ -20,19 +20,15 @@ def create_device(device_config: EvuKitSetup): client = None def create_bat_component(component_config: EvuKitBatSetup): - nonlocal client return BatKit(component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: EvuKitCounterSetup): - nonlocal client return EvuKit(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: EvuKitInverterSetup): - nonlocal client return PvKit(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[BatKit, EvuKit, PvKit]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/openwb/openwb_flex/device.py b/packages/modules/devices/openwb/openwb_flex/device.py index 350a6dd0df..9e74cbdda6 100644 --- a/packages/modules/devices/openwb/openwb_flex/device.py +++ b/packages/modules/devices/openwb/openwb_flex/device.py @@ -25,19 +25,15 @@ def create_device(device_config: Flex): client = None def create_bat_component(component_config: BatKitFlexSetup): - nonlocal client return BatKitFlex(component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: EvuKitFlexSetup): - nonlocal client return EvuKitFlex(component_config, device_id=device_config.id, client=client) def create_consumption_counter_component(component_config: ConsumptionCounterFlexSetup): - nonlocal client return ConsumptionCounterFlex(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: PvKitFlexSetup): - nonlocal client return PvKitFlex(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[BatKitFlex, ConsumptionCounterFlex, EvuKitFlex, PvKitFlex]]): diff --git a/packages/modules/devices/openwb/openwb_pv_kit/device.py b/packages/modules/devices/openwb/openwb_pv_kit/device.py index 6562467134..cde7c8cb5d 100644 --- a/packages/modules/devices/openwb/openwb_pv_kit/device.py +++ b/packages/modules/devices/openwb/openwb_pv_kit/device.py @@ -17,11 +17,9 @@ def create_device(device_config: PvKitSetup): client = None def create_inverter_component(component_config: PvKitInverterSetup): - nonlocal client return inverter.PvKit(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[inverter.PvKit]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/orno/orno/device.py b/packages/modules/devices/orno/orno/device.py index 169bc971fd..00028d678f 100644 --- a/packages/modules/devices/orno/orno/device.py +++ b/packages/modules/devices/orno/orno/device.py @@ -17,7 +17,6 @@ def create_device(device_config: Orno): client = None def create_counter_component(component_config: OrnoCounterSetup): - nonlocal client return OrnoCounter(component_config, client=client) def update_components(components: Iterable[OrnoCounter]): diff --git a/packages/modules/devices/powerdog/powerdog/device.py b/packages/modules/devices/powerdog/powerdog/device.py index 901b8f0d2e..921df310b7 100644 --- a/packages/modules/devices/powerdog/powerdog/device.py +++ b/packages/modules/devices/powerdog/powerdog/device.py @@ -16,21 +16,18 @@ def create_device(device_config: Powerdog): client = None def create_counter_component(component_config: PowerdogCounterSetup): - nonlocal client return PowerdogCounter(component_config, device_id=device_config.id, client=client, modbus_id=device_config.configuration.modbus_id) def create_inverter_component(component_config: PowerdogInverterSetup): - nonlocal client return PowerdogInverter(component_config, device_id=device_config.id, client=client, modbus_id=device_config.configuration.modbus_id) def update_components(components: Iterable[Union[PowerdogCounter, PowerdogInverter]]): - nonlocal client with client: if len(components) == 1: for component in components: diff --git a/packages/modules/devices/qcells/qcells/device.py b/packages/modules/devices/qcells/qcells/device.py index a5c9b8eb18..c6827b1180 100644 --- a/packages/modules/devices/qcells/qcells/device.py +++ b/packages/modules/devices/qcells/qcells/device.py @@ -18,19 +18,15 @@ def create_device(device_config: QCells): client = None def create_bat_component(component_config: QCellsBatSetup): - nonlocal client return QCellsBat(component_config, modbus_id=device_config.configuration.modbus_id, client=client) def create_counter_component(component_config: QCellsCounterSetup): - nonlocal client return QCellsCounter(component_config, modbus_id=device_config.configuration.modbus_id, client=client) def create_inverter_component(component_config: QCellsInverterSetup): - nonlocal client return QCellsInverter(component_config, modbus_id=device_config.configuration.modbus_id, client=client) def update_components(components: Iterable[Union[QCellsBat, QCellsCounter, QCellsInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/saxpower/saxpower/device.py b/packages/modules/devices/saxpower/saxpower/device.py index e5cf479f67..55e3ff504e 100644 --- a/packages/modules/devices/saxpower/saxpower/device.py +++ b/packages/modules/devices/saxpower/saxpower/device.py @@ -17,7 +17,6 @@ def create_device(device_config: Saxpower): client = None def create_bat_component(component_config: SaxpowerBatSetup): - nonlocal client return SaxpowerBat(component_config, device_id=device_config.id, client=client, @@ -30,7 +29,6 @@ def create_counter_component(component_config: SaxpowerCounterSetup): modbus_id=device_config.configuration.modbus_id) def update_components(components: Iterable[Union[SaxpowerBat, SaxpowerCounter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/shelly/shelly/device.py b/packages/modules/devices/shelly/shelly/device.py index 303f5b6818..de3cb54fd0 100644 --- a/packages/modules/devices/shelly/shelly/device.py +++ b/packages/modules/devices/shelly/shelly/device.py @@ -17,7 +17,6 @@ def create_device(device_config: Shelly) -> ConfigurableDevice: generation = 1 def create_counter_component(component_config: ShellyCounterSetup) -> ShellyCounter: - nonlocal generation return ShellyCounter(component_config, device_id=device_config.id, ip_address=device_config.configuration.ip_address, @@ -26,7 +25,6 @@ def create_counter_component(component_config: ShellyCounterSetup) -> ShellyCoun generation=generation) def create_inverter_component(component_config: ShellyInverterSetup) -> ShellyInverter: - nonlocal generation return ShellyInverter(component_config, device_id=device_config.id, ip_address=device_config.configuration.ip_address, @@ -35,7 +33,6 @@ def create_inverter_component(component_config: ShellyInverterSetup) -> ShellyIn generation=generation) def create_bat_component(component_config: ShellyBatSetup) -> ShellyBat: - nonlocal generation return ShellyBat(component_config, device_id=device_config.id, ip_address=device_config.configuration.ip_address, diff --git a/packages/modules/devices/siemens/siemens/device.py b/packages/modules/devices/siemens/siemens/device.py index 667af3607e..c998e07f21 100644 --- a/packages/modules/devices/siemens/siemens/device.py +++ b/packages/modules/devices/siemens/siemens/device.py @@ -21,28 +21,24 @@ def create_device(device_config: Siemens): client = None def create_bat_component(component_config: SiemensBatSetup): - nonlocal client return SiemensBat(component_config, device_id=device_config.id, client=client, modbus_id=device_config.configuration.modbus_id) def create_counter_component(component_config: SiemensCounterSetup): - nonlocal client return SiemensCounter(component_config, device_id=device_config.id, client=client, modbus_id=device_config.configuration.modbus_id) def create_inverter_component(component_config: SiemensInverterSetup): - nonlocal client return SiemensInverter(component_config, device_id=device_config.id, client=client, modbus_id=device_config.configuration.modbus_id) def update_components(components: Iterable[siemens_component_classes]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/siemens/siemens_sentron/device.py b/packages/modules/devices/siemens/siemens_sentron/device.py index 354ccbe274..24dde106d6 100644 --- a/packages/modules/devices/siemens/siemens_sentron/device.py +++ b/packages/modules/devices/siemens/siemens_sentron/device.py @@ -17,23 +17,19 @@ def create_device(device_config: SiemensSentron): client = None def create_counter_component(component_config: SiemensSentronCounterSetup): - nonlocal client return counter.SiemensSentronCounter(component_config, client=client, modbus_id=device_config.configuration.modbus_id) def create_inverter_component(component_config: SiemensSentronInverterSetup): - nonlocal client return inverter.SiemensSentronInverter(component_config, client=client, modbus_id=device_config.configuration.modbus_id) def create_bat_component(component_config: SiemensSentronBatSetup): - nonlocal client return bat.SiemensSentronBat(component_config, client=client, modbus_id=device_config.configuration.modbus_id) def update_components(components: Iterable[Union[counter.SiemensSentronCounter, inverter.SiemensSentronInverter, bat.SiemensSentronBat]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/sigenergy/sigenergy/device.py b/packages/modules/devices/sigenergy/sigenergy/device.py index 36a8b043cc..3a5ffe3441 100644 --- a/packages/modules/devices/sigenergy/sigenergy/device.py +++ b/packages/modules/devices/sigenergy/sigenergy/device.py @@ -23,19 +23,15 @@ def create_device(device_config: Sigenergy): client = None def create_bat_component(component_config: SigenergyBatSetup): - nonlocal client return SigenergyBat(component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: SigenergyCounterSetup): - nonlocal client return SigenergyCounter(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: SigenergyInverterSetup): - nonlocal client return SigenergyInverter(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[SigenergyBat, SigenergyCounter, SigenergyInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/sma/sma_shm/speedwire_listener.py b/packages/modules/devices/sma/sma_shm/speedwire_listener.py index ff9ab86998..78fc0be695 100644 --- a/packages/modules/devices/sma/sma_shm/speedwire_listener.py +++ b/packages/modules/devices/sma/sma_shm/speedwire_listener.py @@ -8,7 +8,7 @@ class SpeedwireListener: def __init__(self, timeout_seconds: float): self.__timeout_seconds = timeout_seconds - self.__socket = None # type: Optional[socket.socket] + self.__socket: Optional[socket.socket] = None def __enter__(self) -> Iterator[dict]: ip_bind = "0.0.0.0" @@ -36,4 +36,5 @@ def generator() -> Iterator[dict]: return generator() def __exit__(self, exc_type, exc_val, exc_tb): - self.__socket.close() + if self.__socket: + self.__socket.close() diff --git a/packages/modules/devices/sma/sma_sunny_boy/device.py b/packages/modules/devices/sma/sma_sunny_boy/device.py index 0e47eef457..43d831fbad 100644 --- a/packages/modules/devices/sma/sma_sunny_boy/device.py +++ b/packages/modules/devices/sma/sma_sunny_boy/device.py @@ -26,19 +26,15 @@ def create_device(device_config: SmaSunnyBoy): client = None def create_bat_component(component_config: SmaSunnyBoyBatSetup): - nonlocal client return SunnyBoyBat(component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: SmaSunnyBoyCounterSetup): - nonlocal client return SmaSunnyBoyCounter(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: SmaSunnyBoyInverterSetup): - nonlocal client return SmaSunnyBoyInverter(component_config, client=client, device_id=device_config.id) def update_components(components: Iterable[sma_modbus_tcp_component_classes]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/sma/sma_sunny_island/device.py b/packages/modules/devices/sma/sma_sunny_island/device.py index 6629eadcfa..530360b0fe 100644 --- a/packages/modules/devices/sma/sma_sunny_island/device.py +++ b/packages/modules/devices/sma/sma_sunny_island/device.py @@ -16,11 +16,9 @@ def create_device(device_config: SmaSunnyIsland): client = None def create_bat_component(component_config: SmaSunnyIslandBatSetup): - nonlocal client return SunnyIslandBat(component_config, client=client) def update_components(components: Iterable[SunnyIslandBat]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/sofar/sofar/device.py b/packages/modules/devices/sofar/sofar/device.py index 8112ed1373..d3a36932b0 100644 --- a/packages/modules/devices/sofar/sofar/device.py +++ b/packages/modules/devices/sofar/sofar/device.py @@ -18,19 +18,15 @@ def create_device(device_config: Sofar): client = None def create_bat_component(component_config: SofarBatSetup): - nonlocal client return SofarBat(component_config, modbus_id=device_config.configuration.modbus_id, client=client) def create_counter_component(component_config: SofarCounterSetup): - nonlocal client return SofarCounter(component_config, modbus_id=device_config.configuration.modbus_id, client=client) def create_inverter_component(component_config: SofarInverterSetup): - nonlocal client return SofarInverter(component_config, modbus_id=device_config.configuration.modbus_id, client=client) def update_components(components: Iterable[Union[SofarBat, SofarCounter, SofarInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/solakon/solakon_one/device.py b/packages/modules/devices/solakon/solakon_one/device.py index fcc8c2ca57..3a92b5e420 100644 --- a/packages/modules/devices/solakon/solakon_one/device.py +++ b/packages/modules/devices/solakon/solakon_one/device.py @@ -17,15 +17,12 @@ def create_device(device_config: SolakonOne): client = None def create_bat_component(component_config: SolakonOneBatSetup): - nonlocal client return SolakonOneBat(component_config=component_config, client=client) def create_inverter_component(component_config: SolakonOneInverterSetup): - nonlocal client return SolakonOneInverter(component_config=component_config, client=client) def update_components(components: Iterable[Union[SolakonOneBat, SolakonOneInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/solaredge/solaredge/device.py b/packages/modules/devices/solaredge/solaredge/device.py index 6b4bb205e4..871875d418 100644 --- a/packages/modules/devices/solaredge/solaredge/device.py +++ b/packages/modules/devices/solaredge/solaredge/device.py @@ -23,23 +23,18 @@ def create_device(device_config: Solaredge): client = None def create_bat_component(component_config: SolaredgeBatSetup): - nonlocal client return SolaredgeBat(component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: SolaredgeCounterSetup): - nonlocal client, device return SolaredgeCounter(component_config, client=client, components=device.components) def create_inverter_component(component_config: SolaredgeInverterSetup): - nonlocal client return SolaredgeInverter(component_config, client=client, device_id=device_config.id) def create_external_inverter_component(component_config: SolaredgeExternalInverterSetup): - nonlocal client, device return SolaredgeExternalInverter(component_config, client=client, components=device.components) def update_components(components: Iterable[Union[SolaredgeBat, SolaredgeCounter, SolaredgeInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/solarmax/solarmax/device.py b/packages/modules/devices/solarmax/solarmax/device.py index 8ca5334d2f..3ce95f8239 100644 --- a/packages/modules/devices/solarmax/solarmax/device.py +++ b/packages/modules/devices/solarmax/solarmax/device.py @@ -23,24 +23,19 @@ def create_device(device_config: Solarmax): client = None def create_bat_component(component_config: SolarmaxBatSetup): - nonlocal client return SolarmaxBat(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: SolarmaxInverterSetup): - nonlocal client return SolarmaxInverter(component_config, device_id=device_config.id, client=client) def create_inverter_ms_component(component_config: SolarmaxMsInverterSetup): - nonlocal client return SolarmaxMsInverter(component_config, device_id=device_config.id, client=client) def create_counter_ms_component(component_config: SolarmaxMsCounterSetup): - nonlocal client return SolarmaxMsCounter(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[SolarmaxBat, SolarmaxInverter, SolarmaxMsCounter, SolarmaxMsInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/solax/solax/device.py b/packages/modules/devices/solax/solax/device.py index 09a0d76940..d7f0b0343c 100644 --- a/packages/modules/devices/solax/solax/device.py +++ b/packages/modules/devices/solax/solax/device.py @@ -27,7 +27,6 @@ def create_inverter_component(component_config: SolaxInverterSetup): return SolaxInverter(component_config, device_config=device_config, client=client) def update_components(components: Iterable[Union[SolaxBat, SolaxCounter, SolaxInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/solis/solis/device.py b/packages/modules/devices/solis/solis/device.py index 9f0feb97f6..eb3602539f 100644 --- a/packages/modules/devices/solis/solis/device.py +++ b/packages/modules/devices/solis/solis/device.py @@ -18,25 +18,21 @@ def create_device(device_config: Solis): client = None def create_bat_component(component_config: SolisBatSetup): - nonlocal client return SolisBat(component_config, client=client, device_id=device_config.id, version=device_config.configuration.version) def create_counter_component(component_config: SolisCounterSetup): - nonlocal client return SolisCounter(component_config, client=client, version=device_config.configuration.version) def create_inverter_component(component_config: SolisInverterSetup): - nonlocal client return SolisInverter(component_config, client=client, device_id=device_config.id, version=device_config.configuration.version) def update_components(components: Iterable[Union[SolisBat, SolisCounter, SolisInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/studer/studer/device.py b/packages/modules/devices/studer/studer/device.py index ae0d85fb4b..cb124036f9 100644 --- a/packages/modules/devices/studer/studer/device.py +++ b/packages/modules/devices/studer/studer/device.py @@ -17,15 +17,12 @@ def create_device(device_config: Studer): client = None def create_bat_component(component_config: StuderBatSetup): - nonlocal client return StuderBat(component_config, client=client) def create_inverter_component(component_config: StuderInverterSetup): - nonlocal client return StuderInverter(component_config, client=client) def update_components(components: Iterable[Union[StuderBat, StuderInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/sungrow/sungrow_ihm/device.py b/packages/modules/devices/sungrow/sungrow_ihm/device.py index 4619549b00..3ca1b21649 100644 --- a/packages/modules/devices/sungrow/sungrow_ihm/device.py +++ b/packages/modules/devices/sungrow/sungrow_ihm/device.py @@ -19,15 +19,12 @@ def create_device(device_config: SungrowIHM): client = None def create_bat_component(component_config: SungrowIHMBatSetup): - nonlocal client return SungrowIHMBat(component_config, device_config=device_config, client=client) def create_counter_component(component_config: SungrowIHMCounterSetup): - nonlocal client return SungrowIHMCounter(component_config, device_config=device_config, client=client) def create_inverter_component(component_config: SungrowIHMInverterSetup): - nonlocal client return SungrowIHMInverter(component_config, device_config=device_config, client=client) def update_components(components: Iterable[Union[SungrowIHMBat, SungrowIHMCounter, SungrowIHMInverter]]): diff --git a/packages/modules/devices/sungrow/sungrow_micro/device.py b/packages/modules/devices/sungrow/sungrow_micro/device.py index 27593e5f35..561ce5cd0c 100644 --- a/packages/modules/devices/sungrow/sungrow_micro/device.py +++ b/packages/modules/devices/sungrow/sungrow_micro/device.py @@ -16,7 +16,6 @@ def create_device(device_config: SungrowMicro): client = None def create_inverter_component(component_config: SungrowMicroInverterSetup): - nonlocal client return SungrowMicroInverter(component_config, device_config=device_config, client=client) def update_components(components: Iterable[Union[SungrowMicroInverter]]): diff --git a/packages/modules/devices/sungrow/sungrow_sg/device.py b/packages/modules/devices/sungrow/sungrow_sg/device.py index 07ea25873e..7965aa5386 100644 --- a/packages/modules/devices/sungrow/sungrow_sg/device.py +++ b/packages/modules/devices/sungrow/sungrow_sg/device.py @@ -17,11 +17,9 @@ def create_device(device_config: SungrowSG): client = None def create_counter_component(component_config: SungrowSGCounterSetup): - nonlocal client return SungrowSGCounter(component_config, device_config=device_config, client=client) def create_inverter_component(component_config: SungrowSGInverterSetup): - nonlocal client return SungrowSGInverter(component_config, device_config=device_config, client=client) def update_components(components: Iterable[Union[SungrowSGCounter, SungrowSGInverter]]): diff --git a/packages/modules/devices/sungrow/sungrow_sh/device.py b/packages/modules/devices/sungrow/sungrow_sh/device.py index 080686f2a4..1585e9b3c2 100644 --- a/packages/modules/devices/sungrow/sungrow_sh/device.py +++ b/packages/modules/devices/sungrow/sungrow_sh/device.py @@ -19,15 +19,12 @@ def create_device(device_config: SungrowSH): client = None def create_bat_component(component_config: SungrowSHBatSetup): - nonlocal client return SungrowSHBat(component_config, device_config=device_config, client=client) def create_counter_component(component_config: SungrowSHCounterSetup): - nonlocal client return SungrowSHCounter(component_config, device_config=device_config, client=client) def create_inverter_component(component_config: SungrowSHInverterSetup): - nonlocal client return SungrowSHInverter(component_config, device_config=device_config, client=client) def update_components(components: Iterable[Union[SungrowSHBat, SungrowSHCounter, SungrowSHInverter]]): diff --git a/packages/modules/devices/tesla/tesla/device.py b/packages/modules/devices/tesla/tesla/device.py index 58f0589f2d..3a219cc1fe 100644 --- a/packages/modules/devices/tesla/tesla/device.py +++ b/packages/modules/devices/tesla/tesla/device.py @@ -54,7 +54,6 @@ def create_inverter_component(component_config: TeslaInverterSetup): def update_components(components: Iterable[Union[TeslaBat, TeslaCounter, TeslaInverter]]): log.debug("Beginning update") - nonlocal http_client, session address = device_config.configuration.ip_address email = device_config.configuration.email password = device_config.configuration.password diff --git a/packages/modules/devices/thermia/thermia/device.py b/packages/modules/devices/thermia/thermia/device.py index 019d2966ab..b37f0c87c4 100644 --- a/packages/modules/devices/thermia/thermia/device.py +++ b/packages/modules/devices/thermia/thermia/device.py @@ -16,7 +16,6 @@ def create_device(device_config: Thermia): client = None def create_counter_component(component_config: ThermiaCounterSetup): - nonlocal client return ThermiaCounter(component_config, device_id=device_config.id, client=client, modbus_id=device_config.configuration.modbus_id) diff --git a/packages/modules/devices/upower/upower/device.py b/packages/modules/devices/upower/upower/device.py index 4637d1922d..0dc146a2e9 100644 --- a/packages/modules/devices/upower/upower/device.py +++ b/packages/modules/devices/upower/upower/device.py @@ -19,19 +19,16 @@ def create_device(device_config: UPower): client = None def create_bat_component(component_config: UPowerBatSetup): - nonlocal client return UPowerBat(component_config, UPowerVersion(device_config.configuration.version), device_config.configuration.modbus_id, client, device_config.id) def create_counter_component(component_config: UPowerCounterSetup): - nonlocal client return UPowerCounter(component_config, UPowerVersion(device_config.configuration.version), device_config.configuration.modbus_id, client, device_config.id) def create_inverter_component(component_config: UPowerInverterSetup): - nonlocal client return UPowerInverter(component_config, UPowerVersion(device_config.configuration.version), device_config.configuration.modbus_id, client) diff --git a/packages/modules/devices/varta/varta/device.py b/packages/modules/devices/varta/varta/device.py index 507348b95c..3718668db7 100644 --- a/packages/modules/devices/varta/varta/device.py +++ b/packages/modules/devices/varta/varta/device.py @@ -29,28 +29,24 @@ def create_bat_api_component(component_config: VartaBatApiSetup): ip_address=device_config.configuration.ip_address) def create_bat_modbus_component(component_config: VartaBatModbusSetup): - nonlocal client return VartaBatModbus(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def create_counter_component(component_config: VartaCounterSetup): - nonlocal client return VartaCounter(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def create_inverter_component(component_config: VartaInverterSetup): - nonlocal client return VartaInverter(component_config, device_id=device_config.id, modbus_id=device_config.configuration.modbus_id, client=client) def update_components(components: Iterable[Union[VartaBatApi, VartaBatModbus, VartaCounter, VartaInverter]]): - nonlocal client with client: for component in components: if isinstance(component, (VartaBatModbus, VartaCounter, VartaInverter)): diff --git a/packages/modules/devices/victron/victron/device.py b/packages/modules/devices/victron/victron/device.py index 5f346f400e..e229b0bf71 100644 --- a/packages/modules/devices/victron/victron/device.py +++ b/packages/modules/devices/victron/victron/device.py @@ -18,19 +18,15 @@ def create_device(device_config: Victron): client = None def create_bat_component(component_config: VictronBatSetup): - nonlocal client return VictronBat(component_config, device_id=device_config.id, client=client) def create_counter_component(component_config: VictronCounterSetup): - nonlocal client return VictronCounter(component_config, device_id=device_config.id, client=client) def create_inverter_component(component_config: VictronInverterSetup): - nonlocal client return VictronInverter(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[Union[VictronBat, VictronCounter, VictronInverter]]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/devices/victron/victron_3p75ct/device.py b/packages/modules/devices/victron/victron_3p75ct/device.py index ac98f9624a..166eaf497a 100644 --- a/packages/modules/devices/victron/victron_3p75ct/device.py +++ b/packages/modules/devices/victron/victron_3p75ct/device.py @@ -16,11 +16,9 @@ def create_device(device_config: Victron): client = None def create_counter_component(component_config: VictronCounterSetup): - nonlocal client return VictronCounter(component_config, device_id=device_config.id, client=client) def update_components(components: Iterable[VictronCounter]): - nonlocal client with client: for component in components: with SingleComponentUpdateContext(component.fault_state): diff --git a/packages/modules/io_devices/dimm_kit/api.py b/packages/modules/io_devices/dimm_kit/api.py index 76ed494b4d..a94883d812 100644 --- a/packages/modules/io_devices/dimm_kit/api.py +++ b/packages/modules/io_devices/dimm_kit/api.py @@ -23,7 +23,6 @@ def create_io(config: IoLan): def read(): nonlocal version - nonlocal client if version is False: try: parsed_answer = get_version_by_telnet(VALID_VERSIONS[0], config.configuration.host) @@ -60,7 +59,6 @@ def read(): ) def write(analog_output: Optional[Dict[str, int]], digital_output: Optional[Dict[str, bool]]) -> None: - nonlocal client for i, value in digital_output.items(): client.write_single_coil(DigitalOutputMapping[i].value, 1 if value is True else 0, unit=config.configuration.modbus_id) diff --git a/packages/modules/io_devices/eebus/api.py b/packages/modules/io_devices/eebus/api.py index 0034a35961..12b8a68b8d 100644 --- a/packages/modules/io_devices/eebus/api.py +++ b/packages/modules/io_devices/eebus/api.py @@ -98,8 +98,6 @@ def run(): name="eebus_binary")) def read(): - nonlocal broker - nonlocal received_topics nonlocal thread_exception if is_thread_alive("eebus_binary") is False: diff --git a/packages/modules/smarthome/mqtt/off.py b/packages/modules/smarthome/mqtt/off.py index edb8cc3953..c10c28f263 100644 --- a/packages/modules/smarthome/mqtt/off.py +++ b/packages/modules/smarthome/mqtt/off.py @@ -10,7 +10,7 @@ def on_connect(client, userdata, flags, rc) -> None: def on_message(client, userdata, msg) -> None: - global numberOfSupportedDevices + pass # No action needed for incoming messages in this script devicenumber = str(sys.argv[1]) diff --git a/packages/modules/smarthome/mqtt/on.py b/packages/modules/smarthome/mqtt/on.py index aabd8d2299..10dcc0b0c5 100644 --- a/packages/modules/smarthome/mqtt/on.py +++ b/packages/modules/smarthome/mqtt/on.py @@ -10,7 +10,7 @@ def on_connect(client, userdata, flags, rc) -> None: def on_message(client, userdata, msg) -> None: - global numberOfSupportedDevices + pass # No action needed for incoming messages in this script devicenumber = str(sys.argv[1]) diff --git a/packages/modules/smarthome/mqtt/watt.py b/packages/modules/smarthome/mqtt/watt.py index 304b000423..e11635424b 100644 --- a/packages/modules/smarthome/mqtt/watt.py +++ b/packages/modules/smarthome/mqtt/watt.py @@ -9,12 +9,10 @@ def on_connect(client, userdata, flags, rc) -> None: - global devicenumber client.subscribe("openWB/LegacySmartHome/Devices/"+str(devicenumber) + "/#", 2) def on_message(client, userdata, msg) -> None: - global numberOfSupportedDevices global aktpower global powerc global tempa diff --git a/packages/modules/vehicles/kia/api.py b/packages/modules/vehicles/kia/api.py index b8f48d7123..ebb73d8400 100644 --- a/packages/modules/vehicles/kia/api.py +++ b/packages/modules/vehicles/kia/api.py @@ -130,7 +130,6 @@ def getStamp(brand: str) -> str: def getHTTP(url: str = "", headers: str = "", cookies: str = "", timeout: int = 30, allow_redirects: bool = True) -> str: global last_cookies - global last_url try: response = requests.get(url, headers=headers, @@ -217,7 +216,6 @@ def deleteHTTP(url: str = "", headers: str = "", cookies: str = "", def postHTTP(url: str = "", data: Union[str, dict] = "", headers: str = "", cookies: str = "", timeout: int = 30, allow_redirects: bool = True) -> str: - global last_cookies global last_url try: @@ -452,8 +450,6 @@ def getDeviceId(brand: str) -> dict: def getAuthCode(username: str, password: str, brand: str, cookies: dict) -> str: - global last_cookies - log.info("Kia/Hyundai: Sending username/password") try: diff --git a/packages/smarthome/smartcommon.py b/packages/smarthome/smartcommon.py index 7b6d958a41..4b95036ee8 100644 --- a/packages/smarthome/smartcommon.py +++ b/packages/smarthome/smartcommon.py @@ -44,8 +44,6 @@ def on_connect(client: mqtt.Client, userdata: Any, flags: Dict, rc: int) -> None: - global mqttcg - global mqttsdevstat # mqttcg = 'openWB/config/get/SmartHome/' # client.subscribe("openWB/config/get/SmartHome/#", 2) client.subscribe(mqttcg + '#', 2) @@ -55,8 +53,6 @@ def on_connect(client: mqtt.Client, userdata: Any, flags: Dict, rc: int) -> None def logmq(topic: str, devicenumb: int, keyword: str, value: str) -> None: - global parammqtt - global ramdiskwrite # richtig topic single if (devicenumb < 1) or (devicenumb > numberOfSupportedDevices): pass @@ -112,7 +108,6 @@ def on_message(client: mqtt.Client, userdata: Any, msg: mqtt.MQTTMessage) -> Non def getdevicevalues(uberschuss: int, uberschussoffset: int, pvwatt: int, chargestatus: bool) -> None: - global mydevices totalwatt = 0 totalwattot = 0 totalminhaus = 0 @@ -204,7 +199,6 @@ def pub(client: mqtt.Client, key: str, value: str) -> None: def sendmq(mqtt_input: Dict[str, str]) -> None: - global mqtt_cache client = mqtt.Client("openWB-SmartHome-bulkpublisher-" + str(os.getpid())) client.connect("localhost", mqttport) for key, value in mqtt_input.items(): @@ -224,15 +218,11 @@ def sendmq(mqtt_input: Dict[str, str]) -> None: def conditions(speichersoc: int) -> None: - global mydevices for mydevice in mydevices: mydevice.conditions(speichersoc) def update_devices() -> None: - global parammqtt - global mydevices - global mqtt_cache client = mqtt.Client("openWB-SmartHome-bulkpublisher-" + str(os.getpid())) client.connect("localhost", mqttport) # statische daten einschaltgruppe @@ -341,7 +331,6 @@ def update_devices() -> None: def readmq() -> None: global parammqtt - global mydevices log.info("Config reRead start / Parameter check") if ramdiskwrite: with open(bp+'/ramdisk/smartparam.sh', 'w') as f: @@ -369,7 +358,6 @@ def readmq() -> None: def resetmaxeinschaltdauerfunc() -> None: global resetmaxeinschaltdauer - global mydevices mqtt_reset = {} hour = time.strftime("%H") if (int(hour) == 0): @@ -408,9 +396,6 @@ def resetmaxeinschaltdauerfunc() -> None: def loadregelvars(wattbezug: int, speicherleistung: int, speichersoc: int, pvwatt: int, chargestatus: bool) -> Tuple[int, int]: - global maxspeicher - global mydevices - global firststart uberschuss = wattbezug + speicherleistung uberschussoffset = wattbezug + speicherleistung - maxspeicher log.info("EVU Bezug(-)/Einspeisung(+): " + str(wattbezug) + diff --git a/simpleAPI/simpleAPI_mqtt.py b/simpleAPI/simpleAPI_mqtt.py index 2882fcfd9e..580c09dfc5 100755 --- a/simpleAPI/simpleAPI_mqtt.py +++ b/simpleAPI/simpleAPI_mqtt.py @@ -92,10 +92,10 @@ def _on_connect(self, client, userdata, flags, rc): """Callback for successful MQTT connection.""" if rc == 0: log.info(f"Connected to MQTT broker at {self.host}:{self.port}") - + # Publish API revision self._publish_revision() - + # Subscribe to specific openWB component topics client.subscribe("openWB/bat/#", qos=0) client.subscribe("openWB/pv/#", qos=0) @@ -280,7 +280,7 @@ def _transform_chargepoint_topic(self, simple_base: str) -> Optional[str]: log.debug(f"DEBUG: Found connected_vehicle soc pattern, transforming: {simple_base}") simple_base = re.sub(r'/get/connected_vehicle/soc$', '/soc', simple_base) simple_base = re.sub(r'/connected_vehicle/soc$', '/soc', simple_base) - + # Keep only config topics that are in the allowed list if '/config/' in simple_base and not re.search(r'/(chargemode|vehicle_name)$', simple_base): allowed_config_paths = [ @@ -313,13 +313,13 @@ def _transform_chargepoint_topic(self, simple_base: str) -> Optional[str]: # Handle get topics - remove /get/ prefix if '/get/' in simple_base: simple_base = simple_base.replace('/get/', '/') - + # Special handling for soc-related topics if re.search(r'/soc$', simple_base): simple_base = re.sub(r'/soc$', '/pro_soc', simple_base) elif re.search(r'/soc_timestamp$', simple_base): simple_base = re.sub(r'/soc_timestamp$', '/pro_soc_timestamp', simple_base) - + # Filter out unwanted topics - but exclude already transformed ones if not re.search(r'/(chargemode|vehicle_name|soc|pro_soc|pro_soc_timestamp)$', simple_base): unwanted_patterns = [ @@ -439,7 +439,7 @@ def _cache_charge_template(self, topic: str, payload: str): charge_template = json.loads(payload) self.charge_template_cache[chargepoint_id] = charge_template log.debug(f"Cached charge_template for chargepoint {chargepoint_id}") - + # Publish read topics for charge_template values self._publish_charge_template_read_topics(chargepoint_id, charge_template) @@ -452,72 +452,72 @@ def _publish_charge_template_read_topics(self, chargepoint_id: str, charge_templ """Publish readable topics for charge_template values.""" try: chargemode = charge_template.get('chargemode', {}) - + # Extract min_current from pv_charging pv_charging = chargemode.get('pv_charging', {}) if 'min_current' in pv_charging: topic = f"openWB/simpleAPI/chargepoint/{chargepoint_id}/minimal_permanent_current" self._publish_if_changed(topic, pv_charging['min_current']) - + # Also publish for lowest ID if this is it if 'chargepoint' in self.lowest_ids and self.lowest_ids['chargepoint'] == int(chargepoint_id): simple_topic = "openWB/simpleAPI/chargepoint/minimal_permanent_current" self._publish_if_changed(simple_topic, pv_charging['min_current']) - + # Extract min_soc from pv_charging (minimal_pv_soc) if 'min_soc' in pv_charging: topic = f"openWB/simpleAPI/chargepoint/{chargepoint_id}/minimal_pv_soc" self._publish_if_changed(topic, pv_charging['min_soc']) - + # Also publish for lowest ID if this is it if 'chargepoint' in self.lowest_ids and self.lowest_ids['chargepoint'] == int(chargepoint_id): simple_topic = "openWB/simpleAPI/chargepoint/minimal_pv_soc" self._publish_if_changed(simple_topic, pv_charging['min_soc']) - + # Extract max_price from eco_charging eco_charging = chargemode.get('eco_charging', {}) if 'max_price' in eco_charging: topic = f"openWB/simpleAPI/chargepoint/{chargepoint_id}/max_price_eco" self._publish_if_changed(topic, eco_charging['max_price']) - + # Also publish for lowest ID if this is it if 'chargepoint' in self.lowest_ids and self.lowest_ids['chargepoint'] == int(chargepoint_id): simple_topic = "openWB/simpleAPI/chargepoint/max_price_eco" self._publish_if_changed(simple_topic, eco_charging['max_price']) - + # Extract instant_charging_limit values instant_charging = chargemode.get('instant_charging', {}) limit = instant_charging.get('limit', {}) - + if 'selected' in limit: topic = f"openWB/simpleAPI/chargepoint/{chargepoint_id}/instant_charging_limit" self._publish_if_changed(topic, limit['selected']) - + # Also publish for lowest ID if this is it if 'chargepoint' in self.lowest_ids and self.lowest_ids['chargepoint'] == int(chargepoint_id): simple_topic = "openWB/simpleAPI/chargepoint/instant_charging_limit" self._publish_if_changed(simple_topic, limit['selected']) - + if 'amount' in limit: # Convert from internal value (Wh) to kWh for display amount_kwh = limit['amount'] / 1000 topic = f"openWB/simpleAPI/chargepoint/{chargepoint_id}/instant_charging_limit_amount" self._publish_if_changed(topic, amount_kwh) - + # Also publish for lowest ID if this is it if 'chargepoint' in self.lowest_ids and self.lowest_ids['chargepoint'] == int(chargepoint_id): simple_topic = "openWB/simpleAPI/chargepoint/instant_charging_limit_amount" self._publish_if_changed(simple_topic, amount_kwh) - + if 'soc' in limit: topic = f"openWB/simpleAPI/chargepoint/{chargepoint_id}/instant_charging_limit_soc" self._publish_if_changed(topic, limit['soc']) - + # Also publish for lowest ID if this is it if 'chargepoint' in self.lowest_ids and self.lowest_ids['chargepoint'] == int(chargepoint_id): simple_topic = "openWB/simpleAPI/chargepoint/instant_charging_limit_soc" self._publish_if_changed(simple_topic, limit['soc']) - + except Exception as e: log.error(f"Error publishing charge_template read topics: {e}") From a696b25dcc9a8f2158f179dbbfe8ebdef5896334 Mon Sep 17 00:00:00 2001 From: Lutz Bender Date: Tue, 7 Jul 2026 12:56:40 +0200 Subject: [PATCH 2/2] upgrade actions --- .github/workflows/github-actions-python.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github-actions-python.yml b/.github/workflows/github-actions-python.yml index 87b55c8029..529a6e17cd 100644 --- a/.github/workflows/github-actions-python.yml +++ b/.github/workflows/github-actions-python.yml @@ -6,21 +6,21 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 - name: Set up Python 3.9 - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: "3.9.12" - name: Install dependencies run: | pip3 install -r "/home/runner/work/core/core/requirements.txt" - name: Flake8 with annotations in packages folder - uses: TrueBrain/actions-flake8@v2.1 + uses: TrueBrain/actions-flake8@v2.4 with: path: packages flake8_version: "7.3.0" - name: Flake8 with annotations in runs folder - uses: TrueBrain/actions-flake8@v2.1 + uses: TrueBrain/actions-flake8@v2.4 with: path: runs flake8_version: "7.3.0"