Skip to content

Commit

Permalink
Properly set update_interval during Speedtest setup (#37708)
Browse files Browse the repository at this point in the history
* Properly set update_interval during setup

* implement new update_interval method
  • Loading branch information
engrbm87 authored and balloob committed Jul 14, 2020
1 parent 39d5fb8 commit 0d58048
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions homeassistant/components/speedtestdotnet/__init__.py
Expand Up @@ -105,16 +105,14 @@ def __init__(self, hass, config_entry):
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."""
Expand Down Expand Up @@ -189,12 +187,11 @@ async def request_update(call):

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()

0 comments on commit 0d58048

Please sign in to comment.