Skip to content

Improve error handling and add comprehensive client tests#2007

Merged
iMicknl merged 4 commits intov2/mainfrom
v2/error_handling
Apr 19, 2026
Merged

Improve error handling and add comprehensive client tests#2007
iMicknl merged 4 commits intov2/mainfrom
v2/error_handling

Conversation

@iMicknl
Copy link
Copy Markdown
Owner

@iMicknl iMicknl commented Apr 19, 2026

Summary

  • Fix get_current_execution crashing on empty responses (cloud returns {}, local returns [] or null)
  • Make ActionGroup.id and ActionGroup.oid optional (str | None) — inline action groups from exec/current don't carry identifiers
  • Add start_time, execution_type, and execution_sub_type fields to Execution model (matching real API responses)
  • Change Execution.state from str to ExecutionState enum (consistent with HistoryExecution)
  • Add NoSuchDeviceError and NoSuchActionGroupError exception types with response handler mappings
  • Add 8 new cloud exception fixture tests and 6 new cloud exception JSON fixtures
  • Add 13 cloud client tests covering executions, history, state, places, action groups, and event listeners
  • Add 10 local API tests verifying proper error handling for KizOs gateway differences

Breaking changes

  • Execution.state is now ExecutionState instead of str, ActionGroup.id and ActionGroup.oid are now str | None instead of str, get_current_execution now returns Execution | None instead of Execution

Test plan

  • All 311 unit tests pass
  • All prek checks pass (ruff, mypy, ty)
  • Validated against real Somfy cloud API (37/37 probes pass)
  • Validated against real local KizOs gateway (37/37 probes pass)
  • JSON fixtures verified against real API response structures

iMicknl added 2 commits April 19, 2026 21:38
- Update `get_current_execution` method to return None for non-existent executions.
- Add new exceptions: NoSuchDeviceError and NoSuchActionGroupError.
- Introduce error handling probes in `test_error_handling.py` for various invalid inputs.
- Add test cases for empty responses and specific error scenarios in `test_client.py`.
- Create JSON fixtures for various error responses to improve testing coverage.
Copilot AI review requested due to automatic review settings April 19, 2026 19:39
@iMicknl iMicknl requested a review from tetienne as a code owner April 19, 2026 19:39
@iMicknl iMicknl added v2 enhancement New feature or request labels Apr 19, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves robustness of Overkiz client error/edge-case handling (notably executions and missing resources), aligns execution parsing with real API payloads, and adds broad unit-test coverage plus a real-API probing script.

Changes:

  • Make get_current_execution() resilient to empty/invalid “not found” payloads by returning None.
  • Extend/align models and error mapping: Execution gains timing/type fields and uses ExecutionState; add NoSuchDeviceError / NoSuchActionGroupError; allow inline ActionGroup objects without identifiers.
  • Add many new unit tests + JSON fixtures for cloud/local differences, plus a probe script to validate error handling against real endpoints.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyoverkiz/client.py Returns None for empty/non-dict exec/current/{id} responses to prevent crashes.
pyoverkiz/models.py Aligns Execution/ActionGroup parsing with observed API payloads; adds execution metadata fields and enum state.
pyoverkiz/response_handler.py Maps NO_SUCH_DEVICE / NO_SUCH_ACTION_GROUP to new dedicated exceptions.
pyoverkiz/exceptions.py Introduces NoSuchDeviceError and NoSuchActionGroupError.
tests/test_client.py Adds comprehensive tests for executions, history, places, state parsing, action execution, and local-gateway error variants.
tests/fixtures/** Adds endpoint and exception JSON fixtures used by new tests.
scripts/test_error_handling.py Adds a probe tool to validate error handling behavior against real cloud/local APIs.

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

Comment thread pyoverkiz/client.py
Comment thread tests/test_client.py Outdated
@iMicknl iMicknl merged commit 9f4acfa into v2/main Apr 19, 2026
6 checks passed
@iMicknl iMicknl deleted the v2/error_handling branch April 19, 2026 19:51
@iMicknl iMicknl mentioned this pull request Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking enhancement New feature or request v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants