squishykid / solax

🌞 Solax Inverter API Wrapper
MIT License
92 stars 56 forks source link

extend class method "async def real_time_api(ip_address, port=80, pwd="")" with inverter #105

Open emichel11 opened 1 year ago

emichel11 commented 1 year ago

The discover process takes some time or - in my case does not work properly Actually the method async def real_time_api(ip_address, port=80, pwd=""): i = await discover(ip_address, port, pwd) return RealTimeAPI(i)

calls discover and this method scans all available classes in regestry async def discover(host, port, pwd="") -> Inverter: failures = [] for inverter in REGISTRY:

It shall be possible to predefine the INVERTER for real_time_api / discover method. This will speedup the process for known inverters

MatthiasFraass commented 1 year ago

Agreed.

Meanwhile this is the code for direct use of a known inverter:

import solax
import asyncio

from solax.inverters import QVOLTHYBG33P
from solax import RealTimeAPI

async def work():
    i = QVOLTHYBG33P._build('IP_OF_WIFI_DONGLE', 80, 'SERIAL_NUMER_OF_WIFI_DONGLE')
    r = RealTimeAPI(i)
    return await r.get_data()

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
data = loop.run_until_complete(work())
print(data)