hoover-washer-status-check
Version:
Hoover washer status check
32 lines (31 loc) • 1.37 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const node_fetch_1 = __importDefault(require("node-fetch"));
const debug_1 = require("../debug");
const config_1 = __importDefault(require("../config"));
const cycleStateRecognizer_1 = require("../washer/cycleStateRecognizer");
const LaundryCycleState_1 = require("../washer/LaundryCycleState");
let lastLaundryCycleState = LaundryCycleState_1.LaundryCycleState.OFF;
exports.triggerIftttWebhookAfterEndLaundry = async (status) => {
const cycleSate = Number(status.MachMd);
if (cycleStateRecognizer_1.hasCycleBeenEnded(cycleSate, lastLaundryCycleState)) {
debug_1.debug.extend('ifttt')('triggering ifttt webhook service');
await triggerIftttWebhook('laundry_done');
}
lastLaundryCycleState = cycleSate;
};
const triggerIftttWebhook = async (eventName, value1, value2, value3) => {
const url = `https://maker.ifttt.com/trigger/${eventName}/with/key/${config_1.default.iftttApiKey}`;
return node_fetch_1.default(url, {
method: 'POST',
headers: { 'Context-Type': 'application/json' },
body: JSON.stringify({
value1,
value2,
value3,
}),
});
};