Protect device_tracker scan interval / TTS logging (#6041)

* Protect device_tracker scan interval / TTS logging

* clear pass
pull/4006/merge
Pascal Vizeli 2017-02-16 16:13:33 +01:00 committed by Paulus Schoutsen
parent 714ba31b75
commit a496a7c792
2 changed files with 15 additions and 5 deletions

View File

@ -168,7 +168,7 @@ def async_setup(hass: HomeAssistantType, config: ConfigType):
if scanner:
async_setup_scanner_platform(
hass, p_config, scanner, tracker.async_see)
hass, p_config, scanner, tracker.async_see, p_type)
return
if not setup:
@ -640,12 +640,14 @@ def async_load_config(path: str, hass: HomeAssistantType,
@callback
def async_setup_scanner_platform(hass: HomeAssistantType, config: ConfigType,
scanner: Any, async_see_device: Callable):
scanner: Any, async_see_device: Callable,
platform: str):
"""Helper method to connect scanner-based platform to device tracker.
This method must be run in the event loop.
"""
interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
update_lock = asyncio.Lock(loop=hass.loop)
scanner.hass = hass
# Initial scan of each mac we also tell about host name for config
@ -654,6 +656,13 @@ def async_setup_scanner_platform(hass: HomeAssistantType, config: ConfigType,
@asyncio.coroutine
def async_device_tracker_scan(now: dt_util.dt.datetime):
"""Called when interval matches."""
if update_lock.locked():
_LOGGER.warning(
"Updating device list from %s took longer than the scheduled "
"scan interval %s", platform, interval)
return
with (yield from update_lock):
found_devices = yield from scanner.async_scan_devices()
for mac in found_devices:

View File

@ -247,8 +247,9 @@ class SpeechManager(object):
for _, filename in self.file_cache.items():
try:
os.remove(os.path.join(self.cache_dir, filename))
except OSError:
pass
except OSError as err:
_LOGGER.warning(
"Can't remove cache file '%s': %s", filename, err)
yield from self.hass.loop.run_in_executor(None, remove_files)
self.file_cache = {}