feat: REST API to list surfaces and set brightness - #4405
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughChangesThe REST API now exposes typed surface listing and brightness update endpoints. Surface routes are mounted through the controller and registered in OpenAPI. Shared error responses replace the connection API’s local definition. Tests cover authorization, validation, page mapping, and surface state errors. Surface REST API
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
0ab6e13 to
dbd22ee
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d3977468-1b42-4ce6-a952-ac9578664446
📒 Files selected for processing (8)
companion/lib/Instance/Connection/ConnectionsRestApi.tscompanion/lib/Service/RestApi/RestApiRouter.tscompanion/lib/Service/RestApi/openapi.tscompanion/lib/Service/RestApi/schemas/common.tscompanion/lib/Surface/Controller.tscompanion/lib/Surface/SurfacesRestApi.tscompanion/test/Instance/Connection/ConnectionsRestApi.test.tscompanion/test/Surface/SurfacesRestApi.test.ts
There was a problem hiding this comment.
Pull request overview
Adds a new Surfaces resource to the v2 REST API, enabling external systems (e.g. automations/Home Assistant) to query surface state and set brightness via scoped bearer-token auth, with OpenAPI registration.
Changes:
- Added
GET /api/v2/surfaces/v1to list all known surfaces and their current state (incl. page context). - Added
PATCH /api/v2/surfaces/v1/:surfaceIdto set brightness for a connected surface. - Centralized shared OpenAPI error response definitions (
errorResponses) for reuse across resources, and registered the new resource in OpenAPI generation.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| companion/test/Surface/SurfacesRestApi.test.ts | New e2e-style router tests for listing surfaces and patching brightness (auth + error cases). |
| companion/test/Instance/Connection/ConnectionsRestApi.test.ts | Updates REST API router test registry wiring to include the new surfaces resource. |
| companion/lib/Surface/SurfacesRestApi.ts | Implements surfaces REST router, zod schemas, endpoint specs, and OpenAPI path registration. |
| companion/lib/Surface/Controller.ts | Exposes createRestApiRouter() on SurfaceController to mount the surfaces REST resource via the registry. |
| companion/lib/Service/RestApi/schemas/common.ts | Adds shared errorResponses definition for OpenAPI endpoint specs. |
| companion/lib/Service/RestApi/RestApiRouter.ts | Mounts the new surfaces router under the v2 REST API base path. |
| companion/lib/Service/RestApi/openapi.ts | Registers surfaces endpoints into the generated OpenAPI document. |
| companion/lib/Instance/Connection/ConnectionsRestApi.ts | Switches connections resource to reuse the shared errorResponses definition. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Adds a
surfacesresource to the REST API from #4259:GET /api/v2/surfaces/v1lists all known surfaces with their state (name, connection, size, brightness and current page), andPATCH /api/v2/surfaces/v1/:surfaceIdsets the brightness of a connected surface. Replaces #4293, which added the same thing to the legacy/apirouter, as suggested there.Use cases:
errorResponsesmoved fromConnectionsRestApi.tstoRestApi/schemas/common.tsso both resources share one definition, the generated spec for connections is unchanged.Two things I would like a view on:
read/writerather than a resource scope likeconnections. Surfaces hold no secrets and there is no token UI yet, so asurfacesscope felt speculative.openapi-stable.jsonis not regenerated yet. The change is additive so the compatibility test passes, and I would rather freeze the contract once the response shape is agreed. Happy to add that commit before merge.Tested end to end against a Stream Deck + and a Stream Deck Network Dock.
Related to #1964, #4266 and #4273.
Summary by CodeRabbit
New Features
Bug Fixes