Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when API request responds without units #15

Open
mulles opened this issue Jul 11, 2024 · 9 comments
Open

Error when API request responds without units #15

mulles opened this issue Jul 11, 2024 · 9 comments

Comments

@mulles
Copy link

mulles commented Jul 11, 2024

$ 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

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

Screenshot

@Kleinrotti
Copy link
Owner

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

@mulles
Copy link
Author

mulles commented Jul 11, 2024

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
Copy link
Owner

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
Copy link
Author

mulles commented Jul 11, 2024

Looks like the data is available:

image

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

@Kleinrotti
Copy link
Owner

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

@mulles
Copy link
Author

mulles commented Jul 11, 2024

With pleasure:
image

@Kleinrotti
Copy link
Owner

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
Copy link
Author

mulles commented Jul 11, 2024

$ 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
Copy link
Owner

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}}))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants