Skip to content
Open
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge Dreo",
"name": "homebridge-dreo",
"version": "4.3.0",
"version": "4.3.1",
"description": "Homebridge Plugin for Dreo Smart Devices",
"homepage": "https://github.com/zyonse/homebridge-dreo",
"license": "Apache-2.0",
Expand Down
30 changes: 27 additions & 3 deletions src/DreoAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export default class DreoAPI {
private readonly email: string;
private readonly password: string;
private readonly log: Logger;
private readonly controlDelayMs = 250;
private access_token: string;
private ws: WebSocket;
private ws!: WebSocket;
private controlQueue: Promise<void>;
public server: string;

constructor(platform: DreoPlatform) {
Expand All @@ -23,6 +25,7 @@ export default class DreoAPI {
this.password = platform.config.options?.password;
this.server = 'us';
this.access_token = '';
this.controlQueue = Promise.resolve();
}

// Get authentication token
Expand Down Expand Up @@ -152,11 +155,32 @@ export default class DreoAPI {

// Send control commands to device (fan speed, power, etc)
public control(sn, command) {
this.ws.send(JSON.stringify({
this.controlQueue = this.controlQueue
.catch(() => undefined)
.then(() => this.sendControl(sn, command));

return this.controlQueue;
}

private async sendControl(sn, command) {
const payload = JSON.stringify({
'deviceSn': sn,
'method': 'control',
'params': command,
'timestamp': Date.now(),
}));
});

try {
this.ws.send(payload);
this.log.debug('Dreo control queue send:', payload);
} catch (error) {
this.log.error('error sending control command:', error);
}

await this.delay(this.controlDelayMs);
}

private delay(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}
}
3 changes: 2 additions & 1 deletion src/platform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from 'homebridge';

import { PLATFORM_NAME, PLUGIN_NAME } from './settings';
import { PLATFORM_NAME, PLUGIN_NAME, PLUGIN_VERSION } from './settings';
import { FanAccessory } from './accessories/FanAccessory';
import { HeaterAccessory } from './accessories/HeaterAccessory';
import { HumidifierAccessory } from './accessories/HumidifierAccessory';
Expand All @@ -24,6 +24,7 @@ export class DreoPlatform implements DynamicPlatformPlugin {
public readonly config: PlatformConfig,
public readonly api: API,
) {
this.log.info('Homebridge Dreo plugin version:', PLUGIN_VERSION);
this.log.debug('Finished initializing platform:', this.config.name);

// When this event is fired it means Homebridge has restored all cached accessories from disk.
Expand Down
5 changes: 5 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ export const PLATFORM_NAME = 'DreoPlatform';
* This must match the name of your plugin as defined the package.json
*/
export const PLUGIN_NAME = 'homebridge-dreo';

/**
* Keep this in sync with package.json while debugging local Homebridge links.
*/
export const PLUGIN_VERSION = '4.3.1';