mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Limit observations requested for NWS (#90137)
* fetch data only for 70 minutes * Use timezone aware now * Type hint Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
b58c90602f
commit
c06bc28434
@ -26,6 +26,7 @@ from .const import (
|
|||||||
COORDINATOR_OBSERVATION,
|
COORDINATOR_OBSERVATION,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
NWS_DATA,
|
NWS_DATA,
|
||||||
|
UPDATE_TIME_PERIOD,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -110,11 +111,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
nws_data = SimpleNWS(latitude, longitude, api_key, client_session)
|
nws_data = SimpleNWS(latitude, longitude, api_key, client_session)
|
||||||
await nws_data.set_station(station)
|
await nws_data.set_station(station)
|
||||||
|
|
||||||
|
async def update_observation() -> None:
|
||||||
|
"""Retrieve recent observations."""
|
||||||
|
await nws_data.update_observation(start_time=utcnow() - UPDATE_TIME_PERIOD)
|
||||||
|
|
||||||
coordinator_observation = NwsDataUpdateCoordinator(
|
coordinator_observation = NwsDataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
name=f"NWS observation station {station}",
|
name=f"NWS observation station {station}",
|
||||||
update_method=nws_data.update_observation,
|
update_method=update_observation,
|
||||||
update_interval=DEFAULT_SCAN_INTERVAL,
|
update_interval=DEFAULT_SCAN_INTERVAL,
|
||||||
failed_update_interval=FAILED_SCAN_INTERVAL,
|
failed_update_interval=FAILED_SCAN_INTERVAL,
|
||||||
request_refresh_debouncer=debounce.Debouncer(
|
request_refresh_debouncer=debounce.Debouncer(
|
||||||
|
@ -82,3 +82,5 @@ COORDINATOR_FORECAST_HOURLY = "coordinator_forecast_hourly"
|
|||||||
|
|
||||||
OBSERVATION_VALID_TIME = timedelta(minutes=20)
|
OBSERVATION_VALID_TIME = timedelta(minutes=20)
|
||||||
FORECAST_VALID_TIME = timedelta(minutes=45)
|
FORECAST_VALID_TIME = timedelta(minutes=45)
|
||||||
|
# A lot of stations update once hourly plus some wiggle room
|
||||||
|
UPDATE_TIME_PERIOD = timedelta(minutes=70)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user