diff --git a/pychromecast/const.py b/pychromecast/const.py index cff9f556e..3aec9c084 100644 --- a/pychromecast/const.py +++ b/pychromecast/const.py @@ -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" diff --git a/pychromecast/dial.py b/pychromecast/dial.py index 1be1650cd..32dfae2ed 100644 --- a/pychromecast/dial.py +++ b/pychromecast/dial.py @@ -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(): @@ -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 = "" try: display_supported = True - status = _get_status( + host, status = _get_status( cast_info.services, zconf, "/setup/eureka_info?params=device_info,name", @@ -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( @@ -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", @@ -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", diff --git a/pychromecast/discovery.py b/pychromecast/discovery.py index 625d33074..673bd6d7f 100644 --- a/pychromecast/discovery.py +++ b/pychromecast/discovery.py @@ -12,6 +12,8 @@ from .const import ( CAST_TYPE_AUDIO, CAST_TYPE_GROUP, + CAST_TYPES, + MF_GOOGLE, SERVICE_TYPE_HOST, SERVICE_TYPE_MDNS, ) @@ -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) if uuid not in self._devices: self._devices[uuid] = CastInfo( {service_info},