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

Reduce discovery timeout #69

Merged
merged 2 commits into from
Apr 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions glocaltokens/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ACCESS_TOKEN_DURATION,
ACCESS_TOKEN_SERVICE,
ANDROID_ID_LENGTH,
DISCOVERY_TIMEOUT,
GOOGLE_HOME_FOYER_API,
HOMEGRAPH_DURATION,
JSON_KEY_DEVICE_NAME,
Expand Down Expand Up @@ -336,6 +337,7 @@ def get_google_devices(
disable_discovery: bool = False,
zeroconf_instance=None,
force_homegraph_reload: bool = False,
discovery_timeout: int = DISCOVERY_TIMEOUT,
) -> List[Device]:
"""
Returns a list of google devices with their local authentication tokens,
Expand All @@ -347,6 +349,7 @@ def get_google_devices(
zeroconf_instance: If you already have an initialized zeroconf instance,
use it here.
force_homegraph_reload: If the stored homegraph should be generated again.
discovery_timeout: Timeout for zeroconf discovery in seconds.
"""

# Set models_list to empty list if None
Expand All @@ -365,6 +368,7 @@ def get_google_devices(
LOGGER.debug("Getting network devices...")
network_devices = discover_devices(
models_list,
timeout=discovery_timeout,
zeroconf_instance=zeroconf_instance,
logging_level=self.logging_level,
)
Expand Down
3 changes: 2 additions & 1 deletion glocaltokens/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

HOMEGRAPH_DURATION = 24 * 60 * 60

DISCOVER_TIMEOUT = 20
DISCOVERY_TIMEOUT = 2

GOOGLE_HOME_MODELS = [
"Google Home",
"Google Home Mini",
Expand Down
10 changes: 5 additions & 5 deletions glocaltokens/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from zeroconf import ServiceListener

from .const import DISCOVER_TIMEOUT
from .const import DISCOVERY_TIMEOUT
from .utils import network as net_utils, types as type_utils

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -126,7 +126,7 @@ def __str__(self) -> str:
def discover_devices(
models_list: Optional[List[str]] = None,
max_devices: int = None,
timeout: int = DISCOVER_TIMEOUT,
timeout: int = DISCOVERY_TIMEOUT,
zeroconf_instance=None,
logging_level=logging.ERROR,
):
Expand All @@ -141,10 +141,10 @@ def discover_devices(
def callback():
"""Called when zeroconf has discovered a new chromecast."""
if max_devices is not None and listener.count >= max_devices:
discover_complete.set()
discovery_complete.set()

LOGGER.debug("Creating new Event for discovery completion...")
discover_complete = Event()
discovery_complete = Event()
LOGGER.debug("Creating new CastListener...")
listener = CastListener(callback)
if not zeroconf_instance:
Expand All @@ -158,7 +158,7 @@ def callback():

# Wait for the timeout or the maximum number of devices
LOGGER.debug("Waiting for discovery completion...")
discover_complete.wait(timeout)
discovery_complete.wait(timeout)

devices = []
LOGGER.debug("Got %s devices. Iterating...", len(listener.devices))
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ ipdb = "^0.13.7"
"Bug Tracker" = "https://github.com/leikoilja/glocaltokens/issues"
"Release Notes" = "https://github.com/leikoilja/glocaltokens/releases"

[tool.pylint.master]
extension-pkg-whitelist = [
"_socket",
]

[tool.pylint.format]
max-line-length = 88
min-similarity-lines = 7
Expand Down