Skip to content

Commit 5396cda

Browse files
committed
Handle when no services exists
1 parent b9759d9 commit 5396cda

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pychromecast/dial.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import zeroconf
1818

1919
from .const import CAST_TYPE_AUDIO, CAST_TYPE_CHROMECAST, CAST_TYPE_GROUP
20-
from .error import ZeroConfInstanceRequired
20+
from .error import ZeroConfInstanceRequired, ResolveHostFailed
2121
from .models import ZEROCONF_ERRORS, CastInfo, HostServiceInfo, MDNSServiceInfo
2222

2323
XML_NS_UPNP_DEVICE = "{urn:schemas-upnp-org:device-1-0}"
@@ -112,6 +112,8 @@ def _get_status(
112112
if host:
113113
_LOGGER.debug("Resolved service %s to %s", service, host)
114114
break
115+
else:
116+
raise ResolveHostFailed("Unable to find host to read status from.")
115117

116118
if secure:
117119
url = FORMAT_BASE_URL_HTTPS.format(host) + path
@@ -175,6 +177,7 @@ def get_cast_type(
175177
urllib.error.URLError,
176178
OSError,
177179
ValueError,
180+
ResolveHostFailed,
178181
) as err:
179182
_LOGGER.warning(
180183
"Failed to determine cast type for host %s (%s) (services:%s)",

pychromecast/error.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,9 @@ def __init__(self, request: str, timeout: float) -> None:
6060
super().__init__(self.MSG.format(request=request, timeout=timeout))
6161

6262

63+
class ResolveHostFailed(PyChromecastError):
64+
"""Raised when library is unable to resolve a name into an connectable address."""
65+
66+
6367
class ZeroConfInstanceRequired(PyChromecastError):
6468
"""Raised when a zeroconf instance is required."""

0 commit comments

Comments
 (0)