mirror of
https://github.com/natekspencer/hacs-oasis_mini.git
synced 2025-12-06 18:44:14 -05:00
Ensure update_tracks closes the connection
This commit is contained in:
@@ -30,20 +30,23 @@ def get_author_name(data: dict) -> str:
|
|||||||
|
|
||||||
async def update_tracks() -> None:
|
async def update_tracks() -> None:
|
||||||
"""
|
"""
|
||||||
Fetch tracks from the Grounded Labs cloud, detect new or changed public tracks compared to the local TRACKS mapping, augment changed entries with author and reduced SVG content, and persist the merged, sorted track list to custom_components/oasis_mini/pyoasiscontrol/tracks.json.
|
Fetch tracks from the Grounded Labs cloud, detect new or changed public tracks
|
||||||
|
compared to the local TRACKS mapping, augment changed entries with author and
|
||||||
|
reduced SVG content, and persist the merged, sorted track list to
|
||||||
|
`custom_components/oasis_mini/pyoasiscontrol/tracks.json`.
|
||||||
|
|
||||||
Side effects:
|
Side effects:
|
||||||
- May print error or status messages to stdout.
|
- May print error or status messages to stdout.
|
||||||
- Writes the updated tracks JSON file.
|
- Writes the updated tracks JSON file.
|
||||||
- Ensures the OasisCloudClient session is closed and returns early on errors or unexpected data.
|
- Ensures the OasisCloudClient session is closed and returns early on errors or
|
||||||
|
unexpected data.
|
||||||
"""
|
"""
|
||||||
client = OasisCloudClient(access_token=ACCESS_TOKEN)
|
client = OasisCloudClient(access_token=ACCESS_TOKEN)
|
||||||
|
try:
|
||||||
try:
|
try:
|
||||||
data = await client.async_get_tracks()
|
data = await client.async_get_tracks()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
print(type(ex).__name__, ex)
|
print(type(ex).__name__, ex)
|
||||||
await client.session.close()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if not isinstance(data, list):
|
if not isinstance(data, list):
|
||||||
@@ -70,7 +73,8 @@ async def update_tracks() -> None:
|
|||||||
"reduced_svg_content_new"
|
"reduced_svg_content_new"
|
||||||
)
|
)
|
||||||
updated_tracks[track_id] = result
|
updated_tracks[track_id] = result
|
||||||
await client.session.close()
|
finally:
|
||||||
|
await client.async_close()
|
||||||
|
|
||||||
if not updated_tracks:
|
if not updated_tracks:
|
||||||
print("No updated tracks")
|
print("No updated tracks")
|
||||||
|
|||||||
Reference in New Issue
Block a user