iobroker.zigbee 1.10.14 → 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.
package/lib/exclude.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ const devicedefinitions = require('./devices');
2
3
 
3
4
  class Exclude {
4
5
  constructor(adapter) {
@@ -9,6 +10,7 @@ class Exclude {
9
10
  start(zbController, stController) {
10
11
  this.zbController = zbController;
11
12
  this.stController = stController;
13
+ this.localConfig = stController.localConfig;
12
14
  }
13
15
 
14
16
  stop() {
@@ -52,6 +54,12 @@ class Exclude {
52
54
  this.adapter.sendTo(obj.from, obj.command, exclude, obj.callback));
53
55
  }
54
56
  break;
57
+ case 'getExcludable':
58
+ if (obj && obj.message && typeof obj.message === 'object') {
59
+ this.getExcludable(exclude =>
60
+ this.adapter.sendTo(obj.from, obj.command, exclude, obj.callback));
61
+ }
62
+ break;
55
63
  case 'delExclude':
56
64
  if (obj && obj.message) {
57
65
  this.delExclude(obj.from, obj.command, obj.message, err =>
@@ -74,7 +82,7 @@ class Exclude {
74
82
  }
75
83
 
76
84
  extractExcludeId(stateId) {
77
- return stateId.replace(`${this.adapter.namespace}.exclude.`, '');
85
+ return stateId.replace(`${this.adapter.namespace}.info.legacy.`, '');
78
86
  }
79
87
 
80
88
  getExcludeName(devName, stateId) {
@@ -83,18 +91,10 @@ class Exclude {
83
91
 
84
92
  async addExclude(from, command, params, callback) {
85
93
  try {
86
- this.debug('addExclude message: ' + JSON.stringify(params));
94
+ //this.warn('addExclude message: ' + JSON.stringify(params));
87
95
  const exclude_mod = params.exclude_model.common.type;
88
- const stateId = `exclude.${exclude_mod}`;
89
-
90
- this.adapter.setObjectNotExists(stateId,
91
- {
92
- type: 'state',
93
- common: {name: exclude_mod},
94
- },
95
- () => this.adapter.setState(stateId, exclude_mod, true, () =>
96
- callback()),
97
- );
96
+ this.localConfig.updateLocalOverride(exclude_mod, exclude_mod, 'legacy', exclude_mod, true);
97
+ callback({});
98
98
  } catch (error) {
99
99
  this.error(`Failed to addExclude ${error.stack}`);
100
100
  throw new Error(`Failed to addExclude ${error.stack}`);
@@ -104,58 +104,34 @@ class Exclude {
104
104
  async delExclude(from, command, exclude_id, callback) {
105
105
  try {
106
106
  this.debug(`delExclude message: ${JSON.stringify(exclude_id)}`);
107
- const stateId = `exclude.${exclude_id}`;
108
- this.adapter.getStateAsync(stateId)
109
- .then(async (stateV) => {
110
- this.debug(`found state: ${JSON.stringify(stateV)}`);
111
- this.adapter.deleteState(null, 'exclude', exclude_id, async () =>
112
- callback());
113
- });
107
+ this.localConfig.updateLocalOverride(exclude_id, exclude_id, 'legacy', '', true);
108
+ callback({});
114
109
  } catch (error) {
115
110
  this.error(`Failed to delExclude ${error.stack}`);
116
111
  throw new Error(`Failed to delExclude ${error.stack}`);
117
112
  }
118
113
  }
119
114
 
120
- getExclude(callback) {
115
+ async getExclude(callback) {
121
116
  try {
122
- const exclude = [];
123
- this.adapter.getStatesOf('exclude', (err, states) => {
124
- if (!err && states) {
125
- const exc = [];
126
- states.forEach(state => {
127
- if (state._id.startsWith(`${this.adapter.namespace}.exclude`)) {
128
- exc.push(new Promise(resolve =>
129
- this.adapter.getStateAsync(state._id)
130
- .then(stateVa => {
131
- if (stateVa !== null) {
132
- const val = {
133
- id: this.extractExcludeId(state._id),
134
- name: stateVa.val
135
- };
136
- if (this.extractExcludeId(state._id) !== 'all') {
137
- exclude.push(val);
138
- }
139
- }
140
- resolve();
141
- })));
142
- }
143
- });
144
- return Promise.all(exc)
145
- .then(() => {
146
- const arrExclude = JSON.stringify(exclude);
147
- this.debug(`getExclude result: ${arrExclude}`);
148
- this.adapter.setState('exclude.all', arrExclude, true, () =>
149
- callback(exclude));
150
- });
151
- } else {
152
- this.debug(`getExclude result: ${JSON.stringify(exclude)}`);
153
- callback(exclude);
154
- }
155
- });
117
+ const exclude = this.localConfig.getOverridesWithKey('legacy', true)
118
+ callback({legacy: exclude});
156
119
  } catch (error) {
157
120
  this.error(`Failed to getExclude ${error.stack}`);
121
+ callback({error: 'unable to get excludes' });
122
+ }
123
+ }
124
+
125
+ async getExcludable(callback) {
126
+ const devices = this.zbController.getClients();
127
+ const excludables = [];
128
+ for (const device of devices) {
129
+ const obj = await this.adapter.getObjectAsync(device.ieeeAddr.substr(2));
130
+ if (obj && obj.common && obj.common.type) {
131
+ excludables.push(obj.common.tyoe);
132
+ }
158
133
  }
134
+ callback(devices.pairedLegacyDevices(excludables));
159
135
  }
160
136
  }
161
137