The API follows a specific sequence of events to establish communication and receive device updates:
- Connection & Versioning: Upon connection, the server immediately sends a
version message containing driver and server versions, as well as the supported minSchemaVersion and maxSchemaVersion. - Schema Negotiation: The client should ideally send a
set_api_schema command to specify which API version it wants to use. If omitted, the server defaults to the minimum supported schema (currently 0). - Start Listening: To receive device states and events, the client must send the
start_listening command. - State Initialization: After
start_listening, the server responds with a result message containing the current state (driver info, stations, and devices) and begins streaming real-time events for any state changes.
// 1. Server sends version on connect
// { type: "version", driverVersion: "...", serverVersion: "...", minSchemaVersion: 0, maxSchemaVersion: 13 }
// 2. Client sets schema (optional but recommended)
// { command: "set_api_schema", messageId: 1, schemaVersion: 1 }
// 3. Client starts listening for events
// { messageId: "unique-id", command: "start_listening" }
// 4. Server responds with initial state
// { type: "result", messageId: "unique-id", success: true, result: { state: { ... } } }