Refactor/dedupe api response checks - #25
Merged
Merged
Conversation
There was a problem hiding this comment.
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 plusrequire_parsed/require_datasemantics. - Replace ad-hoc response checks across tools/podcast/notes/music/devices with calls to
_ensure_ok. - Introduce
Light._device_tool_items()andLight._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.
Owner
Author
|
Closes #24 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_ensure_okto validtae API responses instead of manually putting all those checks in everywhere.