mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Clean up fastdotcom by doing time tracking outside of the data object (#20725)
This commit is contained in:
parent
1fe67fb1b0
commit
ec625f02fc
@ -41,9 +41,12 @@ CONFIG_SCHEMA = vol.Schema({
|
|||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the Fast.com component."""
|
"""Set up the Fast.com component."""
|
||||||
conf = config[DOMAIN]
|
conf = config[DOMAIN]
|
||||||
data = hass.data[DOMAIN] = SpeedtestData(
|
data = hass.data[DOMAIN] = SpeedtestData(hass)
|
||||||
hass, conf[CONF_UPDATE_INTERVAL], conf[CONF_MANUAL]
|
|
||||||
)
|
if not conf[CONF_MANUAL]:
|
||||||
|
async_track_time_interval(
|
||||||
|
hass, data.update, conf[CONF_UPDATE_INTERVAL]
|
||||||
|
)
|
||||||
|
|
||||||
def update(call=None):
|
def update(call=None):
|
||||||
"""Service call to manually update the data."""
|
"""Service call to manually update the data."""
|
||||||
@ -61,14 +64,12 @@ async def async_setup(hass, config):
|
|||||||
class SpeedtestData:
|
class SpeedtestData:
|
||||||
"""Get the latest data from fast.com."""
|
"""Get the latest data from fast.com."""
|
||||||
|
|
||||||
def __init__(self, hass, interval, manual):
|
def __init__(self, hass):
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
self.data = None
|
self.data = None
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
if not manual:
|
|
||||||
async_track_time_interval(self._hass, self.update, interval)
|
|
||||||
|
|
||||||
def update(self):
|
def update(self, now=None):
|
||||||
"""Get the latest data from fast.com."""
|
"""Get the latest data from fast.com."""
|
||||||
from fastdotcom import fast_com
|
from fastdotcom import fast_com
|
||||||
_LOGGER.debug("Executing fast.com speedtest")
|
_LOGGER.debug("Executing fast.com speedtest")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user