Skip to content

Commit

Permalink
refactor: move each inverter in a separate file (#63)
Browse files Browse the repository at this point in the history
* remove redundant inverter mapping methods
* split up test data into multiple files
  • Loading branch information
VadimKraus authored Apr 21, 2022
1 parent eefc446 commit 5672b86
Show file tree
Hide file tree
Showing 20 changed files with 1,386 additions and 1,495 deletions.
4 changes: 2 additions & 2 deletions solax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import async_timeout

from solax import inverter
from solax.discovery import discover

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -34,7 +34,7 @@ async def rt_request(inv, retry, t_wait=0):


async def real_time_api(ip_address, port=80, pwd=''):
i = await inverter.discover(ip_address, port, pwd)
i = await discover(ip_address, port, pwd)
return RealTimeAPI(i)


Expand Down
30 changes: 30 additions & 0 deletions solax/discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

from solax.inverter import Inverter, InverterError
from solax.inverters import XHybrid, X3, X3V34, X1, X1Mini, X1MiniV34,\
X1Smart, QVOLTHYBG33P

# registry of inverters
REGISTRY = [XHybrid, X3, X3V34, X1, X1Mini, X1MiniV34, X1Smart,
QVOLTHYBG33P]


class DiscoveryError(Exception):
"""Raised when unable to discover inverter"""


async def discover(host, port, pwd='') -> Inverter:
failures = []
for inverter in REGISTRY:
i = inverter(host, port, pwd)
try:
await i.get_data()
return i
except InverterError as ex:
failures.append(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(msg)
Loading

0 comments on commit 5672b86

Please sign in to comment.