Properly set update_interval during Speedtest setup (#37708)

* Properly set update_interval during setup

* implement new update_interval method
pull/37836/head
Rami Mosleh 2020-07-13 22:32:22 +03:00 committed by Paulus Schoutsen
parent 39d5fb82e5
commit 0d58048cea
1 changed files with 12 additions and 15 deletions

View File

@ -105,16 +105,14 @@ class SpeedTestDataCoordinator(DataUpdateCoordinator):
self.api = None
self.servers = {}
super().__init__(
self.hass,
_LOGGER,
name=DOMAIN,
update_method=self.async_update,
update_interval=timedelta(
self.hass, _LOGGER, name=DOMAIN, update_method=self.async_update,
)
if not self.config_entry.options.get(CONF_MANUAL):
self.update_interval = timedelta(
minutes=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
)
),
)
)
def update_servers(self):
"""Update list of test servers."""
@ -189,12 +187,11 @@ class SpeedTestDataCoordinator(DataUpdateCoordinator):
async def options_updated_listener(hass, entry):
"""Handle options update."""
if not entry.options[CONF_MANUAL]:
hass.data[DOMAIN].update_interval = timedelta(
minutes=entry.options[CONF_SCAN_INTERVAL]
)
await hass.data[DOMAIN].async_request_refresh()
if entry.options[CONF_MANUAL]:
hass.data[DOMAIN].update_interval = None
return
# set the update interval to a very long time
# if the user wants to disable auto update
hass.data[DOMAIN].update_interval = timedelta(days=7)
hass.data[DOMAIN].update_interval = timedelta(
minutes=entry.options[CONF_SCAN_INTERVAL]
)
await hass.data[DOMAIN].async_request_refresh()