From 4fb0b27310375f4809d8875b7d5d268013aadd66 Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello <tchello.mello@gmail.com> Date: Thu, 27 Oct 2016 02:31:49 -0400 Subject: [PATCH] Wunderground sensor with alerts exceeds API limits (#4070) * Fixes issue #4067 - Wunderground sensor with alerts exceeds API limits To avoid hitting the max limit of 500 calls per day, this patch keeps weather conditions being updated each 5 minutes and weather advisories each 15 minutes. This formula will result the following: conditions -> 300 seconds -> 5 minutes -> 12 req/h -> 288 req/day alerts -> 900 seconds -> 15 minutes -> 4 req/h -> 96 req/day * Using timedelta in minutes instead seconds --- homeassistant/components/sensor/wunderground.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/sensor/wunderground.py b/homeassistant/components/sensor/wunderground.py index 7abc2a0fc1e..98a06c7545a 100644 --- a/homeassistant/components/sensor/wunderground.py +++ b/homeassistant/components/sensor/wunderground.py @@ -25,7 +25,8 @@ _LOGGER = logging.getLogger(__name__) CONF_ATTRIBUTION = "Data provided by the WUnderground weather service" CONF_PWS_ID = 'pws_id' -MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=300) +MIN_TIME_BETWEEN_UPDATES_ALERTS = timedelta(minutes=15) +MIN_TIME_BETWEEN_UPDATES_OBSERVATION = timedelta(minutes=5) # Sensor types are defined like: Name, units SENSOR_TYPES = { @@ -187,7 +188,7 @@ class WUndergroundData(object): return url + '.json' - @Throttle(MIN_TIME_BETWEEN_UPDATES) + @Throttle(MIN_TIME_BETWEEN_UPDATES_OBSERVATION) def update(self): """Get the latest data from WUnderground.""" try: @@ -202,7 +203,7 @@ class WUndergroundData(object): self.data = None raise - @Throttle(MIN_TIME_BETWEEN_UPDATES) + @Throttle(MIN_TIME_BETWEEN_UPDATES_ALERTS) def update_alerts(self): """Get the latest alerts data from WUnderground.""" try: -- GitLab