Skip to content

Commit

Permalink
Protect device_tracker scan interval / TTS logging (home-assistant#6041)
Browse files Browse the repository at this point in the history
* Protect device_tracker scan interval / TTS logging

* clear pass
  • Loading branch information
pvizeli authored and balloob committed Feb 16, 2017
1 parent 714ba31 commit a496a7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 12 additions & 3 deletions homeassistant/components/device_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def async_setup_platform(p_type, p_config, disc_info=None):

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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/tts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ def remove_files():
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 = {}
Expand Down

0 comments on commit a496a7c

Please sign in to comment.