1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Catch exception from libsoundtouch if device not available (#155749)

Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Fredrik Mårtensson
2025-11-04 10:24:38 +01:00
committed by GitHub
parent 1c5f7adf4e
commit 5012aa5cb0

View File

@@ -4,11 +4,13 @@ import logging
from libsoundtouch import soundtouch_device
from libsoundtouch.device import SoundTouchDevice
import requests
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, Platform
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
@@ -130,7 +132,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Bose SoundTouch from a config entry."""
device = await hass.async_add_executor_job(soundtouch_device, entry.data[CONF_HOST])
try:
device = await hass.async_add_executor_job(
soundtouch_device, entry.data[CONF_HOST]
)
except requests.exceptions.ConnectionError as err:
raise ConfigEntryNotReady(
f"Unable to connect to SoundTouch device at {entry.data[CONF_HOST]}"
) from err
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = SoundTouchData(device)