37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { Device } from "./device";
|
|
|
|
import { IDeviceInterface } from "../interfaces";
|
|
|
|
import * as Consts from "../consts";
|
|
|
|
export class Light extends Device {
|
|
|
|
|
|
constructor (hub: IDeviceInterface, portId: number) {
|
|
super(hub, portId, Consts.DeviceType.LIGHT);
|
|
}
|
|
|
|
|
|
/**
|
|
* Set the light brightness.
|
|
* @method Light#brightness
|
|
* @param {number} brightness Brightness value between 0-100 (0 is off)
|
|
* @returns {Promise} Resolved upon successful completion of command.
|
|
*/
|
|
public setBrightness (brightness: number) {
|
|
return new Promise((resolve) => {
|
|
const isWeDo2 = (this.hub.type === Consts.HubType.WEDO2_SMART_HUB);
|
|
if (isWeDo2) {
|
|
const data = Buffer.from([this.portId, 0x01, 0x02, brightness]);
|
|
this.send(data, Consts.BLECharacteristic.WEDO2_MOTOR_VALUE_WRITE);
|
|
} else {
|
|
const data = Buffer.from([0x81, this.portId, 0x11, 0x51, 0x00, brightness]);
|
|
this.send(data);
|
|
}
|
|
return resolve();
|
|
});
|
|
}
|
|
|
|
|
|
}
|