39 lines
1001 B
JavaScript
39 lines
1001 B
JavaScript
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
|
|
});
|
|
|
|
},
|
|
pause: async (time) => {
|
|
await new Promise(resolve => setTimeout(resolve, time));
|
|
},
|
|
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);
|
|
}
|
|
} |