Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable ports for devices #1380

Merged
merged 1 commit into from
Mar 26, 2024
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
26 changes: 25 additions & 1 deletion packages/helpermodules/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


class UpdateConfig:
DATASTORE_VERSION = 39
DATASTORE_VERSION = 40
valid_topic = [
"^openWB/bat/config/configured$",
"^openWB/bat/set/charging_power_left$",
Expand Down Expand Up @@ -1333,3 +1333,27 @@ def upgrade(topic: str, payload) -> Optional[dict]:
return {topic: updated_payload}
self._loop_all_received_topics(upgrade)
self.__update_topic("openWB/system/datastore_version", 39)
Pub().pub("openWB/system/datastore_version", 39)

def upgrade_datastore_39(self) -> None:
def upgrade(topic: str, payload) -> None:
if re.search("openWB/system/device/[0-9]+/config", topic) is not None:
payload = decode_payload(payload)
if payload.get("type") == "alpha_ess" and "port" not in payload["configuration"]:
if payload["configuration"]["source"] == 1:
payload["configuration"].update({"port": 502})
if payload.get("type") == "kostal_plenticore" and "port" not in payload["configuration"]:
payload["configuration"].update({"port": 1502})
if payload.get("type") == "saxpower" and "port" not in payload["configuration"]:
payload["configuration"].update({"port": 3600})
# modules with port 502
modified_modules = ["powerdog", "carlo_gavazzi", "e3dc", "good_we",
"huawei", "huawei_smartlogger", "janitza", "kostal_sem", "qcells",
"siemens", "siemens_sentron", "sma_sunny_boy", "sma_sunny_island",
"solarmax", "solax", "studer", "varta", "victron"]
for i in modified_modules:
if payload.get("type") == i and "port" not in payload["configuration"]:
payload["configuration"].update({"port": 502})
Pub().pub(topic, payload)
self._loop_all_received_topics(upgrade)
Pub().pub("openWB/system/datastore_version", 40)
3 changes: 2 additions & 1 deletion packages/modules/devices/alpha_ess/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@


class AlphaEssConfiguration:
def __init__(self, source: int = 0, ip_address: Optional[str] = None, version: int = 1):
def __init__(self, source: int = 0, ip_address: Optional[str] = None, version: int = 1, port: int = 502):
self.source = source # 0: AlphaEss-Kit, 1: Hi5/10 mit variabler IP
self.ip_address = ip_address
self.version = version # 0: <V1.23, 1: >= V1.23
self.port = port


class AlphaEss:
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/alpha_ess/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def __init__(self, device_config: Union[Dict, AlphaEss]) -> None:
if self.device_config.configuration.source == 0:
self.client = modbus.ModbusTcpClient_("192.168.193.125", 8899)
else:
self.client = modbus.ModbusTcpClient_(self.device_config.configuration.ip_address, 502)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/carlo_gavazzi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class CarloGavazziConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


class CarloGavazzi:
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/devices/carlo_gavazzi/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, device_config: Union[Dict, CarloGavazzi]) -> None:
self.components = {} # type: Dict[str, counter.CarloGavazziCounter]
try:
self.device_config = dataclass_from_dict(CarloGavazzi, device_config)
ip_address = self.device_config.configuration.ip_address
self.client = modbus.ModbusTcpClient_(ip_address, 502)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/e3dc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

@auto_str
class E3dcConfiguration:
def __init__(self, address: str = None):
def __init__(self, address: str = None, port: int = 502):
self.address = address
self.port = port


@auto_str
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/devices/e3dc/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def update_components(components: Iterable[Union[E3dcBat, E3dcCounter, E3dcInver
component.update(c)

try:
client = modbus.ModbusTcpClient_(device_config.configuration.address, 502)
client = modbus.ModbusTcpClient_(device_config.configuration.address, device_config.configuration.port)
except Exception:
log.exception("Fehler in create_device")

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/good_we/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@


class GoodWeConfiguration:
def __init__(self, ip_address: Optional[str] = None, modbus_id: int = 247):
def __init__(self, ip_address: Optional[str] = None, modbus_id: int = 247, port: int = 502):
self.ip_address = ip_address
self.modbus_id = modbus_id
self.port = port


class GoodWe:
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/devices/good_we/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def __init__(self, device_config: Union[Dict, GoodWe]) -> None:
self.components = {} # type: Dict[str, good_we_component_classes]
try:
self.device_config = dataclass_from_dict(GoodWe, device_config)
ip_address = self.device_config.configuration.ip_address
self.client = modbus.ModbusTcpClient_(ip_address, 502)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul " + self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/huawei/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@


class HuaweiConfiguration:
def __init__(self, modbus_id: int = 1, ip_address: Optional[str] = None,):
def __init__(self, modbus_id: int = 1, ip_address: Optional[str] = None, port: int = 502):
self.modbus_id = modbus_id
self.ip_address = ip_address
self.port = port


class Huawei:
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/huawei/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def update_components(components: Iterable[Union[HuaweiBat, HuaweiCounter, Huawe
raise e

try:
client = ModbusTcpClient_(device_config.configuration.ip_address, 502, sleep_after_connect=7)
client = ModbusTcpClient_(device_config.configuration.ip_address,
device_config.configuration.port, sleep_after_connect=7)
except Exception:
log.exception("Fehler in create_device")
return ConfigurableDevice(
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/huawei_smartlogger/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

@auto_str
class Huawei_SmartloggerConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


@auto_str
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/devices/huawei_smartlogger/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def __init__(self, device_config: Union[Dict, Huawei_Smartlogger]) -> None:
try:
self.device_config = dataclass_from_dict(Huawei_Smartlogger, device_config)
ip_address = self.device_config.configuration.ip_address
self.port = 502
self.client = modbus.ModbusTcpClient_(ip_address, 502)
self.port = self.device_config.configuration.port
self.client = modbus.ModbusTcpClient_(ip_address, self.device_config.configuration.port)
self.client.connect()
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/janitza/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class JanitzaConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


class Janitza:
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/devices/janitza/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, device_config: Union[Dict, Janitza]) -> None:
self.components = {} # type: Dict[str, counter.JanitzaCounter]
try:
self.device_config = dataclass_from_dict(Janitza, device_config)
ip_address = self.device_config.configuration.ip_address
self.client = modbus.ModbusTcpClient_(ip_address, 502)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/kostal_plenticore/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class KostalPlenticoreConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 1502):
self.ip_address = ip_address
self.port = port


class KostalPlenticore:
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/devices/kostal_plenticore/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def update_components(
update(components, reader)

try:
tcp_client = modbus.ModbusTcpClient_(device_config.configuration.ip_address, 1502)
tcp_client = modbus.ModbusTcpClient_(device_config.configuration.ip_address, device_config.configuration.port)
reader = _create_reader(tcp_client)
except Exception:
log.exception("Fehler in create_device")
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/kostal_sem/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class KostalSemConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


class KostalSem:
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/devices/kostal_sem/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create_device(device_config: KostalSem):
def create_counter_component(component_config: KostalSemCounterSetup):
return KostalSemCounter(component_config, client)

client = modbus.ModbusTcpClient_(device_config.configuration.ip_address, 502)
client = modbus.ModbusTcpClient_(device_config.configuration.ip_address, device_config.configuration.port)
return ConfigurableDevice(
device_config=device_config,
component_factory=ComponentFactoryByType(counter=create_counter_component),
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/powerdog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class PowerdogConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


class Powerdog:
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/devices/powerdog/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def __init__(self, device_config: Union[Dict, Powerdog]) -> None:
self.components = {} # type: Dict[str, Union[counter.PowerdogCounter, inverter.PowerdogInverter]]
try:
self.device_config = dataclass_from_dict(Powerdog, device_config)
ip_address = self.device_config.configuration.ip_address
self.client = modbus.ModbusTcpClient_(ip_address, 502)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/qcells/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@


class QCellsConfiguration:
def __init__(self, modbus_id: int = 1, ip_address: Optional[str] = None):
def __init__(self, modbus_id: int = 1, ip_address: Optional[str] = None, port: int = 502):
self.modbus_id = modbus_id
self.ip_address = ip_address
self.port = port


class QCells:
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/devices/qcells/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def update_components(components: Iterable[Union[QCellsBat, QCellsCounter, QCell
component.update(c)

try:
client = ModbusTcpClient_(device_config.configuration.ip_address, 502)
client = ModbusTcpClient_(device_config.configuration.ip_address, device_config.configuration.port)
except Exception:
log.exception("Fehler in create_device")
return ConfigurableDevice(
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/saxpower/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class SaxpowerConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 3600):
self.ip_address = ip_address
self.port = port


class Saxpower:
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/devices/saxpower/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, device_config: Union[Dict, Saxpower]) -> None:
self.components = {} # type: Dict[str, bat.SaxpowerBat]
try:
self.device_config = dataclass_from_dict(Saxpower, device_config)
ip_address = self.device_config.configuration.ip_address
self.client = modbus.ModbusTcpClient_(ip_address, 3600)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/siemens/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class SiemensConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


class Siemens:
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/siemens/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def __init__(self, device_config: Union[Dict, Siemens]) -> None:
self.components = {} # type: Dict[str, siemens_component_classes]
try:
self.device_config = dataclass_from_dict(Siemens, device_config)
self.client = modbus.ModbusTcpClient_(self.device_config.configuration.ip_address, 502)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/siemens_sentron/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class SiemensSentronConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


class SiemensSentron:
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/devices/siemens_sentron/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, device_config: Union[Dict, SiemensSentron]) -> None:
self.components = {} # type: Dict[str, counter.SiemensSentronCounter]
try:
self.device_config = dataclass_from_dict(SiemensSentron, device_config)
ip_address = self.device_config.configuration.ip_address
self.client = modbus.ModbusTcpClient_(ip_address, 502)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/sma_sunny_boy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@


class SmaSunnyBoyConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


class SmaSunnyBoy:
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/devices/sma_sunny_boy/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def __init__(self, device_config: Union[Dict, SmaSunnyBoy]) -> None:
self.components = {} # type: Dict[str, sma_modbus_tcp_component_classes]
try:
self.device_config = dataclass_from_dict(SmaSunnyBoy, device_config)
ip_address = self.device_config.configuration.ip_address
self.client = modbus.ModbusTcpClient_(ip_address, 502)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/sma_sunny_island/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class SmaSunnyIslandConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


class SmaSunnyIsland:
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/sma_sunny_island/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def __init__(self, device_config: Union[Dict, SmaSunnyIsland]) -> None:
self.components = {} # type: Dict[str, bat.SunnyIslandBat]
try:
self.device_config = dataclass_from_dict(SmaSunnyIsland, device_config)
self.client = modbus.ModbusTcpClient_(self.device_config.configuration.ip_address, 502)
self.client = modbus.ModbusTcpClient_(
self.device_config.configuration.ip_address, self.device_config.configuration.port)
except Exception:
log.exception("Fehler im Modul "+self.device_config.name)

Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/solarmax/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


class SolarmaxConfiguration:
def __init__(self, ip_address: Optional[str] = None):
def __init__(self, ip_address: Optional[str] = None, port: int = 502):
self.ip_address = ip_address
self.port = port


class Solarmax:
Expand Down
Loading