Fix uncaught exception during WiZ discovery during firmware update (#66358)

This commit is contained in:
J. Nick Koston 2022-02-11 20:42:41 -06:00 committed by GitHub
parent 366609ea44
commit 578456bbb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -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:

View File

@ -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(

View File

@ -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)