@constructorfleet/ultimate-govee
Version:
Library for interacting with Govee devices written in Typescript.
62 lines • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MistLevelState = exports.MistLevelStateName = void 0;
const states_1 = require("../../../states");
const humidifier_modes_1 = require("./humidifier.modes");
exports.MistLevelStateName = 'mistLevel';
class MistLevelState extends states_1.DeviceState {
constructor(device, active) {
super(device, exports.MistLevelStateName, undefined);
this.active = active;
this.stateToCommand = () => {
return undefined;
};
active?.subscribe((event) => {
if (this.subscription !== undefined) {
this.subscription.unsubscribe();
}
switch (event?.name) {
case humidifier_modes_1.CustomModeStateName:
this.subscription = event?.subscribe((event) => {
this.stateValue.next(event?.currentProgram?.mistLevel);
});
break;
case humidifier_modes_1.ManualModeStateName:
this.subscription = event?.subscribe((event) => {
this.stateValue.next(event);
});
break;
default:
this.stateValue.next(undefined);
break;
}
});
}
setState(nextState) {
if (this.active.value === undefined) {
this.logger.warn('Active state is unknown, ignoring command');
return [];
}
if (nextState === undefined) {
this.logger.warn('Mist level is not specified, igoring command');
return [];
}
switch (this.active.value.name) {
case humidifier_modes_1.AutoModeStateName:
this.logger.warn('Mist level cannot be set when in Auto, changing mode to Manual');
return (this.active.modes
.find((mode) => mode.name === humidifier_modes_1.ManualModeStateName)
?.setState(nextState) ?? []);
case humidifier_modes_1.CustomModeStateName:
return this.active.value.setState({
mistLevel: nextState,
});
case humidifier_modes_1.ManualModeStateName:
return this.active.value.setState(nextState);
default:
return [];
}
}
}
exports.MistLevelState = MistLevelState;
//# sourceMappingURL=humidifier.mist.js.map