joggs / home_assistant_ebeco

Integration for Ebeco thermostats
28 stars 14 forks source link

Unable to update Ebeco thermostat - json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) #37

Open danilsson opened 7 months ago

danilsson commented 7 months ago

I've been consistently getting the following error in Home Assistant.

Unable to update Ebeco thermostat

Traceback (most recent call last):
  File "/config/custom_components/ebeco/ebeco_device.py", line 44, in async_change
    await self.set_room_target_temperature(changes["temperature"], True)
  File "/config/custom_components/ebeco/ebeco_device.py", line 65, in set_room_target_temperature
    await self._ebeco_data_handler.set_room_target_temperature(json_data)
  File "/config/custom_components/ebeco/data_handler.py", line 71, in set_room_target_temperature
    await self._request(
  File "/config/custom_components/ebeco/data_handler.py", line 119, in _request
    await self._getAccessToken(self)
  File "/config/custom_components/ebeco/data_handler.py", line 109, in _getAccessToken
    token_data = json.loads(
                 ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Stepping through the code with debugger I've found that it happens when the API returns 429 (Too many requests).

danilsson commented 7 months ago

Since I've made these changes to my local component, and it seems to have resolved the issue completely:

https://github.com/joggs/home_assistant_ebeco/pull/35

PerfectlyNormal commented 7 months ago

Have you changed the default refresh interval yourself? Or are you often changing the temperature? (Or do you maybe just have several thermostats?)

The backoff in #35 should fix it/work around the problem, yes. I'm just curious why you're getting them in the first place. I don't think I've ever seen it, but I mostly use it as a fancy read-only sensor

danilsson commented 7 months ago

This was with the default refresh rate, but I was changing the temperature based on the electricity price, sometimes quite frequently. I have two thermostats.

danilsson commented 7 months ago

I wanted to try to implement a DataUpdateCoordinator that pulls data only once, using GetUserDevices, instead of separately for each thermostat, but I find the HA documentation quite confusing :D