Skip to content

Commit

Permalink
fix reconnection delay for counter and inverter
Browse files Browse the repository at this point in the history
  • Loading branch information
Lutz Bender committed Feb 26, 2024
1 parent 7c0a7e4 commit 11f27ff
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/modules/devices/solaredge/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from operator import add
from statistics import mean
import time
from typing import Dict, Iterable, Tuple, Union, Optional, List
from urllib3.util import parse_url

Expand Down Expand Up @@ -30,6 +31,8 @@
solaredge_component_classes = Union[SolaredgeBat, SolaredgeCounter,
SolaredgeExternalInverter, SolaredgeInverter]
default_unit_id = 85
synergy_unit_identifier = 160
reconnect_delay = 1.2


class Device(AbstractDevice):
Expand Down Expand Up @@ -68,10 +71,31 @@ def add_component(self,
self.device_config.id, component_config, self.client))
if component_type == "inverter" or component_type == "external_inverter":
self.inverter_counter += 1
self.synergy_units = int(self.client.read_holding_registers(
40129, modbus.ModbusDataType.UINT_16,
unit=component_config.configuration.modbus_id)) or 1
log.debug("Synergy Units: %s", self.synergy_units)
with self.client:
# try:
# # ToDo: convert to String
# manufacturer = self.client.read_holding_registers(40004, [modbus.ModbusDataType.UINT_32]*8,
# unit=component_config.configuration.modbus_id)
# # ToDo: convert to String
# model = self.client.read_holding_registers(40020, [modbus.ModbusDataType.UINT_32]*8,
# unit=component_config.configuration.modbus_id)
# # ToDo: convert to String
# version = self.client.read_holding_registers(40044, [modbus.ModbusDataType.UINT_16]*8,
# unit=component_config.configuration.modbus_id)
# serial_number = self.client.read_holding_registers(40052, [modbus.ModbusDataType.UINT_32]*8,
# unit=component_config.configuration.modbus_id)
# log.debug("Version: " + str(version))
# except Exception as e:
# log.exception("Fehler beim Auslesen der Modbus-Register: " + str(e))
# pass
if self.client.read_holding_registers(40121, modbus.ModbusDataType.UINT_16,
unit=component_config.configuration.modbus_id
) == synergy_unit_identifier:

Check failure on line 93 in packages/modules/devices/solaredge/device.py

View workflow job for this annotation

GitHub Actions / build

closing bracket does not match visual indentation
log.debug("Synergy Units supported")
self.synergy_units = int(self.client.read_holding_registers(
40129, modbus.ModbusDataType.UINT_16,
unit=component_config.configuration.modbus_id)) or 1
log.debug("Synergy Units detected: %s", self.synergy_units)
if component_type == "external_inverter" or component_type == "counter" or component_type == "inverter":
self.set_component_registers(self.components.values(), self.synergy_units)
else:
Expand Down Expand Up @@ -179,6 +203,7 @@ def create_inverter(modbus_id: int) -> SolaredgeInverter:
if component_type == "counter":
dev.add_component(SolaredgeCounterSetup(
id=num, configuration=SolaredgeCounterConfiguration(modbus_id=int(slave_id0))))
time.sleep(reconnect_delay)
log.debug('Solaredge ModbusID: ' + str(slave_id0))
dev.update()
elif component_type == "inverter":
Expand Down Expand Up @@ -250,6 +275,7 @@ def create_inverter(modbus_id: int) -> SolaredgeInverter:
state = get_external_inverter_state(dev, int(slave_id0))
total_power += state.power
get_inverter_value_store(num).set(InverterState(exported=total_energy, power=total_power))
time.sleep(reconnect_delay)

elif component_type == "bat":
with SingleComponentUpdateContext(ComponentInfo(0, "Solaredge Speicher", "bat")):
Expand Down

0 comments on commit 11f27ff

Please sign in to comment.