Skip to content

Commit

Permalink
Handle connection errors more gracefully
Browse files Browse the repository at this point in the history
Fixes #41
  • Loading branch information
jjlawren committed Jan 10, 2023
1 parent 2455c8c commit 4775c9c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions custom_components/sonos_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN][SESSION] = session

url = "https://api.ws.sonos.com/control/api/v1/households"
result = await session.async_request("get", url)
try:
result = await session.async_request("get", url)
except OSError as exc:
_LOGGER.error("Connection error requesting households: %s", exc)
raise ConfigEntryNotReady from exc

if result.status >= 400:
body = await result.text()
_LOGGER.error(
Expand All @@ -87,7 +92,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

async def async_get_available_players(household: str) -> list[dict]:
url = f"https://api.ws.sonos.com/control/api/v1/households/{household}/groups"
result = await session.async_request("get", url)
try:
result = await session.async_request("get", url)
except OSError as exc:
_LOGGER.error("Connection error requesting players: %s", exc)
raise ConfigEntryNotReady from exc
if result.status >= 400:
body = await result.text()
_LOGGER.error(
Expand Down

0 comments on commit 4775c9c

Please sign in to comment.