summaryrefslogtreecommitdiff
path: root/smart_home/chromecasts.py
diff options
context:
space:
mode:
authorScott <[email protected]>2022-01-18 15:18:21 -0800
committerScott <[email protected]>2022-01-18 15:18:21 -0800
commit1315e2d5356aa3616ef96ded72b7902c8591ebd7 (patch)
tree6a68fe7bfab486f787f5f28cf11998c5af574670 /smart_home/chromecasts.py
parent07a9659282a6b7c7776eec85f0708de9f8815374 (diff)
Don't let chromecasts steal the thread for too long.
Diffstat (limited to 'smart_home/chromecasts.py')
-rw-r--r--smart_home/chromecasts.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/smart_home/chromecasts.py b/smart_home/chromecasts.py
index 5e11ac0..7480cec 100644
--- a/smart_home/chromecasts.py
+++ b/smart_home/chromecasts.py
@@ -5,7 +5,6 @@
import atexit
import datetime
import logging
-import time
import pychromecast
@@ -29,7 +28,11 @@ class BaseChromecast(dev.Device):
or (now - BaseChromecast.refresh_ts).total_seconds() > 60
):
logger.debug('Refreshing the shared chromecast info list')
- BaseChromecast.ccasts, BaseChromecast.browser = pychromecast.get_chromecasts()
+ if BaseChromecast.browser is not None:
+ BaseChromecast.browser.stop_discovery()
+ BaseChromecast.ccasts, BaseChromecast.browser = pychromecast.get_chromecasts(
+ timeout=10.0
+ )
atexit.register(BaseChromecast.browser.stop_discovery)
BaseChromecast.refresh_ts = now
@@ -38,8 +41,7 @@ class BaseChromecast(dev.Device):
if cc.cast_info.host == ip:
logger.debug(f'Found chromecast at {ip}: {cc}')
self.cast = cc
- self.cast.wait()
- time.sleep(0.1)
+ self.cast.wait(timeout=1.0)
if self.cast is None:
raise Exception(f'Can\'t find ccast device at {ip}, is that really a ccast device?')