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