@constructorfleet/ultimate-govee
Version:
Library for interacting with Govee devices written in Typescript.
47 lines • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NightLightState = exports.NightLightStateName = void 0;
const _ultimate_govee_common_1 = require("../../../common");
const device_state_1 = require("./device.state");
exports.NightLightStateName = 'nightLight';
class NightLightState extends device_state_1.DeviceOpState {
constructor(device, opType = _ultimate_govee_common_1.OpType.REPORT, ...identifier) {
super({ opType, identifier }, device, exports.NightLightStateName, {
on: undefined,
brightness: undefined,
});
this.stateToCommand = (state) => {
if (!(0, _ultimate_govee_common_1.isTypeOf)(state?.on, 'boolean')) {
this.logger.warn('On not included in state, ignoring command');
return undefined;
}
if (!(0, _ultimate_govee_common_1.isBetween)(state?.brightness, 0, 100)) {
this.logger.warn('Brightness not included in state, ignoring command');
return undefined;
}
return {
status: {
op: {
command: [[state.on ? 0x01 : 0x00, state.brightness]],
},
},
command: {
data: {
command: [
(0, _ultimate_govee_common_1.asOpCode)(_ultimate_govee_common_1.OpType.COMMAND, ...this.identifier, state.on ? 0x01 : 0x00, state.brightness),
],
},
},
};
};
}
parseOpCommand(opCommand) {
const [on, brightness] = opCommand.slice(0, 2);
this.stateValue.next({
on: on === 0x01,
brightness,
});
}
}
exports.NightLightState = NightLightState;
//# sourceMappingURL=night-light.state.js.map