Skip to content
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
15 changes: 15 additions & 0 deletions pychromecast/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
# Cast Audio group device, supports only audio
CAST_TYPE_GROUP = "group"

MF_GOOGLE = "Google Inc."

CAST_TYPES = {
"chromecast audio": (CAST_TYPE_AUDIO, MF_GOOGLE),
"chromecast": (CAST_TYPE_CHROMECAST, MF_GOOGLE),
"eureka dongle": (CAST_TYPE_CHROMECAST, MF_GOOGLE),
"google cast group": (CAST_TYPE_GROUP, MF_GOOGLE),
"google home mini": (CAST_TYPE_AUDIO, MF_GOOGLE),
"google home": (CAST_TYPE_AUDIO, MF_GOOGLE),
"google nest hub": (CAST_TYPE_CHROMECAST, MF_GOOGLE),
"google nest mini": (CAST_TYPE_AUDIO, MF_GOOGLE),
"lenovocd-24502f": (CAST_TYPE_AUDIO, "LENOVO"),
"nest audio": (CAST_TYPE_AUDIO, MF_GOOGLE),
}

SERVICE_TYPE_HOST = "host"
SERVICE_TYPE_MDNS = "mdns"

Expand Down
16 changes: 11 additions & 5 deletions pychromecast/dial.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _get_status(services, zconf, path, secure, timeout, context):
req = urllib.request.Request(url, headers=headers)
with urllib.request.urlopen(req, timeout=timeout, context=context) as response:
data = response.read()
return json.loads(data.decode("utf-8"))
return (host, json.loads(data.decode("utf-8")))


def get_ssl_context():
Expand All @@ -116,9 +116,10 @@ def get_cast_type(cast_info, zconf=None, timeout=30, context=None):
cast_type = CAST_TYPE_GROUP
manufacturer = "Google Inc."
else:
host = "<unknown>"
try:
display_supported = True
status = _get_status(
host, status = _get_status(
cast_info.services,
zconf,
"/setup/eureka_info?params=device_info,name",
Expand All @@ -143,7 +144,12 @@ def get_cast_type(cast_info, zconf=None, timeout=30, context=None):
OSError,
ValueError,
) as err:
_LOGGER.warning("Failed to determine cast type (%s)", err)
_LOGGER.warning(
"Failed to determine cast type for host %s (%s) (services:%s)",
host,
err,
cast_info.services,
)
cast_type = CAST_TYPE_CHROMECAST

return CastInfo(
Expand Down Expand Up @@ -171,7 +177,7 @@ def get_device_info( # pylint: disable=too-many-locals
try:
if services is None:
services = [ServiceInfo(SERVICE_TYPE_HOST, (host, 8009))]
status = _get_status(
_, status = _get_status(
services,
zconf,
"/setup/eureka_info?params=device_info,name",
Expand Down Expand Up @@ -251,7 +257,7 @@ def get_multizone_status(host, services=None, zconf=None, timeout=30, context=No
try:
if services is None:
services = [ServiceInfo(SERVICE_TYPE_HOST, (host, 8009))]
status = _get_status(
_, status = _get_status(
services,
zconf,
"/setup/eureka_info?params=multizone",
Expand Down
9 changes: 7 additions & 2 deletions pychromecast/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from .const import (
CAST_TYPE_AUDIO,
CAST_TYPE_GROUP,
CAST_TYPES,
MF_GOOGLE,
SERVICE_TYPE_HOST,
SERVICE_TYPE_MDNS,
)
Expand Down Expand Up @@ -206,8 +208,11 @@ def get_value(key):

# Lock because the HostBrowser may also add or remove items
with self._services_lock:
cast_type = CAST_TYPE_GROUP if service.port != 8009 else None
manufacturer = "Google Inc." if service.port != 8009 else None
if service.port != 8009:
cast_type = CAST_TYPE_GROUP
manufacturer = MF_GOOGLE
else:
cast_type, manufacturer = CAST_TYPES.get(model_name.lower(), None, None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get only takes 2 arguments and this are 3.

if uuid not in self._devices:
self._devices[uuid] = CastInfo(
{service_info},
Expand Down