Skip to content

Commit

Permalink
* update channel/device structures for $ selector on object updates, f…
Browse files Browse the repository at this point in the history
…ixes #109
  • Loading branch information
Apollon77 committed Feb 23, 2022
1 parent 56df6fe commit fe12052
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,14 +727,44 @@ function startAdapter(options) {
function updateObjectContext(id, obj) {
if (obj) {
// add state to state ID's list
if (obj.type === 'state' && !context.stateIds.includes(id)) {
context.stateIds.push(id);
context.stateIds.sort();
if (obj.type === 'state') {
if (!context.stateIds.includes(id) {
context.stateIds.push(id);
context.stateIds.sort();
}
if (context.devices && context.channels) {
const parts = id.split('.');
parts.pop();
const chn = parts.join('.');
context.channels[chn] = context.channels[chn] || [];
context.channels[chn].push(id);

parts.pop();
const dev = parts.join('.');
context.devices[dev] = context.devices[dev] || [];
context.devices[dev].push(id);
}
}
} else {
// delete object from state ID's list
const pos = context.stateIds.indexOf(id);
pos !== -1 && context.stateIds.splice(pos, 1);
if (context.devices && context.channels) {
const parts = id.split('.');
parts.pop();
const chn = parts.join('.');
if (context.channels[chn]) {
const posChn = context.channels[chn].indexOf(id);
posChn !== -1 && context.channels[chn].splice(posChn, 1);
}

parts.pop();
const dev = parts.join('.');
if (context.devices[dev]) {
const posDev = context.devices[dev].indexOf(id);
posDev !== -1 && context.devices[dev].splice(posDev, 1);
}
}
}

if (!obj && context.objects[id]) {
Expand Down

0 comments on commit fe12052

Please sign in to comment.