hpeyerl / venstar_colortouch

Python interface for Venstar ColorTouch thermostats
MIT License
12 stars 22 forks source link

JSONDecodeError when calling update_info() #17

Closed flamechair closed 4 years ago

flamechair commented 4 years ago

https://github.com/hpeyerl/venstar_colortouch/blob/9ef092603b3fe91917b14187504ef98e5d35ecde/src/venstarcolortouch/venstarcolortouch.py#L142-L147

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 270, in async_update_ha_state
    await self.async_device_update()
  File "/usr/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 450, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/venstar/climate.py", line 109, in update
    info_success = self._client.update_info()
  File "/usr/lib/python3.7/site-packages/venstarcolortouch/venstarcolortouch.py", line 122, in update_info
    self._info=r.json()
  File "/usr/lib/python3.7/site-packages/requests/models.py", line 889, in json
    self.content.decode(encoding), **kwargs
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/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)

Maybe we should wrap the self._info=r.json() in a try/except?

r = self._request("/query/info")

if r is False:
    return r

try:
    self._info=r.json()
catch json.decoder.JSONDecodeError as error:
    self.log.error("Failed to update info, response: %s", str(r))
    return False
flamechair commented 4 years ago

Also a similar error happens in set_control():

https://github.com/hpeyerl/venstar_colortouch/blob/9ef092603b3fe91917b14187504ef98e5d35ecde/src/venstarcolortouch/venstarcolortouch.py#L264-L273

File "/usr/lib/python3.7/site-packages/venstarcolortouch/venstarcolortouch.py", line 242, in set_setpoints
    return self.set_control()
  File "/usr/lib/python3.7/site-packages/venstarcolortouch/venstarcolortouch.py", line 227, in set_control
    if "success" in r.json():
  File "/usr/lib/python3.7/site-packages/requests/models.py", line 889, in json
    self.content.decode(encoding), **kwargs
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/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)
hpeyerl commented 4 years ago

Yeah. Good idea. Merge request please?

hpeyerl commented 4 years ago

Do you want me to push a new release to pypi or just wait until the next one?

flamechair commented 4 years ago

I'd say cut a minor/patch release, I don't think I'm the only one that has been experiencing this.

hpeyerl commented 4 years ago

I have pushed a 0.12 now which includes Garbled's fixes too.