Clean up fastdotcom by doing time tracking outside of the data object (#20725)

This commit is contained in:
Rohan Kapoor 2019-02-03 22:43:59 -08:00 committed by GitHub
parent 1fe67fb1b0
commit ec625f02fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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")