Skip to content

Commit

Permalink
fix: previous date not available
Browse files Browse the repository at this point in the history
  • Loading branch information
duhow committed Nov 18, 2024
1 parent 3a98526 commit c06dd46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/aigues_barcelona/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/duhow/hass-aigues-barcelona/issues",
"requirements": [],
"version": "0.4.6"
"version": "0.4.7"
}
5 changes: 3 additions & 2 deletions custom_components/aigues_barcelona/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ async def _async_update_data(self):
previous = datetime.fromisoformat(self._data.get(CONF_STATE, ""))
# FIX: TypeError: can't subtract offset-naive and offset-aware datetimes
previous = previous.replace(tzinfo=None)
LAST_TIME_DAYS = (TODAY - previous).days
if previous:
LAST_TIME_DAYS = (TODAY - previous).days
except ValueError:
previous = None

Expand Down Expand Up @@ -188,7 +189,7 @@ async def _async_update_data(self):
except:
pass

if LAST_TIME_DAYS >= 7:
if LAST_TIME_DAYS and LAST_TIME_DAYS >= 7:
await self.import_old_consumptions(days=LAST_TIME_DAYS)

return True
Expand Down

0 comments on commit c06dd46

Please sign in to comment.