Skip to content

Add REST API support with backward-compatible auto detection#454

Open
espipj wants to merge 12 commits intoiMicknl:mainfrom
espipj:feat/new-API-support
Open

Add REST API support with backward-compatible auto detection#454
espipj wants to merge 12 commits intoiMicknl:mainfrom
espipj:feat/new-API-support

Conversation

@espipj
Copy link

@espipj espipj commented Feb 22, 2026

Summary

This PR adds support for newer Sagemcom firmware that exposes /api/v1/* endpoints, while preserving compatibility with legacy /cgi/json-req firmware.

What Changed

  • Added ApiMode enum:
    • ApiMode.AUTO (default)
    • ApiMode.LEGACY
    • ApiMode.REST
  • Extended SagemcomClient with api_mode parameter.
  • Implemented API mode selection logic in login():
    • LEGACY: force legacy flow
    • REST: force REST flow
    • AUTO: try legacy first, fallback to REST when legacy endpoint appears unavailable.
  • Added REST request path for:
    • login() via POST /api/v1/login (form-encoded)
    • logout() via POST /api/v1/logout
    • get_device_info() via GET /api/v1/device
    • get_hosts() via GET /api/v1/home
  • Kept legacy behavior for XPath-based methods; these now raise clear NotImplementedError in REST mode.

Backward Compatibility

  • Existing usage remains compatible.
  • Default mode is AUTO, so legacy users do not need to change code.
  • Explicit mode can be set when deterministic behavior is required.

Tests

  • Added unit test for AUTO fallback to REST on legacy 503 HTML response.
  • Added unit test for REST get_hosts() parsing (wireless + ethernet devices).

Documentation

  • README updated with:
    • ApiMode usage in quickstart
    • API mode behavior and REST/legacy limitations

@espipj espipj requested a review from iMicknl as a code owner February 22, 2026 01:02
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.

1 participant