1
0
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:
Nathan Spencer
2025-11-24 04:06:42 +00:00
parent 1cc3585653
commit e4f6cd2803
8 changed files with 106 additions and 109 deletions

View File

@@ -30,29 +30,29 @@ def _bit_to_bool(val: str) -> bool:
def _parse_int(val: str) -> int:
"""
Parse a string into an integer, falling back to 0 when conversion fails.
Parameters:
val (str): String potentially containing an integer value.
Returns:
int: The parsed integer, or 0 if `val` cannot be converted.
"""
try:
return int(val)
except Exception:
except Exception: # noqa: BLE001
return 0
def create_svg(track: dict, progress: int) -> str | None:
"""
Create an SVG visualization of a track showing progress as a completed path and indicator.
Builds an SVG representation from the track's "svg_content" and the provided progress value. If progress is supplied, the function will decrypt the stored SVG content (if needed), compute which path segments are complete using the track's optional "reduced_svg_content_new" value or the number of path segments, and render a base arc, completed arc, track, completed track segment, background circle, and a ball indicator positioned at the current progress point. Returns None if input is missing or an error occurs.
Parameters:
track (dict): Track data containing at minimum an "svg_content" entry and optionally "reduced_svg_content_new" to indicate total segments.
progress (int): Current progress expressed as a count relative to the track's total segments.
Returns:
str | None: Serialized SVG markup as a UTF-8 string when successful, otherwise `None`.
"""
@@ -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
@@ -200,4 +200,4 @@ def decrypt_svg_content(svg_content: dict[str, str]):
def now() -> datetime:
return datetime.now(UTC)
return datetime.now(UTC)