From a496a7c7927a6edefa8ee83c4579722dd986219e Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 16 Feb 2017 16:13:33 +0100 Subject: [PATCH] Protect device_tracker scan interval / TTS logging (#6041) * Protect device_tracker scan interval / TTS logging * clear pass --- .../components/device_tracker/__init__.py | 15 ++++++++++++--- homeassistant/components/tts/__init__.py | 5 +++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py index 01f0dbaccc9..d4a80358f02 100644 --- a/homeassistant/components/device_tracker/__init__.py +++ b/homeassistant/components/device_tracker/__init__.py @@ -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,7 +656,14 @@ 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.""" - found_devices = yield from scanner.async_scan_devices() + 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: if mac in seen: diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 9d31667cc14..5673e61e16b 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -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 = {}