@constructorfleet/ultimate-govee
Version:
Library for interacting with Govee devices written in Typescript.
47 lines • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModeState = exports.defaultModeIdMap = exports.ModeStateName = void 0;
const _ultimate_govee_common_1 = require("../../../common");
const rxjs_1 = require("rxjs");
const device_state_1 = require("./device.state");
const states_types_1 = require("./states.types");
exports.ModeStateName = 'mode';
const definedStates = (states) => states.filter((state) => state !== undefined);
const defaultModeIdMap = (state) => {
return state.modes
.map((mode) => mode)
.find((mode) => state.activeIdentifier
.getValue()
?.every((i, index) => mode.identifier?.at(index) === i));
};
exports.defaultModeIdMap = defaultModeIdMap;
class ModeState extends device_state_1.DeviceOpState {
get activeMode() {
return this.identifierMap(this);
}
constructor(device, modes, opType = _ultimate_govee_common_1.OpType.REPORT, identifier = [0x05], inline = false, identifierMap = exports.defaultModeIdMap) {
super({ opType, identifier }, device, exports.ModeStateName, undefined, states_types_1.ParseOption.opCode.or(states_types_1.ParseOption.state));
this.identifierMap = identifierMap;
this.activeIdentifier = new rxjs_1.BehaviorSubject(undefined);
this.modes = definedStates(modes);
this.inline = inline;
}
parseState(data) {
if (data?.state?.mode !== undefined) {
this.activeIdentifier.next([data.state.mode]);
}
}
parseOpCommand(opCommand) {
if (this.inline) {
this.activeIdentifier.next(opCommand);
return;
}
const [identifier, ...value] = opCommand;
if (identifier !== 0x00) {
return;
}
this.activeIdentifier.next(value);
}
}
exports.ModeState = ModeState;
//# sourceMappingURL=mode.state.js.map