-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.js
69 lines (60 loc) · 1.71 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Venstar api interface
require('isomorphic-fetch')
const querystring = require('querystring');
const request = require("request-promise-native");
const http = require("http");
//exports.VenstarAPI = exports.GetInfoResponse = void 0;
class GetInfoResponse {
constructor() {
this.name = "THERMOSTAT";
this.mode = 0;
this.state = 0;
this.activestage = 0;
this.fan = 0;
this.fanstate = 0;
this.tempunits = 0;
this.schedule = 0;
this.schedulepart = 0;
this.away = 0;
this.spacetemp = 0;
this.heattemp = 10;
this.cooltemp = 10;
this.cooltempmin = 10;
this.cooltempmax = 35;
this.heattempmin = 10;
this.heattempmax = 25;
this.setpointdelta = 0;
this.availablemodes = 0;
}
}
exports.GetInfoResponse = GetInfoResponse;
class VenstarAPI {
constructor(address) {
this.uri = address;
}
async getInfo() {
return fetch(`${this.uri}/query/info`)
.then(response=> {
if(!response.ok) {
throw new Error("Network Error: Couldn't get status update from thermostat");
}
return response.json()
})
.catch((err) => {
throw err;
});
}
async setControl(data) {
console.log("setting control data: " + data);
return fetch(`${this.uri}/control`, {
method: 'POST',
body: data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.then((res) => res.json())
.catch((err) => console.log(err));
}
}
exports.VenstarAPI = VenstarAPI;