thomluther / anker-solix-api

Python library for Anker Solix API
MIT License
70 stars 15 forks source link

Refactor Api code to support various api clients #130

Open thomluther opened 1 week ago

thomluther commented 1 week ago

The API cloud has multiple endpoint categories. The API class was originally developed to handle only power services endpoints which are used for power systems like created for solarbank and powerpanels. However, there are many charging endpoints that might be used for PPS (power stations). Those endpoints actually work only on the non EU cloud server. This might be temporary and depend in which geo Anker releases which products. The Anker account assignment to the server is done by the account country and cannot be changed after registration. There are also new hes_* endpoints, probably related to managed devices like announced X1 home energy system. They should be handled via different API client since their structure might be completely different to known power systems and device structures of the power services endpoints. See apitypes.py module for known cloud endpoints and potential server assignment.

thomluther commented 1 week ago

The common request handling code should be in a new apihandler class which can be reused by any api client. If any api client will request and cache a new login response due to invalid token, other clients need to able to update their tokens from the cache file before doing new login requests on their own. Ideally the handler should use a common ecdh object for any encryption services againstthe used account and api clients should register to the handler. The handler could then centrally manage the server communication and authentication for any registered api client.