Kleinrotti / py-senertec

Senertec energy system gen2 interface.
MIT License
1 stars 1 forks source link

Error when API request responds without units #15

Open mulles opened 1 month ago

mulles commented 1 month ago

$ python output_data.py py-senertec: 2024-07-11 19:26:21 INFO Logging in.. py-senertec: 2024-07-11 19:26:21 INFO Login was successful. py-senertec: 2024-07-11 19:26:21 INFO Initializing senertec platform... Traceback (most recent call last): File "/var/home/VENV_BHWK_Senertec_Dachs2API/output_data.py", line 106, in start() File "/var/home/VENV_BHWK_Senertec_Dachs2API/output_data.py", line 42, in start if senertecClient.connectUnit(units[0].serial) is False:


IndexError: list index out of range

I am not able to get any "names" for the units? 
Even though there are 3 units shown on dachsconnect.senertec.com, see the following screenshot:

![Screenshot from 2024-07-11 19-40-40](https://github.com/Kleinrotti/py-senertec/assets/13488510/4e4d50a1-5233-49ca-a8ac-d336de7eebff)

If you want I can create a pull request for better error messaging in case no units are returned by the API:

![Screenshot](https://github.com/Kleinrotti/py-senertec/assets/13488510/98e324ca-0c52-4524-8e30-1dfb44d14c03)
Kleinrotti commented 1 month ago

I have implemented a check in the example script if that list is empty.

mulles commented 1 month ago

Thx a lot for your reponse :)

This should not be a critic, but in the example script:

  # connect to first unit
    if senertecClient.connectUnit(units[0].serial) is False:
        return

There is only a return, not a real error message, which is why I get the error message above in my first post from python right?

Do you have any idea, why the list is empty in my case even though the portal is definitely showing 3 units?

Kleinrotti commented 1 month ago

Can you check the "units" response in the browser debugging network tab? If you refresh the site with your 3 units you should get it. It should look like this (demo account): image

mulles commented 1 month ago

Looks like the data is available:

image

Please give me a hint, in case I did not erease all sensitive data :)

Kleinrotti commented 1 month ago

The response looks ok so far. Can you also post a screenshot of the payload next to the preview tab?

mulles commented 1 month ago

With pleasure: image

Kleinrotti commented 1 month ago

The payload looks also as expected. The only difference is that py-senertec uses an empty filter with limit: 10, offset: 0. Maybe the filter value msr3Filter which is false has a default value of true in the system if it's not present. That would be my only idea because the msrTyp of your energy units is 2 and not 3. Can you try to replace this line of code of the library (client.py, Line 381):

"/rest/info/units", json.dumps({"limit": 10, "offset": 0, "filter": {}}))

with this one:

"/rest/info/units", json.dumps({"limit": 10, "offset": 0, "filter": {"msr3Filter": False}}))

and try it again?

mulles commented 1 month ago
$ python output_data.py 
py-senertec: 2024-07-11 22:37:31 INFO     Logging in..
py-senertec: 2024-07-11 22:37:31 INFO     Login was successful.
py-senertec: 2024-07-11 22:37:31 INFO     Initializing senertec platform...
No energy units were found

That what I get. Thx a lot for your time. I am happy to assist you more, but please be careful with your precious time. It is not that important to me to get it running, but I am learning a lot :)

Probably the difference between my login and the one of most people is that I have 3 BHKW, 2 in one location and the third one on a different instead of just one in one location?

Kleinrotti commented 1 month ago

Locations and number of BHKWs shouldn't make a difference because its still the same list in the response. It has to do something with the payload I think. Can you also try this complete filter:

"/rest/info/units", json.dumps({"limit": 10, "offset": 0, "filter": {"connected": False, "search": None, "msr3Filter": False, "sortByLocation": True}}))