Skip to content

Commit

Permalink
re-submitting @rowinho 's PR to trigger the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luismsousa committed Feb 8, 2024
1 parent 4783bc9 commit 8e046bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions solax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ async def rt_request(inv: Inverter, retry, t_wait=0) -> InverterResponse:
raise


async def real_time_api(ip_address, port=80, pwd=""):
i = await discover(ip_address, port, pwd)
async def real_time_api(ip_address, port=80, pwd="", model=""):
i = await discover(ip_address, port, pwd, model)
return RealTimeAPI(i)


Expand Down
20 changes: 13 additions & 7 deletions solax/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ async def _discovery_task(cls, i) -> Inverter:
await i.get_data()
return i

async def discover(self, host, port, pwd="") -> Inverter:
async def discover(self, host, port, pwd="", model=None) -> Inverter:
for inverter in REGISTRY:
for i in inverter.build_all_variants(host, port, pwd):
task = asyncio.create_task(self._discovery_task(i), name=f"{i}")
task.add_done_callback(self._task_handler)
self._tasks.add(task)
if inverter.__name__ == model or model is None:
for i in inverter.build_all_variants(host, port, pwd):
task = asyncio.create_task(self._discovery_task(i), name=f"{i}")
task.add_done_callback(self._task_handler)
self._tasks.add(task)

while len(self._tasks) > 0:
logging.debug("%d discovery tasks are still running...", len(self._tasks))
Expand All @@ -97,7 +98,12 @@ class DiscoveryError(Exception):
"""Raised when unable to discover inverter"""


async def discover(host, port, pwd="") -> Inverter:
async def discover(host, port, pwd="", model=None) -> Inverter:
discover_state = DiscoveryState()
await discover_state.discover(host, port, pwd)
await discover_state.discover(host, port, pwd, model)
return discover_state.get_discovered_inverter()

def get_models() -> List[str]:
models = list(map(lambda inverter: inverter.__name__, REGISTRY))
models.sort()
return models

0 comments on commit 8e046bb

Please sign in to comment.