diff --git a/homeassistant/components/wiz/__init__.py b/homeassistant/components/wiz/__init__.py index abdbbf1191a..9a4444c523e 100644 --- a/homeassistant/components/wiz/__init__.py +++ b/homeassistant/components/wiz/__init__.py @@ -5,7 +5,6 @@ import logging from typing import Any from pywizlight import wizlight -from pywizlight.exceptions import WizLightNotKnownBulb from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, Platform @@ -16,7 +15,13 @@ from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed -from .const import DISCOVER_SCAN_TIMEOUT, DISCOVERY_INTERVAL, DOMAIN, WIZ_EXCEPTIONS +from .const import ( + DISCOVER_SCAN_TIMEOUT, + DISCOVERY_INTERVAL, + DOMAIN, + WIZ_CONNECT_EXCEPTIONS, + WIZ_EXCEPTIONS, +) from .discovery import async_discover_devices, async_trigger_discovery from .models import WizData @@ -48,7 +53,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: try: scenes = await bulb.getSupportedScenes() await bulb.getMac() - except (WizLightNotKnownBulb, *WIZ_EXCEPTIONS) as err: + except WIZ_CONNECT_EXCEPTIONS as err: raise ConfigEntryNotReady(f"{ip_address}: {err}") from err async def _async_update() -> None: diff --git a/homeassistant/components/wiz/config_flow.py b/homeassistant/components/wiz/config_flow.py index aa564a14f33..924e88793e4 100644 --- a/homeassistant/components/wiz/config_flow.py +++ b/homeassistant/components/wiz/config_flow.py @@ -15,7 +15,7 @@ from homeassistant.const import CONF_HOST from homeassistant.data_entry_flow import AbortFlow, FlowResult from homeassistant.util.network import is_ip_address -from .const import DEFAULT_NAME, DISCOVER_SCAN_TIMEOUT, DOMAIN, WIZ_EXCEPTIONS +from .const import DEFAULT_NAME, DISCOVER_SCAN_TIMEOUT, DOMAIN, WIZ_CONNECT_EXCEPTIONS from .discovery import async_discover_devices from .utils import _short_mac, name_from_bulb_type_and_mac @@ -70,7 +70,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): bulb = wizlight(device.ip_address) try: bulbtype = await bulb.get_bulbtype() - except WIZ_EXCEPTIONS as ex: + except WIZ_CONNECT_EXCEPTIONS as ex: raise AbortFlow("cannot_connect") from ex self._name = name_from_bulb_type_and_mac(bulbtype, device.mac_address) @@ -110,7 +110,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): bulb = wizlight(device.ip_address) try: bulbtype = await bulb.get_bulbtype() - except WIZ_EXCEPTIONS: + except WIZ_CONNECT_EXCEPTIONS: return self.async_abort(reason="cannot_connect") else: return self.async_create_entry( diff --git a/homeassistant/components/wiz/const.py b/homeassistant/components/wiz/const.py index e1a98482635..d1b3a0f6251 100644 --- a/homeassistant/components/wiz/const.py +++ b/homeassistant/components/wiz/const.py @@ -1,7 +1,11 @@ """Constants for the WiZ Platform integration.""" from datetime import timedelta -from pywizlight.exceptions import WizLightConnectionError, WizLightTimeOutError +from pywizlight.exceptions import ( + WizLightConnectionError, + WizLightNotKnownBulb, + WizLightTimeOutError, +) DOMAIN = "wiz" DEFAULT_NAME = "WiZ" @@ -16,3 +20,4 @@ WIZ_EXCEPTIONS = ( WizLightConnectionError, ConnectionRefusedError, ) +WIZ_CONNECT_EXCEPTIONS = (WizLightNotKnownBulb, *WIZ_EXCEPTIONS)