thebradleysanders / evergy_home_assistant

A Home Assistant Integration to view your households energy usage, powered by Evergy.
MIT License
10 stars 3 forks source link

JSONDecodeError #6

Open tboyce021 opened 1 year ago

tboyce021 commented 1 year ago

Stopped syncing yesterday and a reboot gives the following error. Tried removing the integration and adding it back but it fails to add the integration.

This error originated from a custom integration.

Logger: custom_components.evergy.sensor
Source: custom_components/evergy/pyEvergy.py:71
Integration: Evergy (documentation)
First occurred: 6:42:25 PM (1 occurrences)
Last logged: 6:42:25 PM

Unexpected error fetching sensor data: Expecting value: line 2 column 1 (char 1)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 250, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 206, in _async_update_data
    return await self.update_method()
  File "/config/custom_components/evergy/sensor.py", line 49, in async_update_data
    await hass.async_add_executor_job(evergy_api.get_usage)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/evergy/pyEvergy.py", line 94, in get_usage
    return self.get_usage_range(get_past_date(days_back=days - 1), get_past_date(0), interval=interval)
  File "/config/custom_components/evergy/pyEvergy.py", line 106, in get_usage_range
    self.login()
  File "/config/custom_components/evergy/pyEvergy.py", line 71, in login
    self.account_number = json.loads(account_data[0].contents[0])["accountNumber"]
  File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)
terryhonn commented 1 year ago

I believe I'm seeing the same thing. Realized I was no longer seeing the energy consumption data in the Energy dashboard, tried reloading the integration without change, so I deleted the integration and tried adding again, but the setup fails with this message:

[%key:common::config_flow::error::unknown%]

tboyce021 commented 1 year ago

The "official" https://github.com/lawrencefoley/evergy also has this issue. I did some digging and account_data[0].contents[0] is just an empty string with a newline character.

lawrencefoley commented 1 year ago

Here's the related issue: https://github.com/lawrencefoley/evergy/issues/34

I think it might be better to include my library as a dependency instead of having another copy of the code. That way if modifications like this are needed they only need to be changed in one place. Thoughts? @thebradleysanders

thebradleysanders commented 1 year ago

I agree with you @lawrencefoley, I will work on getting your library added.

thebradleysanders commented 1 year ago

I have merged the fix provided by: @Ben-Reg, Version 1.0.5 includes this fix and has been released. Thanks @Ben-Reg, @tboyce021 & @terryhonn.