Skip to content

Commit

Permalink
Fixed issue where days until did not pull new data
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderBlom committed Dec 30, 2023
1 parent dffea01 commit ba69aee
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion custom_components/bir/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,14 @@ def _calculate_days_until_pickup(self) -> int:
"""Calculate the days until the next waste collection."""
today = datetime.now().date()
pickup_date_obj = datetime.strptime(self._date, "%Y-%m-%d").date()
return (pickup_date_obj - today).days
delta = (pickup_date_obj - today).days
return max(delta, 0) # Prevent negative values

async def async_update(self) -> None:
"""Update the sensor state (days until pickup)."""
data = await get_dates(self._session, self._url)
if data and self._waste_type in data:
new_date = data[self._waste_type]
if new_date != self._date:
self._date = new_date

0 comments on commit ba69aee

Please sign in to comment.