Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 13 additions & 38 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,26 @@
## [3.0.0]
## [5.1.0]

### Features

* feat: Replaced the old sdk with a new sdk

## [2.6.1]

### Features

* **Custom device types support**
* **SR_DEBUG to support debug logs**

## [2.7.1]

### Features
* **Push notification feature added**

## [2.8.1]
* feat: Camera support.
feat: Implemented example applications for various device types including Camera, PowerSensor, Device Settings, Module Settings, and Temperature Sensor.

## [2.9.1]
fix: missing mac in Websocket header.

### Features
* fix: setThermostatMode
fix: missing settings, push-notification controller in Switch.

## [2.10.1]
fix: missing instance id.

### Features
* fix: adjustTargetTemperature
fix: missing scope when responding back to server.

## [2.11.1]
## [5.0.0]

### Features
* fix: targetTemperature

## [2.11.2]
* BREAKING CHANGE: feat: remove restoreDeviceStates in order to change this at device level from server side instead of fixed value in client
* Camera, PowerSensor, Switch, TemperatureSensor examples added.
* Missing capabilities added.
* instanceId support for Mode and Range

### Features
* fix: adjustTargetTemperature response format.

## [2.11.4]
## [4.0.0]

### Features
* fix: power on, off event

## [2.12.1]

### Features
* fix: error message when sending an event while connection not established yet
* feat: add onConnected callback
* feat: Replaced the old sdk with a new sdk
105 changes: 105 additions & 0 deletions examples/camera/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* SinricPro Camera Example
*
* This example demonstrates:
* - Connecting to SinricPro
* - Creating a camera device
* - Handling power state changes
* - Sending events when state changes locally
*/

import SinricPro from 'sinricpro';
import { SinricProCamera } from 'sinricpro';
import { SinricProSdkLogger, LogLevel } from 'sinricpro';

// Configuration - Replace with your credentials
const SWITCH_ID = 'YOUR-DEVICE-ID'; // 24-character hex
const APP_KEY = 'YOUR-APP-KEY'; // UUID format
const APP_SECRET = 'YOUR-APP-SECRET'; // Long secret key

// Simulated device state
let devicePowerState = false;

async function main() {
// Enable debug logging
SinricProSdkLogger.setLevel(LogLevel.ERROR);

console.log('='.repeat(60));
console.log('SinricPro Camera Example');
console.log('='.repeat(60));

// Create camera device
const myCamera = SinricProCamera(SWITCH_ID);

// Set up power state callback
myCamera.onPowerState(async (deviceId: string, state: boolean) => {
console.log(`\n[Callback] Device ${deviceId} turned ${state ? 'ON' : 'OFF'}`);

// Update local state
devicePowerState = state;

// Here you would control actual hardware
// For example: GPIO.write(LED_PIN, state);

return true; // Return true if successful
});

// Add device to SinricPro
SinricPro.add(myCamera);

// Connection event handlers
SinricPro.onConnected(() => {
console.log('\n✓ Connected to SinricPro!');
console.log(' You can now control the device via Alexa or Google Home');
});

SinricPro.onDisconnected(() => {
console.log('\n✗ Disconnected from SinricPro');
});

SinricPro.onPong((latency) => {
console.log(`\n♥ Heartbeat (latency: ${latency}ms)`);
});

// Initialize SinricPro
await SinricPro.begin({
appKey: APP_KEY,
appSecret: APP_SECRET,
});

// Simulate local button press every 30 seconds
setInterval(async () => {
devicePowerState = !devicePowerState;
console.log(`\n[Local Event] Button pressed - turning ${devicePowerState ? 'ON' : 'OFF'}`);
const success = await myCamera.sendPowerStateEvent(devicePowerState);

if (success) {
console.log(' ✓ Event sent to SinricPro server');
} else {
console.log(' ✗ Failed to send event (rate limited or not connected)');
}
}, 60000);

console.log('\nWaiting for commands ...');
console.log('Press Ctrl+C to exit\n');
}

// Handle graceful shutdown
process.on('SIGINT', async () => {
console.log('\n\nShutting down...');
await SinricPro.stop();
console.log('Goodbye!\n');
process.exit(0);
});

// Handle unhandled errors
process.on('unhandledRejection', (error) => {
console.error('Unhandled error:', error);
process.exit(1);
});

// Run the example
main().catch((error) => {
console.error('Fatal error:', error);
process.exit(1);
});
182 changes: 182 additions & 0 deletions examples/customdevice/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/**
* SinricPro Custom Device Example
*
* Demonstrates how to use SinricProCustomDevice to create flexible devices
* with any combination of capabilities you need.
*/

import SinricPro from 'sinricpro';
import { SinricProCustomDevice } from 'sinricpro';
import { SinricProSdkLogger, LogLevel } from 'sinricpro';

// Configuration - Replace with your credentials
const DEVICE_ID = 'YOUR-DEVICE-ID'; // 24-character hex
const APP_KEY = 'YOUR-APP-KEY'; // UUID format
const APP_SECRET = 'YOUR-APP-SECRET'; // Long secret key

// Device state
const deviceState = {
power: false,
brightness: 0,
temperature: 22.0,
color: { r: 255, g: 255, b: 255 },
};

async function main() {
SinricProSdkLogger.setLevel(LogLevel.ERROR);

console.log('='.repeat(70));
console.log('SinricPro Custom Device Example');
console.log('='.repeat(70));
console.log('\nThis example demonstrates a custom device that combines:');
console.log(' - Power control (on/off)');
console.log(' - Brightness control (0-100%)');
console.log(' - Color control (RGB)');
console.log(' - Color temperature control');
console.log(' - Range control (generic values)');
console.log(' - Mode control');
console.log(' - Temperature sensor (reporting)');
console.log(' - Thermostat control');
console.log(' - Lock control');
console.log(' - Settings control');
console.log('\nYou can mix and match any capabilities you need!');
console.log('='.repeat(70));

// Create custom device
// You can use any product_type from your SinricPro portal
const customDevice = SinricProCustomDevice(DEVICE_ID, 'CUSTOM_DEVICE');

// Register callbacks for capabilities you want to use
// You only need to register the ones you'll actually use!

// Power control
customDevice.onPowerState(async (deviceId, state) => {
deviceState.power = state;
console.log(`\n[Power] Device ${deviceId} turned ${state ? 'ON' : 'OFF'}`);
return true;
});

// Brightness control
customDevice.onBrightness(async (deviceId, brightness) => {
deviceState.brightness = brightness;
console.log(`\n[Brightness] Set to ${brightness}%`);
return true;
});

customDevice.onAdjustBrightness(async (deviceId, brightnessDelta) => {
const newBrightness = Math.max(0, Math.min(100, deviceState.brightness + brightnessDelta));
deviceState.brightness = newBrightness;
console.log(`\n[Brightness] Adjusted by ${brightnessDelta} to ${newBrightness}%`);
return true;
});

// Color control
customDevice.onColor(async (deviceId, r, g, b) => {
deviceState.color = { r, g, b };
console.log(`\n[Color] Set to RGB(${r}, ${g}, ${b})`);
return true;
});

// Color temperature control
customDevice.onColorTemperature(async (deviceId, colorTemperature) => {
console.log(`\n[Color Temperature] Set to ${colorTemperature}K`);
return true;
});

// Range control (generic)
customDevice.onRangeValue(async (deviceId, rangeValue, instanceId) => {
if (instanceId) {
console.log(`\n[Range] Instance '${instanceId}' set to ${rangeValue}`);
} else {
console.log(`\n[Range] Set to ${rangeValue}`);
}
return true;
});

customDevice.onAdjustRangeValue(async (deviceId, rangeValueDelta, instanceId) => {
if (instanceId) {
console.log(`\n[Range] Instance '${instanceId}' adjusted by ${rangeValueDelta}`);
} else {
console.log(`\n[Range] Adjusted by ${rangeValueDelta}`);
}
return true;
});

// Mode control
customDevice.onSetMode(async (deviceId, mode, instanceId) => {
if (instanceId) {
console.log(`\n[Mode] Instance '${instanceId}' set to '${mode}'`);
} else {
console.log(`\n[Mode] Set to '${mode}'`);
}
return true;
});

// Thermostat control
customDevice.onTargetTemperature(async (deviceId, temperature) => {
deviceState.temperature = temperature;
console.log(`\n[Thermostat] Target temperature set to ${temperature}°C`);
return true;
});

customDevice.onThermostatMode(async (deviceId, mode) => {
console.log(`\n[Thermostat] Mode set to ${mode}`);
return true;
});

// Lock control
customDevice.onLockState(async (deviceId, state) => {
console.log(`\n[Lock] State set to ${state}`);
return true;
});

// Settings control
customDevice.onSetting(async (deviceId, settingId, value) => {
console.log(`\n[Setting] ${settingId} = ${JSON.stringify(value)}`);
return true;
});

// Add device to SinricPro
SinricPro.add(customDevice);

// Connection event handlers
SinricPro.onConnected(() => {
console.log('\n✓ Connected to SinricPro!');
console.log(' Custom device is ready.');
});

SinricPro.onDisconnected(() => {
console.log('\n✗ Disconnected from SinricPro');
});

// Initialize SinricPro
await SinricPro.begin({
appKey: APP_KEY,
appSecret: APP_SECRET,
});

console.log('\n' + '='.repeat(70));
console.log('Waiting for commands...');
console.log('Press Ctrl+C to exit');
console.log('='.repeat(70) + '\n');
}

// Handle graceful shutdown
process.on('SIGINT', async () => {
console.log('\n\nShutting down...');
await SinricPro.stop();
console.log('Goodbye!\n');
process.exit(0);
});

// Handle unhandled errors
process.on('unhandledRejection', (error) => {
console.error('Unhandled error:', error);
process.exit(1);
});

// Run the example
main().catch((error) => {
console.error('Fatal error:', error);
process.exit(1);
});
4 changes: 2 additions & 2 deletions examples/fan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function main() {
});

// Speed control (0-100)
myFan.onRangeValue(async (deviceId, speed) => {
myFan.onRangeValue(async (deviceId, speed, instanceId) => {
console.log(`\n[Fan Speed] Device ${deviceId} Set to ${speed}%`);
// Map speed to fan levels: 0=off, 1-33=low, 34-66=medium, 67-100=high
let level;
Expand All @@ -44,7 +44,7 @@ async function main() {
return true;
});

myFan.onAdjustRangeValue(async (deviceId, delta) => {
myFan.onAdjustRangeValue(async (deviceId, delta, instanceId) => {
console.log(`\n[Fan Speed] Device ${deviceId} Adjust by ${delta > 0 ? '+' : ''}${delta}`);
return true;
});
Expand Down
Loading
Loading