Skip to content

Commit 965dd7c

Browse files
FredrikM97edenhaus
authored andcommitted
Catch exception from libsoundtouch if device not available (home-assistant#155749)
Co-authored-by: Robert Resch <[email protected]>
1 parent 9a921f2 commit 965dd7c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

homeassistant/components/soundtouch/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
from libsoundtouch import soundtouch_device
66
from libsoundtouch.device import SoundTouchDevice
7+
import requests
78
import voluptuous as vol
89

910
from homeassistant.config_entries import ConfigEntry
1011
from homeassistant.const import CONF_HOST, Platform
1112
from homeassistant.core import HomeAssistant, ServiceCall
13+
from homeassistant.exceptions import ConfigEntryNotReady
1214
from homeassistant.helpers import config_validation as cv
1315
from homeassistant.helpers.typing import ConfigType
1416

@@ -130,7 +132,14 @@ async def service_handle(service: ServiceCall) -> None:
130132

131133
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
132134
"""Set up Bose SoundTouch from a config entry."""
133-
device = await hass.async_add_executor_job(soundtouch_device, entry.data[CONF_HOST])
135+
try:
136+
device = await hass.async_add_executor_job(
137+
soundtouch_device, entry.data[CONF_HOST]
138+
)
139+
except requests.exceptions.ConnectionError as err:
140+
raise ConfigEntryNotReady(
141+
f"Unable to connect to SoundTouch device at {entry.data[CONF_HOST]}"
142+
) from err
134143

135144
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = SoundTouchData(device)
136145

0 commit comments

Comments
 (0)