@dynamiccontrols/cloud-integration-server
v0.1.0
Published
A TypeScript-based framework for building cloud integration servers for Dynamic Controls Home Automation System.
Readme
Cloud Integration Server
A TypeScript-based framework for building cloud integration servers for Dynamic Controls Home Automation System.
Usage
Extending the CloudIntegrationServer
Create a new class that extends CloudIntegrationServer and implement the abstract methods:
import { CloudIntegrationServer, LoggerInterface, CloudIntegrationServerOptions, type Context } from './src/cloudIntegrationServer';
import type { ExecuteRequestPayload, ExecuteResponsePayload, SyncResponsePayload } from './src/types';
class MyIntegrationServer extends CloudIntegrationServer {
constructor(logger: LoggerInterface, options: CloudIntegrationServerOptions) {
super(logger, options);
}
async handleExecute(request: ExecuteRequestPayload, context: Context): Promise<ExecuteResponsePayload> {
// Implement your EXECUTE logic here
// Handle device executions and optionally report state changes
return { status: 'SUCCESS' };
}
async handleSync(context: Context): Promise<SyncResponsePayload> {
// Implement your SYNC logic here
// Return device information for synchronization
return {
agentUserId: 'user-id',
devices: []
};
}
}Starting the Server
const logger: LoggerInterface = {
info: (message, meta) => console.log(message, meta),
error: (message, meta) => console.error(message, meta)
};
const options: CloudIntegrationServerOptions = {
port: 3000,
path: '/api/integration',
reportStateUrl: 'https://api.example.com/report-state',
apiKey: 'your-api-key'
};
const server = new MyIntegrationServer(logger, options);
await server.start();Methods
handleExecute(request, context)
Abstract method to handle EXECUTE requests. Implement device control logic here.
handleSync(context)
Abstract method to handle SYNC requests. Return device information for synchronization.
reportState(userId, payload)
Report device state changes to the configured report state URL.
Configuration
The server requires the following configuration options:
port: Server port numberpath: API endpoint pathreportStateUrl: URL for reporting state changesapiKey: API key for authentication when reporting state changes
Development
Building
npm run buildTesting
npm run build:test
npm test