nordicopen / easee_hass

Custom component for Easee EV charger integration with Home Assistant
195 stars 33 forks source link

KeyError: "latest pulse" #429

Closed Alphaemef closed 3 weeks ago

Alphaemef commented 3 weeks ago

The problem

Working integration for a few days. I oversee 3 different chargers, and invited to monitor them as "admin". Suddenly lose access to all 3, without any clear cause.

Version of Easee integration having the issue?

easee_hass-0.9.59

Version of Home Assistant Core having the issue?

cores-2024.5.5

Anything in the logs that might be useful for us?

Logger: homeassistant
Source: custom_components/easee/controller.py:339 
integration: Easee EV charger (documentation, issues) 
First occurred: 13:01:26 (2 occurrences) 
Last logged: 13:02:26

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/easee/controller.py", line 706, in refresh_sites_state
    charger_data.check_latest_pulse()
  File "/config/custom_components/easee/controller.py", line 339, in check_latest_pulse
    elapsed = now - self.state["latestPulse"]
                    ~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyeasee/utils.py", line 55, in __getitem__
    if type(self._storage[key]) == str and validate_iso8601(self._storage[key]):
            ~~~~~~~~~~~~~^^^^^
KeyError: 'latestPulse'

Additional information

When looking into the main logs (debug) most of it (to me) looks to be working fine. Only thing that appears weird to me is: 2024-06-08 13:10:57.724 DEBUG (MainThread) [pyeasee.easee] verify_updated_token: 2024-06-08 13:59:25.442598, 2024-06-08 13:10:57.724246, False 2024-06-08 13:10:57.914 DEBUG (MainThread) [pyeasee.easee] SR start exception: ConnectionError: 429. Retry in 210 seconds

I tried reinstalling, rebooting several times, even removing the integration for about half a day, and reinstallation in the odd chance it was a rate limit issue, but to no avail.

olalid commented 3 weeks ago

I looks to me like the root cause of your problem is that the integration is unable to connect the SignalrR (SR) stream. (That other line from the log with "verify_updated_token" is completely normal). Why it does not connect is unclear to me, I just tried to restart the integration and it connected fine for me. ConnectionError indicates that the server is not reachable or does not respond. Do you still have the problem or was is temporary?

It is a bit unclear to me what you mean when you say "Suddenly lose access to all 3"?

Alphaemef commented 3 weeks ago

Still a problem.

My point was, I have access to 3 locations on my account, and neither of them are reachable in HA any more.

Any way I can investigate it further ?

Alphaemef commented 3 weeks ago

Just to be clear, are you saying the 429 error is wrong or normal ?

If 429 is the error, than that is usually a rate limit right ? But how do I avoid that ? Whats the timeout ?

olalid commented 3 weeks ago

I mean that this line is normal behaviour, it happens each time an API is called and False just indicates that the token does not need to be updated: [pyeasee.easee] verify_updated_token: 2024-06-08 13:59:25.442598, 2024-06-08 13:10:57.724246, False

The 429 error is a you say an indication that server is rate limiting your access. I have never seen that happen when trying to connect to the signalr stream, so not sure why that would happen. If you try to disable all but one of your locations in the integration settings, does that change anything?

Alphaemef commented 3 weeks ago

Super weird. Now its back to normal. I didn't change anything

olalid commented 3 weeks ago

Perhaps if you are using some other software that access the API at the same time, it could trigger rate limit? Well, good that it works again, let us know if you see it happening again.