39 lines
1001 B
JavaScript
Raw Normal View History

2020-09-12 11:42:02 +01:00
const got = require('got');
module.exports = {
request: async (input) => {
var options = {
json: {
"switch": JSON.stringify(input)
}
};
got.post(`http://192.168.4.5:2020/water/switch`, options)
.then((resp) => {
return resp
});
},
2020-09-14 12:11:37 +01:00
pause: async (time) => {
await new Promise(resolve => setTimeout(resolve, time));
},
2020-09-14 13:47:23 +01:00
nextEvent: async (time) => {
time = time.match(/.{11}$/gm)
time = time[0].toLowerCase()
var hours = parseInt(time.substr(0, 2));
if (time.indexOf('am') != -1 && hours == 12) {
time = time.replace('12', '0');
}
if (time.indexOf('pm') != -1 && hours < 12) {
time = time.replace(hours, (hours + 12));
}
time = time.replace(/(am|pm)/, '');
time = time.replace(/ /g,'')
return time.substring(0, time.length - 3);
}
2020-09-12 11:42:02 +01:00
}