iobroker.airzone 1.0.2 → 2.0.1

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.
@@ -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;
@@ -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: 'device',
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, 'text');
33
- await this.adapter.createPropertyAndInit(this.path, 'name', 'string', true, false, this.name, 'text');
34
- await this.adapter.createProperty(this.path, 'status', 'string', true, false, 'text');
35
- await this.adapter.createProperty(this.path, 'mac', 'string', true, false, 'text');
36
- await this.adapter.createProperty(this.path, 'pin', 'string', true, false, 'text');
37
- await this.adapter.createProperty(this.path, 'target_temperature', 'number', 0, 100, '°C', true, true, 'state');
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;
package/Cloud/System.js DELETED
@@ -1,236 +0,0 @@
1
- const Zone = require('./Zone')
2
- const AsyncRequest = require('../Utils/asyncRequest');
3
- const Constants = require('./Constants');
4
-
5
- class System {
6
- constructor(adapter, airzone)
7
- {
8
- this.adapter = adapter;
9
- this.airzone = airzone;
10
- }
11
-
12
- /**
13
- * Initialize the system with the data from the airzone cloud
14
- */
15
- async init(path, systemData) {
16
- this.id = systemData["id"];
17
- this.name = systemData["name"];
18
-
19
- this.device_id = systemData["device_id"];
20
- this.system_number = systemData["system_number"];
21
-
22
- this.min_temp = systemData["min_limit"];
23
- this.max_temp = systemData["max_limit"];
24
-
25
- this.path = path+"."+this.name;
26
- await this.adapter.setObjectNotExistsAsync(this.path, {
27
- type: 'device',
28
- common: {
29
- name: 'System_'+this.name,
30
- type: 'object',
31
- read: true,
32
- write: false,
33
- },
34
- native: {},
35
- });
36
-
37
- await this.adapter.createPropertyAndInit(this.path, 'id', 'string', true, false, this.id, 'text');
38
- await this.adapter.createPropertyAndInit(this.path, 'name', 'string', true, false, this.name, 'text');
39
- await this.adapter.createPropertyAndInit(this.path, 'min_limit', 'string', true, false, this.min_limit, 'value.min');
40
- await this.adapter.createPropertyAndInit(this.path, 'max_limit', 'string', true, false, this.max_limit, 'value.max');
41
- await this.adapter.createProperty(this.path, 'has_velocity', 'boolean', true, false, 'indicator');
42
- await this.adapter.createProperty(this.path, 'velocity_raw', 'string', true, false, 'value');
43
- await this.adapter.createProperty(this.path, 'velocity', 'string', true, false, 'text');
44
- await this.adapter.createProperty(this.path, 'velocity_description', 'string', true, false, 'text');
45
- await this.adapter.createProperty(this.path, 'has_airflow', 'boolean', true, false, 'indicator');
46
- await this.adapter.createProperty(this.path, 'airflow_raw', 'string', true, false, 'value');
47
- await this.adapter.createProperty(this.path, 'airflow', 'string', true, false, 'text');
48
- await this.adapter.createProperty(this.path, 'airflow_description', 'string', true, false, 'text');
49
- await this.adapter.createProperty(this.path, 'mode_raw', 'string', true, true, 'state');
50
- await this.adapter.createProperty(this.path, 'mode', 'string', true, false, 'text');
51
- await this.adapter.createProperty(this.path, 'mode_description', 'string', true, false, 'text');
52
- await this.adapter.createProperty(this.path, 'eco_raw', 'string', true, true, 'state');
53
- await this.adapter.createProperty(this.path, 'eco', 'string', true, false, 'text');
54
- await this.adapter.createProperty(this.path, 'eco_description', 'string', true, false, 'text');
55
-
56
- this.adapter.subscribeState(this.path+'.mode_raw', this, this.reactToModeRawChange);
57
- this.adapter.subscribeState(this.path+'.eco_raw', this, this.reactToEcoRawChange);
58
-
59
- await this.updateData(systemData);
60
-
61
- if(!await this.load_zones(this.path))
62
- return false;
63
-
64
- return true;
65
- }
66
-
67
- /**
68
- * Synchronized the system data from airzone into the iobroker data points
69
- */
70
- async updateData(systemData)
71
- {
72
- this.has_velocity = systemData["has_velocity"];
73
- await this.adapter.updatePropertyValue(this.path, 'has_velocity', this.has_velocity);
74
- this.velocity_raw = systemData["velocity"];
75
- await this.adapter.updatePropertyValue(this.path, 'velocity_raw', this.velocity_raw);
76
- this.velocity = this.has_velocity ? Constants.VELOCITIES_CONVERTER[this.velocity_raw]["name"] : undefined;
77
- await this.adapter.updatePropertyValue(this.path, 'velocity', this.velocity);
78
- this.velocity_description = this.has_velocity ? Constants.VELOCITIES_CONVERTER[this.velocity_raw]["description"] : undefined;
79
- await this.adapter.updatePropertyValue(this.path, 'velocity_description', this.velocity_description);
80
-
81
- this.has_airflow = systemData["has_airflow"];
82
- await this.adapter.updatePropertyValue(this.path, 'has_airflow', this.has_airflow);
83
- this.airflow_raw = systemData["airflow"];
84
- await this.adapter.updatePropertyValue(this.path, 'airflow_raw', this.airflow_raw);
85
- this.airflow = this.has_airflow ? Constants.AIRFLOW_CONVERTER[this.airflow_raw]["name"] : undefined;
86
- await this.adapter.updatePropertyValue(this.path, 'airflow', this.airflow);
87
- this.airflow_description = this.has_airflow ? Constants.AIRFLOW_CONVERTER[this.airflow_raw]["description"] : undefined;
88
- await this.adapter.updatePropertyValue(this.path, 'airflow_description', this.airflow_description);
89
-
90
- this.mode_raw = systemData["mode"];
91
- await this.adapter.updatePropertyValue(this.path, 'mode_raw', this.mode_raw);
92
- this.mode = Constants.MODES_CONVERTER[this.mode_raw]["name"];
93
- await this.adapter.updatePropertyValue(this.path, 'mode', this.mode);
94
- this.mode_description = Constants.MODES_CONVERTER[this.mode_raw]["description"];
95
- await this.adapter.updatePropertyValue(this.path, 'mode_description', this.mode_description);
96
-
97
- this.eco_raw = systemData["eco"];
98
- await this.adapter.updatePropertyValue(this.path, 'eco_raw', this.eco_raw);
99
- this.eco = Constants.ECO_CONVERTER[this.eco_raw]["name"];
100
- await this.adapter.updatePropertyValue(this.path, 'eco', this.eco);
101
- this.eco_description = Constants.ECO_CONVERTER[this.mode_raw]["description"];
102
- await this.adapter.updatePropertyValue(this.path, 'eco_description', this.eco_description);
103
- }
104
-
105
- /**
106
- * Synchronized the system data from airzone into the iobroker data points and call update for all sub zones
107
- */
108
- async update(systemData) {
109
-
110
- await this.updateData(systemData);
111
-
112
- // Ask an update to the airzone hardware (airzonecloud don't autopull data like current temperature)
113
- // The update should be available in airzonecloud after 3 to 5 secs in average
114
- await this.askSystemInfo();
115
-
116
- await this.update_zones();
117
- }
118
-
119
- /**
120
- * Load and initialize the zones of this system from airzone cloud
121
- */
122
- async load_zones(path) {
123
-
124
- var zones_relations = await this.get_zones();
125
- if(zones_relations == undefined)
126
- return false;
127
-
128
- this.zones = [];
129
- for (let index = 0; index < zones_relations.length; index++) {
130
- var zoneData = zones_relations[index];
131
- var zone = new Zone(this.adapter, this.airzone, zoneData, path);
132
- await zone.init(path, zoneData)
133
- this.zones[index] = zone;
134
- }
135
-
136
- return true;
137
- }
138
-
139
- /**
140
- * Update zones with the current zone data from airzone cloud
141
- */
142
- async update_zones() {
143
-
144
- var zones_relations = await this.get_zones();
145
- if(zones_relations == undefined)
146
- return false;
147
-
148
- for (let index = 0; index < zones_relations.length; index++) {
149
- var zoneData = zones_relations[index];
150
- var zId = zoneData["id"];
151
-
152
- for(let i = 0;i<this.zones.length;i++) {
153
- if(this.zones[i].id == zId) {
154
- await this.zones[i].updateData(zoneData);
155
- break;
156
- }
157
- }
158
- }
159
-
160
- return true;
161
- }
162
-
163
- /**
164
- * Web request to get the zones of this system
165
- */
166
- async get_zones() {
167
- var params = "/?system_id="+this.id+"&format=json&user_email="+this.airzone.username.toLowerCase()+"&user_token="+this.airzone.token;
168
- var url = this.airzone.base_url.concat(Constants.API_ZONES, params);
169
- var response = await AsyncRequest.jsonGetRequest(url);
170
-
171
- var errors = response["errors"];
172
- if(errors)
173
- {
174
- this.airzone.logError("Failed to load zones of system "+this.name+": (statusCode: "+response["statusCode"]+") - "+response["errors"]);
175
- return false;
176
- }
177
- var body = response["body"];
178
- var zones_relations = JSON.parse(body)["zones"];
179
- return zones_relations;
180
- }
181
-
182
- /**
183
- * Is called when the state of mode was changed
184
- */
185
- async reactToModeRawChange(self, id, state) {
186
-
187
- if(state.val == 0)
188
- {
189
- self.zones.forEach(zone => {
190
- zone.turn_off();
191
- });
192
- }
193
-
194
- self.sendEvent('mode', state.val);
195
- }
196
-
197
- /**
198
- * Is called when the state of eco was changed
199
- */
200
- async reactToEcoRawChange(self, id, state) {
201
- self.sendEvent('eco', state.val);
202
- }
203
-
204
- /**
205
- * Send event to the airzone cloud
206
- */
207
- async sendEvent(option, value) {
208
- var payload = {
209
- 'event': {
210
- 'cgi': 'modsistema',
211
- 'device_id': this.device_id,
212
- 'system_number': this.system_number,
213
- 'option': option,
214
- 'value': value,
215
- }
216
- };
217
- await this.airzone.sendEvent(payload);
218
- }
219
-
220
- /**
221
- * Ask an update to the airzone hardware (airzonecloud don't autopull data)
222
- */
223
- async askSystemInfo() {
224
- var payload = {
225
- 'event': {
226
- 'cgi': 'infosistema2',
227
- 'device_id': this.device_id,
228
- 'system_number': this.system_number,
229
- 'option': null,
230
- 'value': null,
231
- }
232
- };
233
- await this.airzone.sendEvent(payload);
234
- }
235
- }
236
- module.exports = System;