iobroker.airzone 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Airzone.png +0 -0
- package/LocalApi/AirzoneLocalApi.js +78 -0
- package/LocalApi/Constants.js +14 -0
- package/LocalApi/System.js +150 -0
- package/LocalApi/Zone.js +116 -0
- package/README.md +12 -0
- package/Utils/asyncRequest.js +35 -2
- package/admin/Airzone.png +0 -0
- package/admin/AirzoneSmall.png +0 -0
- package/admin/index_m.html +97 -104
- package/admin/style.css +29 -0
- package/admin/words.js +53 -0
- package/io-package.json +141 -68
- package/main.js +153 -135
- package/package.json +65 -65
- package/Cloud/AirzoneCloud.js +0 -137
- package/Cloud/Constants.js +0 -81
- package/Cloud/Device.js +0 -139
- package/Cloud/System.js +0 -214
- package/Cloud/Zone.js +0 -139
- package/settings/secrets/AUTO_MERGE_TOKEN +0 -1
package/package.json
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name":"iobroker.airzone",
|
|
3
|
-
"version":"
|
|
4
|
-
"description":"Airzone
|
|
5
|
-
"author":{
|
|
6
|
-
"name":"Christian Schemmer",
|
|
7
|
-
"email":"christian.silentphoenix11@gmail.com"
|
|
8
|
-
},
|
|
9
|
-
"contributors": [],
|
|
10
|
-
"homepage":"https://github.com/SilentPhoenix11/ioBroker.airzone",
|
|
11
|
-
"license":"MIT",
|
|
12
|
-
"keywords":[
|
|
13
|
-
"ioBroker",
|
|
14
|
-
"airzone",
|
|
15
|
-
"airzone cloud",
|
|
16
|
-
"Smart Home",
|
|
17
|
-
"home automation"
|
|
18
|
-
],
|
|
19
|
-
"repository":{
|
|
20
|
-
"type":"git",
|
|
21
|
-
"url":"https://github.com/SilentPhoenix11/ioBroker.airzone"
|
|
22
|
-
},
|
|
23
|
-
"engines": {
|
|
24
|
-
"node": ">=12.0.0"
|
|
25
|
-
},
|
|
26
|
-
"dependencies":{
|
|
27
|
-
"@iobroker/adapter-core": "^2.4.0",
|
|
28
|
-
"request": "^2.88.2",
|
|
29
|
-
"util":"^0.12.3"
|
|
30
|
-
},
|
|
31
|
-
"devDependencies":{
|
|
32
|
-
"@iobroker/testing": "^2.4.4",
|
|
33
|
-
"@types/chai": "^4.2.15",
|
|
34
|
-
"@types/chai-as-promised": "^7.1.3",
|
|
35
|
-
"@types/gulp": "^4.0.8",
|
|
36
|
-
"@types/mocha": "^8.2.1",
|
|
37
|
-
"@types/node": "^14.14.34",
|
|
38
|
-
"@types/proxyquire": "^1.3.28",
|
|
39
|
-
"@types/sinon": "^9.0.11",
|
|
40
|
-
"@types/sinon-chai": "^3.2.5",
|
|
41
|
-
"axios": "^0.21.1",
|
|
42
|
-
"chai": "^4.3.4",
|
|
43
|
-
"chai-as-promised": "^7.1.1",
|
|
44
|
-
"eslint": "^7.22.0",
|
|
45
|
-
"gulp": "^4.0.2",
|
|
46
|
-
"mocha": "^8.3.2",
|
|
47
|
-
"proxyquire": "^2.1.3",
|
|
48
|
-
"sinon": "^9.2.4",
|
|
49
|
-
"sinon-chai": "^3.5.0",
|
|
50
|
-
"typescript": "^4.2.3"
|
|
51
|
-
},
|
|
52
|
-
"main":"main.js",
|
|
53
|
-
"scripts":{
|
|
54
|
-
"test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"",
|
|
55
|
-
"test:package": "mocha test/package --exit",
|
|
56
|
-
"test:unit": "mocha test/unit --exit",
|
|
57
|
-
"test:integration": "mocha test/integration --exit",
|
|
58
|
-
"test": "npm run test:js && npm run test:package",
|
|
59
|
-
"check": "tsc --noEmit -p tsconfig.check.json",
|
|
60
|
-
"lint": "eslint"
|
|
61
|
-
},
|
|
62
|
-
"bugs":{
|
|
63
|
-
"url":"https://github.com/SilentPhoenix11/ioBroker.airzone/issues"
|
|
64
|
-
},
|
|
65
|
-
"readmeFilename":"README.md"
|
|
1
|
+
{
|
|
2
|
+
"name":"iobroker.airzone",
|
|
3
|
+
"version":"2.0.0",
|
|
4
|
+
"description":"Airzone local api integration for ioBroker",
|
|
5
|
+
"author":{
|
|
6
|
+
"name":"Christian Schemmer",
|
|
7
|
+
"email":"christian.silentphoenix11@gmail.com"
|
|
8
|
+
},
|
|
9
|
+
"contributors": [],
|
|
10
|
+
"homepage":"https://github.com/SilentPhoenix11/ioBroker.airzone",
|
|
11
|
+
"license":"MIT",
|
|
12
|
+
"keywords":[
|
|
13
|
+
"ioBroker",
|
|
14
|
+
"airzone",
|
|
15
|
+
"airzone cloud",
|
|
16
|
+
"Smart Home",
|
|
17
|
+
"home automation"
|
|
18
|
+
],
|
|
19
|
+
"repository":{
|
|
20
|
+
"type":"git",
|
|
21
|
+
"url":"https://github.com/SilentPhoenix11/ioBroker.airzone"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=12.0.0"
|
|
25
|
+
},
|
|
26
|
+
"dependencies":{
|
|
27
|
+
"@iobroker/adapter-core": "^2.4.0",
|
|
28
|
+
"request": "^2.88.2",
|
|
29
|
+
"util":"^0.12.3"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies":{
|
|
32
|
+
"@iobroker/testing": "^2.4.4",
|
|
33
|
+
"@types/chai": "^4.2.15",
|
|
34
|
+
"@types/chai-as-promised": "^7.1.3",
|
|
35
|
+
"@types/gulp": "^4.0.8",
|
|
36
|
+
"@types/mocha": "^8.2.1",
|
|
37
|
+
"@types/node": "^14.14.34",
|
|
38
|
+
"@types/proxyquire": "^1.3.28",
|
|
39
|
+
"@types/sinon": "^9.0.11",
|
|
40
|
+
"@types/sinon-chai": "^3.2.5",
|
|
41
|
+
"axios": "^0.21.1",
|
|
42
|
+
"chai": "^4.3.4",
|
|
43
|
+
"chai-as-promised": "^7.1.1",
|
|
44
|
+
"eslint": "^7.22.0",
|
|
45
|
+
"gulp": "^4.0.2",
|
|
46
|
+
"mocha": "^8.3.2",
|
|
47
|
+
"proxyquire": "^2.1.3",
|
|
48
|
+
"sinon": "^9.2.4",
|
|
49
|
+
"sinon-chai": "^3.5.0",
|
|
50
|
+
"typescript": "^4.2.3"
|
|
51
|
+
},
|
|
52
|
+
"main":"main.js",
|
|
53
|
+
"scripts":{
|
|
54
|
+
"test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"",
|
|
55
|
+
"test:package": "mocha test/package --exit",
|
|
56
|
+
"test:unit": "mocha test/unit --exit",
|
|
57
|
+
"test:integration": "mocha test/integration --exit",
|
|
58
|
+
"test": "npm run test:js && npm run test:package",
|
|
59
|
+
"check": "tsc --noEmit -p tsconfig.check.json",
|
|
60
|
+
"lint": "eslint"
|
|
61
|
+
},
|
|
62
|
+
"bugs":{
|
|
63
|
+
"url":"https://github.com/SilentPhoenix11/ioBroker.airzone/issues"
|
|
64
|
+
},
|
|
65
|
+
"readmeFilename":"README.md"
|
|
66
66
|
}
|
package/Cloud/AirzoneCloud.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const AsyncRequest = require('../Utils/asyncRequest');
|
|
4
|
-
const Constants = require('./Constants')
|
|
5
|
-
const Device = require('./Device')
|
|
6
|
-
|
|
7
|
-
// Allow to connect to AirzoneCloud API
|
|
8
|
-
|
|
9
|
-
let log;
|
|
10
|
-
let adapter;
|
|
11
|
-
class AirzoneCloud {
|
|
12
|
-
constructor(a, username, password, base_url)
|
|
13
|
-
{
|
|
14
|
-
adapter = a;
|
|
15
|
-
log = a.log;
|
|
16
|
-
this.username = username;
|
|
17
|
-
this.password = password;
|
|
18
|
-
this.base_url = base_url;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async init() {
|
|
22
|
-
|
|
23
|
-
if(!await this.login())
|
|
24
|
-
return false;
|
|
25
|
-
|
|
26
|
-
if(!await this.load_devices())
|
|
27
|
-
return false;
|
|
28
|
-
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async update() {
|
|
33
|
-
if(!await this.login())
|
|
34
|
-
return false;
|
|
35
|
-
|
|
36
|
-
if(!await this.update_devices())
|
|
37
|
-
return false;
|
|
38
|
-
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async login() {
|
|
43
|
-
var url = this.base_url.concat(Constants.API_LOGIN);
|
|
44
|
-
const data = JSON.stringify({"email":this.username, "password":this.password});
|
|
45
|
-
var response = await AsyncRequest.jsonPostRequest(url, data);
|
|
46
|
-
|
|
47
|
-
var errors = response["errors"];
|
|
48
|
-
if(errors)
|
|
49
|
-
{
|
|
50
|
-
if(errors == "invalid")
|
|
51
|
-
this.logError("Failed to login at AirzoneCloud: (statusCode: "+response["statusCode"]+") - Invalid email or password");
|
|
52
|
-
else
|
|
53
|
-
this.logError("Failed to login at AirzoneCloud: (statusCode: "+response["statusCode"]+") - "+errors);
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
var body = response["body"];
|
|
58
|
-
var user = JSON.parse(body)["user"];
|
|
59
|
-
this.token = user["authentication_token"];
|
|
60
|
-
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async load_devices() {
|
|
65
|
-
var device_relations = await this.get_devices();
|
|
66
|
-
if(device_relations == undefined)
|
|
67
|
-
return false;
|
|
68
|
-
|
|
69
|
-
this.devices = [];
|
|
70
|
-
let deviceCount = 0;
|
|
71
|
-
for (let index = 0; index < device_relations.length; index++) {
|
|
72
|
-
var deviceData = device_relations[index]["device"];
|
|
73
|
-
var device = new Device(adapter, this);
|
|
74
|
-
if(await device.init(deviceData))
|
|
75
|
-
{
|
|
76
|
-
this.devices[deviceCount] = device;
|
|
77
|
-
deviceCount++;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async update_devices() {
|
|
84
|
-
var device_relations = await this.get_devices();
|
|
85
|
-
|
|
86
|
-
if(device_relations == undefined)
|
|
87
|
-
return false;
|
|
88
|
-
|
|
89
|
-
for (let index = 0; index < device_relations.length; index++) {
|
|
90
|
-
var deviceData = device_relations[index]["device"];
|
|
91
|
-
|
|
92
|
-
var dId = deviceData["id"];
|
|
93
|
-
|
|
94
|
-
for(let i = 0;i<this.devices.length;i++) {
|
|
95
|
-
if(this.devices[i].id == dId) {
|
|
96
|
-
await this.devices[i].update(deviceData);
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async get_devices() {
|
|
105
|
-
var params = "/?format=json&user_email="+this.username.toLowerCase()+"&user_token="+this.token;
|
|
106
|
-
var url = this.base_url.concat(Constants.API_DEVICE_RELATIONS, params);
|
|
107
|
-
var response = await AsyncRequest.jsonGetRequest(url);
|
|
108
|
-
|
|
109
|
-
var errors = response["errors"];
|
|
110
|
-
if(errors)
|
|
111
|
-
{
|
|
112
|
-
this.logError("Failed to load device relations: (statusCode: "+response["statusCode"]+") - "+response["errors"]);
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
var body = response["body"];
|
|
116
|
-
var device_relations = JSON.parse(body)["device_relations"];
|
|
117
|
-
return device_relations;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
logInfo(msg) {
|
|
121
|
-
log.info(msg);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
logError(msg) {
|
|
125
|
-
log.error(msg);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async sendEvent(payload) {
|
|
129
|
-
if(!await this.login())
|
|
130
|
-
return;
|
|
131
|
-
|
|
132
|
-
var params = "/?format=json&user_email="+this.username.toLowerCase()+"&user_token="+this.token;
|
|
133
|
-
var url = this.base_url.concat(Constants.API_EVENTS, params);
|
|
134
|
-
await AsyncRequest.jsonPostRequest(url, JSON.stringify(payload));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
module.exports = AirzoneCloud;
|
package/Cloud/Constants.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
module.exports = Object.freeze({
|
|
2
|
-
API_LOGIN : "/users/sign_in",
|
|
3
|
-
API_DEVICE_RELATIONS : "/device_relations",
|
|
4
|
-
API_SYSTEMS : "/systems",
|
|
5
|
-
API_ZONES : "/zones",
|
|
6
|
-
API_EVENTS : "/events",
|
|
7
|
-
|
|
8
|
-
MODES_CONVERTER : {
|
|
9
|
-
"0": {"name": "stop", "description": "Stop"},
|
|
10
|
-
"1": {"name": "cool-air", "description": "Air cooling"},
|
|
11
|
-
"2": {"name": "heat-radiant", "description": "Radiant heating"},
|
|
12
|
-
"3": {"name": "ventilate", "description": "Ventilate"},
|
|
13
|
-
"4": {"name": "heat-air", "description": "Air heating"},
|
|
14
|
-
"5": {"name": "heat-both", "description": "Combined heating"},
|
|
15
|
-
"6": {"name": "dehumidify", "description": "Dry"},
|
|
16
|
-
"7": {"name": "not_exit", "description": ""},
|
|
17
|
-
"8": {"name": "cool-radiant", "description": "Radiant cooling"},
|
|
18
|
-
"9": {"name": "cool-both", "description": "Combined cooling"},
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
SCHEDULE_MODES_CONVERTER : {
|
|
22
|
-
"0": {"name": "", "description": ""},
|
|
23
|
-
"1": {"name": "stop", "description": "Stop"},
|
|
24
|
-
"2": {"name": "ventilate", "description": "Ventilate"},
|
|
25
|
-
"3": {"name": "cool-air", "description": "Air cooling"},
|
|
26
|
-
"4": {"name": "heat-air", "description": "Air heating"},
|
|
27
|
-
"5": {"name": "heat-radiant", "description": "Radiant heating"},
|
|
28
|
-
"6": {"name": "heat-both", "description": "Combined heating"},
|
|
29
|
-
"7": {"name": "dehumidify", "description": "Dry"},
|
|
30
|
-
"8": {"name": "cool-radiant", "description": "Radiant cooling"},
|
|
31
|
-
"9": {"name": "cool-both", "description": "Combined cooling"},
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
VELOCITIES_CONVERTER : {
|
|
35
|
-
"0": {"name": "auto", "description": "Auto"},
|
|
36
|
-
"1": {"name": "velocity-1", "description": "Low speed"},
|
|
37
|
-
"2": {"name": "velocity-2", "description": "Medium speed"},
|
|
38
|
-
"3": {"name": "velocity-3", "description": "High speed"},
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
AIRFLOW_CONVERTER : {
|
|
42
|
-
"0": {"name": "airflow-0", "description": "Silence"},
|
|
43
|
-
"1": {"name": "airflow-1", "description": "Standard"},
|
|
44
|
-
"2": {"name": "airflow-2", "description": "Power"},
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
ECO_CONVERTER : {
|
|
48
|
-
"0": {"name": "eco-off", "description": "Eco off"},
|
|
49
|
-
"1": {"name": "eco-m", "description": "Eco manual"},
|
|
50
|
-
"2": {"name": "eco-a", "description": "Eco A"},
|
|
51
|
-
"3": {"name": "eco-aa", "description": "Eco A+"},
|
|
52
|
-
"4": {"name": "eco-aaa", "description": "Eco A++"},
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
SCENES_CONVERTER : {
|
|
56
|
-
"0": {
|
|
57
|
-
"name": "stop",
|
|
58
|
-
"description": "The air-conditioning system will remain switched off regardless of the demand status of any zone, all the motorized dampers will remain opened",
|
|
59
|
-
},
|
|
60
|
-
"1": {
|
|
61
|
-
"name": "confort",
|
|
62
|
-
"description": "Default and standard user mode. The desired set point temperature can be selected using the predefined temperature ranges",
|
|
63
|
-
},
|
|
64
|
-
"2": {
|
|
65
|
-
"name": "unocupied",
|
|
66
|
-
"description": "To be used when there is no presence detected for short periods of time. A more efficient set point temperature will be set. If the thermostat is activated, the zone will start running in comfort mode",
|
|
67
|
-
},
|
|
68
|
-
"3": {
|
|
69
|
-
"name": "night",
|
|
70
|
-
"description": "The system automatically changes the set point temperature 0.5\xba C/1\xba F every 30 minutes in up to 4 increments of 2\xba C/4\xba F in 2 hours. When cooling, the system increases the set point temperature; when heating, the system decreases the set point temperature",
|
|
71
|
-
},
|
|
72
|
-
"4": {
|
|
73
|
-
"name": "eco",
|
|
74
|
-
"description": "The range of available set point temperatures change for more efficient operation",
|
|
75
|
-
},
|
|
76
|
-
"5": {
|
|
77
|
-
"name": "vacation",
|
|
78
|
-
"description": "This mode feature saves energy while the user is away for extended periods of time",
|
|
79
|
-
},
|
|
80
|
-
}
|
|
81
|
-
});
|
package/Cloud/Device.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
const System = require('./System')
|
|
2
|
-
const AsyncRequest = require('../Utils/asyncRequest');
|
|
3
|
-
const Constants = require('./Constants');
|
|
4
|
-
|
|
5
|
-
class Device {
|
|
6
|
-
|
|
7
|
-
constructor(adapter, airzone)
|
|
8
|
-
{
|
|
9
|
-
this.adapter = adapter;
|
|
10
|
-
this.airzone = airzone;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Initialize the device with the data from the airzone cloud
|
|
15
|
-
*/
|
|
16
|
-
async init(deviceData) {
|
|
17
|
-
this.id = deviceData["id"];
|
|
18
|
-
this.name = deviceData["name"];
|
|
19
|
-
|
|
20
|
-
this.path = this.name;
|
|
21
|
-
await this.adapter.setObjectNotExistsAsync(this.path, {
|
|
22
|
-
type: 'state',
|
|
23
|
-
common: {
|
|
24
|
-
name: 'Device_'+this.name,
|
|
25
|
-
type: 'object',
|
|
26
|
-
read: true,
|
|
27
|
-
write: false,
|
|
28
|
-
},
|
|
29
|
-
native: {},
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
await this.adapter.createPropertyAndInit(this.path, 'id', 'string', true, false, this.id);
|
|
33
|
-
await this.adapter.createPropertyAndInit(this.path, 'name', 'string', true, false, this.name);
|
|
34
|
-
await this.adapter.createProperty(this.path, 'status', 'string', true, false);
|
|
35
|
-
await this.adapter.createProperty(this.path, 'mac', 'string', true, false);
|
|
36
|
-
await this.adapter.createProperty(this.path, 'pin', 'string', true, false);
|
|
37
|
-
await this.adapter.createProperty(this.path, 'target_temperature', 'number', 0, 100, '°C', true, true);
|
|
38
|
-
|
|
39
|
-
await this.updateData(deviceData);
|
|
40
|
-
|
|
41
|
-
if(!await this.load_systems(this.path))
|
|
42
|
-
return false;
|
|
43
|
-
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Synchronized the device data from airzone into the iobroker data points
|
|
49
|
-
*/
|
|
50
|
-
async updateData(deviceData)
|
|
51
|
-
{
|
|
52
|
-
this.status = deviceData["status"];
|
|
53
|
-
await this.adapter.updatePropertyValue(this.path, 'status', this.status);
|
|
54
|
-
|
|
55
|
-
this.mac = deviceData["mac"];
|
|
56
|
-
await this.adapter.updatePropertyValue(this.path, 'mac', this.mac);
|
|
57
|
-
|
|
58
|
-
this.pin = deviceData["pin"];
|
|
59
|
-
await this.adapter.updatePropertyValue(this.path, 'pin', this.pin);
|
|
60
|
-
|
|
61
|
-
this.target_temperature = deviceData["consign"];
|
|
62
|
-
await this.adapter.updatePropertyValue(this.path, 'target_temperature', this.target_temperature);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Synchronized the device data from airzone into the iobroker data points and call update for all sub systems
|
|
67
|
-
*/
|
|
68
|
-
async update(deviceData) {
|
|
69
|
-
|
|
70
|
-
await this.updateData(deviceData);
|
|
71
|
-
await this.update_systems();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Load and initialize the systems of this device from airzone cloud
|
|
76
|
-
*/
|
|
77
|
-
async load_systems(path) {
|
|
78
|
-
var systems_relations = await this.get_systems();
|
|
79
|
-
if(systems_relations == undefined)
|
|
80
|
-
return false;
|
|
81
|
-
|
|
82
|
-
this.systems = [];
|
|
83
|
-
let systemsCount = 0;
|
|
84
|
-
for (let index = 0; index < systems_relations.length; index++) {
|
|
85
|
-
var systemData = systems_relations[index];
|
|
86
|
-
var system = new System(this.adapter, this.airzone);
|
|
87
|
-
if(await system.init(path, systemData))
|
|
88
|
-
{
|
|
89
|
-
this.systems[systemsCount] = system;
|
|
90
|
-
systemsCount++;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Update systems with the current system data from airzone cloud
|
|
99
|
-
*/
|
|
100
|
-
async update_systems() {
|
|
101
|
-
var systems_relations = await this.get_systems();
|
|
102
|
-
if(systems_relations == undefined)
|
|
103
|
-
return false;
|
|
104
|
-
|
|
105
|
-
for (let index = 0; index < systems_relations.length; index++) {
|
|
106
|
-
var systemData = systems_relations[index];
|
|
107
|
-
var sId = systemData["id"];
|
|
108
|
-
|
|
109
|
-
for(let i = 0;i<this.systems.length;i++) {
|
|
110
|
-
if(this.systems[i].id == sId) {
|
|
111
|
-
await this.systems[i].update(systemData);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Web request to get the systems of this system
|
|
122
|
-
*/
|
|
123
|
-
async get_systems() {
|
|
124
|
-
var params = "/?device_id="+this.id+"&format=json&user_email="+this.airzone.username.toLowerCase()+"&user_token="+this.airzone.token;
|
|
125
|
-
var url = this.airzone.base_url.concat(Constants.API_SYSTEMS, params);
|
|
126
|
-
var response = await AsyncRequest.jsonGetRequest(url);
|
|
127
|
-
|
|
128
|
-
var errors = response["errors"];
|
|
129
|
-
if(errors)
|
|
130
|
-
{
|
|
131
|
-
this.airzone.logError("Failed to load systems of "+this.name+": (statusCode: "+response["statusCode"]+") - "+response["errors"]);
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
var body = response["body"];
|
|
135
|
-
var systems_relations = JSON.parse(body)["systems"];
|
|
136
|
-
return systems_relations;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
module.exports = Device;
|