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