schmittx / home-assistant-eero

Eero integration for Home Assistant
MIT License
118 stars 23 forks source link

Fix calculation for December #24

Closed mattsch closed 2 years ago

mattsch commented 2 years ago

Woke up to the following traceback and a non-functioning integration. This PR fixes it.

2021-12-01 09:20:50 ERROR (MainThread) [custom_components.eero] Unexpected error fetching Eero data: month must be in 1..12
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 187, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 147, in _async_update_data
    return await self.update_method()
  File "/config/custom_components/eero/__init__.py", line 176, in async_update_data
    return await hass.async_add_executor_job(api.update)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/eero/api/__init__.py", line 156, in update
    activity_data[resource][activity] = self.update_activity(
  File "/config/custom_components/eero/api/__init__.py", line 176, in update_activity
    start, end, cadence = self.define_period(period=ACTIVITY_MAP[activity][2], timezone=timezone)
  File "/config/custom_components/eero/api/__init__.py", line 77, in define_period
    end = start.replace(month=start.month+1) - datetime.timedelta(minutes=1)