Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix waze_travel_time component ERROR on startup #20316

Merged
merged 10 commits into from Feb 6, 2019
14 changes: 10 additions & 4 deletions homeassistant/components/sensor/waze_travel_time.py
Expand Up @@ -5,6 +5,7 @@
https://home-assistant.io/components/sensor.waze_travel_time/
"""
from datetime import timedelta
from homeassistant.util import Throttle
import logging

import voluptuous as vol
Expand Down Expand Up @@ -39,7 +40,7 @@

REGIONS = ['US', 'NA', 'EU', 'IL', 'AU']

SCAN_INTERVAL = timedelta(minutes=5)
VirtualL marked this conversation as resolved.
Show resolved Hide resolved
CONF_UPDATE_INTERVAL = 'update_interval'

TRACKABLE_DOMAINS = ['device_tracker', 'sensor', 'zone']

Expand All @@ -51,6 +52,8 @@
vol.Optional(CONF_INCL_FILTER): cv.string,
vol.Optional(CONF_EXCL_FILTER): cv.string,
vol.Optional(CONF_REALTIME, default=DEFAULT_REALTIME): cv.boolean,
vol.Optional(CONF_UPDATE_INTERVAL, default=timedelta(minutes=5)):
VirtualL marked this conversation as resolved.
Show resolved Hide resolved
vol.All(cv.time_period, cv.positive_timedelta),
})


Expand All @@ -63,11 +66,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
incl_filter = config.get(CONF_INCL_FILTER)
excl_filter = config.get(CONF_EXCL_FILTER)
realtime = config.get(CONF_REALTIME)
update_interval = config.get(CONF_UPDATE_INTERVAL)

sensor = WazeTravelTime(name, origin, destination, region,
incl_filter, excl_filter, realtime)
incl_filter, excl_filter, realtime,
VirtualL marked this conversation as resolved.
Show resolved Hide resolved
update_interval)

add_entities([sensor])
add_entities([sensor], True)
VirtualL marked this conversation as resolved.
Show resolved Hide resolved

# Wait until start event is sent to load this component.
hass.bus.listen_once(
Expand All @@ -84,7 +89,7 @@ class WazeTravelTime(Entity):
"""Representation of a Waze travel time sensor."""

def __init__(self, name, origin, destination, region,
incl_filter, excl_filter, realtime):
incl_filter, excl_filter, realtime, interval):
VirtualL marked this conversation as resolved.
Show resolved Hide resolved
"""Initialize the Waze travel time sensor."""
self._name = name
self._region = region
Expand All @@ -94,6 +99,7 @@ def __init__(self, name, origin, destination, region,
self._state = None
self._origin_entity_id = None
self._destination_entity_id = None
self.update = Throttle(interval)(self.update)
VirtualL marked this conversation as resolved.
Show resolved Hide resolved

if origin.split('.', 1)[0] in TRACKABLE_DOMAINS:
self._origin_entity_id = origin
Expand Down