ldotlopez / ha-ideenergy

ideenergy integration for home-assistant
GNU General Public License v3.0
73 stars 13 forks source link

'HistoricalState' object has no attribute 'when' #42

Closed lazynoda closed 1 year ago

lazynoda commented 1 year ago

Describe the bug When starting HA, the following error log appears:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/homeassistant_historical_sensor/sensor.py", line 155, in async_write_ha_historical_states
    await self._async_save_states_into_statistics(hist_states)
  File "/usr/local/lib/python3.10/site-packages/homeassistant_historical_sensor/sensor.py", line 203, in _async_save_states_into_statistics
    statistics_data = await self.async_calculate_statistic_data(
  File "/config/custom_components/ideenergy/sensor.py", line 107, in async_calculate_statistic_data
    hist_states = [x for x in hist_states if x.when >= latest["end"]]
  File "/config/custom_components/ideenergy/sensor.py", line 107, in <listcomp>
    hist_states = [x for x in hist_states if x.when >= latest["end"]]
AttributeError: 'HistoricalState' object has no attribute 'when'

To Reproduce

  1. I had wip/historical-sensor branch running. It stopped working when I updated HA to 2023.3.X due to changes in DB.
  2. As mentioned in #34, I pulled the main branch, changed the HISTORICAL_PERIOD_LENGHT constant to timedelta(days=15), and restarted everything.

Environment

Expected behavior After restarting HA, I expected the integration to download past consumption data and import it into Energy dashboard.

Logs Working on it to avoid leaking data

Screenshots N/A

Additional context Like said, I came from wip/historical-sensor branch due to #34. I have 2 contracts, one is "disabled" but it has never been an issue before.

lazynoda commented 1 year ago

That commit fixed the issue @ldotlopez ❤️ now it's just a matter of changing the Delta to get past data. Thank you!