Skip to content

Commit

Permalink
Resolve more QA issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Dos Moonen committed Jun 6, 2023
1 parent 3bce66c commit 40adf45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"async_timeout>=4.0.2",
"voluptuous>=0.11.5",
"mypy_extensions",
"async_timeout",
],
setup_requires=[
"setuptools_scm",
Expand Down
40 changes: 22 additions & 18 deletions solax/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DiscoveryError(Exception):
async def discover(host, port, pwd="") -> Inverter:
failures: list = []
clients = all_variations(host, port, pwd)
pending = {}
pending = set()

async def identify_inverter(sleep, client_name, client):
await asyncio.sleep(sleep) # don't spam the inverter
Expand All @@ -45,16 +45,17 @@ async def identify_inverter(sleep, client_name, client):
await asyncio.sleep(0)
try:
inverter = inverter_class(client)

if inverter.identify(response):
return inverter
else:
failures.append(
(
client_name,
inverter_class.__name__,
"did not identify",
)

failures.append(
(
client_name,
inverter_class.__name__,
"did not identify",
)
)
except InverterError as ex:
failures.append(
(
Expand All @@ -65,7 +66,7 @@ async def identify_inverter(sleep, client_name, client):
)

for sleep, (name, client) in enumerate(clients.items()):
pending.append(
pending.add(
asyncio.create_task(
identify_inverter(sleep, name, client),
name=name,
Expand All @@ -81,21 +82,24 @@ async def identify_inverter(sleep, client_name, client):

try:
inverter = await task
for t in pending:
t.cancel()

for loser in pending:
loser.cancel()

return inverter
except Exception as ex:
except RuntimeError as ex:
failures.append(
(
task.get_name(),
ex,
)
)

msg = (
"Unable to connect to the inverter at "
f"host={host} port={port}, or your inverter is not supported yet.\n"
"Please see https://github.com/squishykid/solax/wiki/DiscoveryError\n"
f"Failures={str(failures)}"
raise DiscoveryError(
(
"Unable to connect to the inverter at "
f"host={host} port={port}, or your inverter is not supported yet.\n"
"Please see https://github.com/squishykid/solax/wiki/DiscoveryError\n"
f"Failures={str(failures)}"
)
)
raise DiscoveryError(msg)

0 comments on commit 40adf45

Please sign in to comment.