From a6d16e67900ef20aee7fc7b3454f22eb8cdc1884 Mon Sep 17 00:00:00 2001 From: mle Date: Sun, 28 Apr 2024 23:29:01 +0200 Subject: [PATCH] Do not invoke discover on TCP port --- goodwe/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/goodwe/__init__.py b/goodwe/__init__.py index 4d23602..b954209 100644 --- a/goodwe/__init__.py +++ b/goodwe/__init__.py @@ -4,7 +4,7 @@ import logging from typing import Type -from .const import GOODWE_UDP_PORT +from .const import GOODWE_TCP_PORT, GOODWE_UDP_PORT from .dt import DT from .es import ES from .et import ET @@ -42,7 +42,7 @@ async def connect(host: str, port: int = GOODWE_UDP_PORT, family: str = None, co Raise InverterError if unable to contact or recognise supported inverter. """ - if family in ET_FAMILY: + if family in ET_FAMILY or port == GOODWE_TCP_PORT: inv = ET(host, port, comm_addr, timeout, retries) elif family in ES_FAMILY: inv = ES(host, port, comm_addr, timeout, retries) @@ -53,7 +53,7 @@ async def connect(host: str, port: int = GOODWE_UDP_PORT, family: str = None, co else: raise InverterError("Specify either an inverter family or set do_discover True") - logger.debug("Connecting to %s family inverter at %s.", family, host) + logger.debug("Connecting to %s family inverter at %s:%s.", family, host, port) await inv.read_device_info() logger.debug("Connected to inverter %s, S/N:%s.", inv.model_name, inv.serial_number) return inv @@ -68,7 +68,7 @@ async def discover(host: str, port: int = GOODWE_UDP_PORT, timeout: int = 1, ret # Try the common AA55C07F0102000241 command first and detect inverter type from serial_number try: - logger.debug("Probing inverter at %s.", host) + logger.debug("Probing inverter at %s:%s.", host, port) response = await DISCOVERY_COMMAND.execute(UdpInverterProtocol(host, port, timeout, retries)) response = response.response_data() model_name = response[5:15].decode("ascii").rstrip() @@ -88,7 +88,7 @@ async def discover(host: str, port: int = GOODWE_UDP_PORT, timeout: int = 1, ret logger.debug("Detected DT/MS/D-NS/XS/GEP inverter %s, S/N:%s.", model_name, serial_number) inverter_class = DT if inverter_class: - i = inverter_class(host, 0, timeout, retries) + i = inverter_class(host, port, 0, timeout, retries) await i.read_device_info() return i @@ -97,7 +97,7 @@ async def discover(host: str, port: int = GOODWE_UDP_PORT, timeout: int = 1, ret # Probe inverter specific protocols for inv in _SUPPORTED_PROTOCOLS: - i = inv(host, 0, timeout, retries) + i = inv(host, port, 0, timeout, retries) try: logger.debug("Probing %s inverter at %s.", inv.__name__, host) await i.read_device_info()