mirror of
https://github.com/natekspencer/hacs-oasis_mini.git
synced 2025-12-06 18:44:14 -05:00
Adjust exceptions
This commit is contained in:
@@ -110,10 +110,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: OasisDeviceConfigEntry)
|
||||
|
||||
coordinator = OasisDeviceCoordinator(hass, cloud_client, mqtt_client)
|
||||
|
||||
try:
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
except Exception as ex:
|
||||
_LOGGER.exception(ex)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
if entry.unique_id != (user_id := str(user["id"])):
|
||||
hass.config_entries.async_update_entry(entry, unique_id=user_id)
|
||||
@@ -132,7 +129,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: OasisDeviceConfigEntry)
|
||||
coordinator.last_updated = dt_util.now()
|
||||
coordinator.async_update_listeners()
|
||||
|
||||
for device in coordinator.data:
|
||||
for device in coordinator.data or []:
|
||||
device.add_update_listener(_on_oasis_update)
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
@@ -171,8 +168,8 @@ async def async_remove_entry(
|
||||
cloud_client = create_client(hass, entry.data)
|
||||
try:
|
||||
await cloud_client.async_logout()
|
||||
except Exception as ex:
|
||||
_LOGGER.exception(ex)
|
||||
except Exception:
|
||||
_LOGGER.exception("Error attempting to logout from the cloud")
|
||||
await cloud_client.async_close()
|
||||
|
||||
|
||||
|
||||
@@ -179,8 +179,8 @@ class OasisDeviceConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
errors["base"] = "invalid_auth"
|
||||
except HTTPStatusError as err:
|
||||
errors["base"] = str(err)
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
_LOGGER.error(ex)
|
||||
except Exception:
|
||||
_LOGGER.exception("Error while attempting to validate client")
|
||||
errors["base"] = "unknown"
|
||||
finally:
|
||||
await client.async_close()
|
||||
|
||||
@@ -117,7 +117,7 @@ class OasisDeviceCoordinator(DataUpdateCoordinator[list[OasisDevice]]):
|
||||
# Best-effort playlists
|
||||
try:
|
||||
await self.cloud_client.async_get_playlists()
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
_LOGGER.exception("Error fetching playlists from cloud")
|
||||
|
||||
any_success = False
|
||||
@@ -145,7 +145,7 @@ class OasisDeviceCoordinator(DataUpdateCoordinator[list[OasisDevice]]):
|
||||
any_success = True
|
||||
device.schedule_track_refresh()
|
||||
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
_LOGGER.exception(
|
||||
"Error preparing Oasis device %s", device.serial_number
|
||||
)
|
||||
|
||||
@@ -234,8 +234,8 @@ class OasisCloudClient:
|
||||
raise
|
||||
except UnauthenticatedError:
|
||||
raise
|
||||
except Exception as ex: # noqa: BLE001
|
||||
_LOGGER.exception("Error fetching track %s: %s", track_id, ex)
|
||||
except Exception:
|
||||
_LOGGER.exception("Error fetching track %s: %s", track_id)
|
||||
return None
|
||||
|
||||
async def async_get_tracks(
|
||||
|
||||
@@ -136,7 +136,7 @@ class OasisHttpClient(OasisClientProtocol):
|
||||
mac = await self._async_get(params={"GETMAC": ""})
|
||||
if isinstance(mac, str):
|
||||
return mac.strip()
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
_LOGGER.exception(
|
||||
"Failed to get MAC address via HTTP for %s", device.serial_number
|
||||
)
|
||||
|
||||
@@ -288,7 +288,7 @@ class OasisMqttClient(OasisClientProtocol):
|
||||
try:
|
||||
first_status_event.clear()
|
||||
await self.async_get_status(device)
|
||||
except Exception:
|
||||
except Exception: # noqa: BLE001
|
||||
_LOGGER.debug(
|
||||
"Could not request status for %s (not fully connected yet?)",
|
||||
serial,
|
||||
@@ -428,8 +428,8 @@ class OasisMqttClient(OasisClientProtocol):
|
||||
Change the device's current track to the specified track index.
|
||||
|
||||
Parameters:
|
||||
device (OasisDevice): Target Oasis device.
|
||||
index (int): Track index to switch to (zero-based).
|
||||
device (OasisDevice): Target Oasis device.
|
||||
index (int): Track index to switch to (zero-based).
|
||||
"""
|
||||
payload = f"CMDCHANGETRACK={index}"
|
||||
await self._publish_command(device, payload)
|
||||
@@ -605,7 +605,7 @@ class OasisMqttClient(OasisClientProtocol):
|
||||
topic = f"{serial}/COMMAND/CMD"
|
||||
_LOGGER.debug("Flushing queued MQTT command %s => %s", topic, payload)
|
||||
await self._client.publish(topic, payload.encode(), qos=1)
|
||||
except Exception:
|
||||
except Exception: # noqa: BLE001
|
||||
_LOGGER.debug(
|
||||
"Failed to flush queued command for %s, re-queuing", serial
|
||||
)
|
||||
@@ -651,7 +651,7 @@ class OasisMqttClient(OasisClientProtocol):
|
||||
try:
|
||||
_LOGGER.debug("MQTT publish %s => %s", topic, payload)
|
||||
await self._client.publish(topic, payload.encode(), qos=1)
|
||||
except Exception:
|
||||
except Exception: # noqa: BLE001
|
||||
_LOGGER.debug(
|
||||
"MQTT publish failed, queueing command for %s: %s", serial, payload
|
||||
)
|
||||
@@ -698,7 +698,7 @@ class OasisMqttClient(OasisClientProtocol):
|
||||
|
||||
except asyncio.CancelledError:
|
||||
break
|
||||
except Exception:
|
||||
except Exception: # noqa: BLE001
|
||||
_LOGGER.info("MQTT connection error")
|
||||
|
||||
finally:
|
||||
@@ -818,7 +818,7 @@ class OasisMqttClient(OasisClientProtocol):
|
||||
status_name,
|
||||
payload,
|
||||
)
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
_LOGGER.exception(
|
||||
"Error parsing MQTT payload for %s %s: %r", serial, status_name, payload
|
||||
)
|
||||
|
||||
@@ -305,7 +305,7 @@ class OasisDevice:
|
||||
if n > 18:
|
||||
status["software_version"] = values[18]
|
||||
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
_LOGGER.exception(
|
||||
"Error parsing status string for %s: %r", self.serial_number, raw_status
|
||||
)
|
||||
@@ -487,7 +487,7 @@ class OasisDevice:
|
||||
for listener in list(self._listeners):
|
||||
try:
|
||||
listener()
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
_LOGGER.exception("Error in update listener")
|
||||
|
||||
async def async_get_mac_address(self) -> str | None:
|
||||
@@ -751,7 +751,7 @@ class OasisDevice:
|
||||
|
||||
try:
|
||||
track = await self._cloud.async_get_track_info(track_id)
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
_LOGGER.exception("Error fetching track info for %s", track_id)
|
||||
return
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ def _parse_int(val: str) -> int:
|
||||
"""
|
||||
try:
|
||||
return int(val)
|
||||
except Exception:
|
||||
except Exception: # noqa: BLE001
|
||||
return 0
|
||||
|
||||
|
||||
@@ -169,8 +169,8 @@ def create_svg(track: dict, progress: int) -> str | None:
|
||||
)
|
||||
|
||||
return tostring(svg).decode()
|
||||
except Exception as e:
|
||||
_LOGGER.exception(e)
|
||||
except Exception:
|
||||
_LOGGER.exception("Error creating svg")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user