Skip to content

Commit

Permalink
Do not invoke discover on TCP port
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed Apr 28, 2024
1 parent f963da1 commit a6d16e6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions goodwe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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

Expand All @@ -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()
Expand Down

0 comments on commit a6d16e6

Please sign in to comment.