Fix recollect_waste month time boundary issue (#99429)

pull/99545/head
Mike O'Driscoll 2023-09-03 11:08:17 -04:00 committed by GitHub
parent 186e796e25
commit c297eecb68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -1,7 +1,7 @@
"""The ReCollect Waste integration.""" """The ReCollect Waste integration."""
from __future__ import annotations from __future__ import annotations
from datetime import timedelta from datetime import date, timedelta
from typing import Any from typing import Any
from aiorecollect.client import Client, PickupEvent from aiorecollect.client import Client, PickupEvent
@ -31,7 +31,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_get_pickup_events() -> list[PickupEvent]: async def async_get_pickup_events() -> list[PickupEvent]:
"""Get the next pickup.""" """Get the next pickup."""
try: try:
return await client.async_get_pickup_events() # Retrieve today through to 35 days in the future, to get
# coverage across a full two months boundary so that no
# upcoming pickups are missed. The api.recollect.net base API
# call returns only the current month when no dates are passed.
# This ensures that data about when the next pickup is will be
# returned when the next pickup is the first day of the next month.
# Ex: Today is August 31st, tomorrow is a pickup on September 1st.
today = date.today()
return await client.async_get_pickup_events(
start_date=today,
end_date=today + timedelta(days=35),
)
except RecollectError as err: except RecollectError as err:
raise UpdateFailed( raise UpdateFailed(
f"Error while requesting data from ReCollect: {err}" f"Error while requesting data from ReCollect: {err}"