Skip to content

Refactor/dedupe api response checks - #25

Merged
garado merged 9 commits into
devfrom
refactor/dedupe-api-response-checks
Jul 30, 2026
Merged

Refactor/dedupe api response checks#25
garado merged 9 commits into
devfrom
refactor/dedupe-api-response-checks

Conversation

@garado

@garado garado commented Jul 30, 2026

Copy link
Copy Markdown
Owner
  • Helper for shared for device_tool/phone lookups.
  • Added a generic _ensure_ok to validtae API responses instead of manually putting all those checks in everywhere.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors repeated API response validation logic into a shared Light._ensure_ok helper and centralizes shared /api/devices “included” parsing (device-tool items + SIM phone numbers) into reusable helpers on Light. This reduces duplicated status/parsed/data checks across the various feature modules while keeping endpoint-specific behavior explicit via ok_codes, require_parsed, and require_data.

Changes:

  • Add Light._ensure_ok() and unit tests covering status-code handling plus require_parsed/require_data semantics.
  • Replace ad-hoc response checks across tools/podcast/notes/music/devices with calls to _ensure_ok.
  • Introduce Light._device_tool_items() and Light._device_phone_numbers() to share device-tool and SIM parsing logic.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_api.py Adds focused unit tests for the new _ensure_ok helper.
light_api/light_api/client.py Introduces _ensure_ok and new helpers for parsing /api/devices included items.
light_api/light_api/tools.py Replaces manual response checks with _ensure_ok and reuses shared included-item iteration.
light_api/light_api/podcast.py Refactors response validation to _ensure_ok with appropriate status code sets.
light_api/light_api/notes.py Refactors response validation to _ensure_ok (including 200/201/204 cases).
light_api/light_api/music.py Refactors response validation to _ensure_ok including broad 2xx success handling.
light_api/light_api/devices.py Refactors device listing validation and SIM phone extraction to shared helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@garado
garado merged commit 6c706d2 into dev Jul 30, 2026
2 checks passed
@garado

garado commented Jul 30, 2026

Copy link
Copy Markdown
Owner Author

Closes #24

@garado
garado deleted the refactor/dedupe-api-response-checks branch July 30, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants