Repository navigation
feat: async client, SignalR user hub, live control and typed errors - #11
Merged
Merged
Conversation
Bring the SDK up to the C# SDK's feature set and beyond.
- Add AsyncOpenShockClient / AsyncOpenShockHubClient. The sync client is now
generated from the async code by scripts/unasync.py (checked in CI).
- Add openshock.realtime (optional 'realtime' extra, asyncio only):
UserHubClient for the SignalR user hub and LiveControlClient for the live
control gateway, sharing a reconnecting WebSocket transport.
- Parse problem details into typed exceptions (ShockerPaused, HubOffline,
TokenPermissionMissing, ...). OpenShockAuthError and OpenShockNotFound are
now subclasses of OpenShockApiError.
- Replace string aliases with real enums that still compare equal to their
wire strings and tolerate unknown backend values.
- Send a descriptive User-Agent including app_name / app_version.
- Add devices.gateway() for GET /2/devices/{id}/lcg.
- Fix devices.create(), devices.pair_code() and account.create_token(), which
parsed responses the backend does not send.
- Return typed models from shockers.list_own/list_shared/get/all_logs and
UUIDs from methods that create things. Remove the PairCode model.
- Add tests for every REST method, the hub and live control (against
in-process fake servers), four standalone examples, and a rewritten README.
- Bump version to 0.2.0b1.
Replace the hand-written REST resources and models with a client generated by openapi-python-client from a committed snapshot of the backend's OpenAPI document (scripts/generate.py, checked in CI). BREAKING: REST calls now go through openshock.rest.api.*, Python 3.10 is no longer supported, and httpx is replaced by httpx2.
- refuse concurrent start(), let stop() abort a connection attempt - bind each event dispatcher to its own queue; bound dispatcher shutdown - honour allowReconnect for a close sent with the SignalR handshake - reject non-finite hold_for in live control - redact credentials in URLs put into exception messages - tolerate a malformed problem status; ASCII-only User-Agent fields - pin example requirements; make pure-Python install skip pip's cache - replace fixed sleeps in live control tests with observed ticks
…ient The SDK authenticates with API tokens or a hub's device token. Operations tagged Admin and operations that only accept the browser session cookie are removed from the OpenAPI document before generation, together with the models only they used (134 -> 75 operations).
…rated client" This reverts commit 47d5d4d.
|
Important Review skippedToo many files! This PR contains 235 files, which is 135 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This organization's CodeRabbit subscription is cancelled. Resubscribe in Billing to continue reviews beyond the free-tier limit.
|
Contributor
Author
|
This branch depends on OpenShock/API#419 to drastically reduce amount of code generated |
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.
Brings the Python SDK up to the C# SDK's feature set (and covers the rest of the user hub), and fixes a few REST methods that could not work against the current backend.
Added
AsyncOpenShockClient/AsyncOpenShockHubClient, same resources and methods as the sync clients. The sync client is now generated from the async code byscripts/unasync.py; CI fails if the two drift.openshock.realtime.UserHubClientcontrol,set_captive_portal,emergency_stop,ota_install,rebootopenshock.realtime.LiveControlClientintake_frame()feeds a tick loop at the gateway-announced rate; handles ping/pong, latency, and rejection responsesShockerPaused,ShockerNoPermission,ShockerNotFoundOrNoAccess,HubOffline,HubNotFound,TokenPermissionMissing,ApiTokenPaused,OpenShockRateLimited)ControlType,ShockerModelType,PermissionType, ...) that still compare equal to their wire strings and do not raise on values the SDK does not know yetapp_name/app_versionclient.devices.gateway()forGET /2/devices/{id}/lcgexamples/, and a rewritten READMERealtime is asyncio-only and behind an optional extra:
pip install "openshock[realtime]"(addswebsockets). The SignalR client is a small in-house implementation of the JSON protocol with negotiation skipped, sharing its reconnecting transport with live control.Fixed
devices.create()parsed the response as an object; the backend returns a bare IDdevices.pair_code()did the same; the backend returns the code as a stringaccount.create_token()readcreatedOnwhere the backend sendscreatedAt, and dropped the token secretBreaking changes from 0.1.0b1
shockers.list_own(),list_shared(),get()andall_logs()return typed models instead of dictsstrnow returnUUIDshockers.control()returnsNone; the pause methods return the new stateOpenShockAuthErrorandOpenShockNotFoundare now subclasses ofOpenShockApiError, soexceptorder mattersPairCodeis removedShareInfo.shared_withis aBasicUserInforather than a dictVersion is bumped to
0.2.0b1.Notes for review
UserHubClient, becauseOpenShockHubClientalready means the device-token REST client in this SDK. The C# SDK uses that name for the SignalR client.websocketsclient cannot parse. The transport repeats such a failure as a plain GET so a bad token is reported asOpenShockAuthErrorrather than a network error.openshock/_sync/is generated. Reviewopenshock/_async/instead.Testing
websockets13.0 and latest;ruffand strictmypyare cleanNot yet verified against production with a real token: receiving hub events and sending live control frames.
examples/realtime_eventsandexamples/live_controlare the quickest way to check both.Summary by CodeRabbit