diff --git a/admin/custom_m.html b/admin/custom_m.html
index 82f93972e..e93bf08a6 100644
--- a/admin/custom_m.html
+++ b/admin/custom_m.html
@@ -12,6 +12,7 @@
+
@@ -193,4 +194,4 @@
});
}
-
\ No newline at end of file
+
diff --git a/lib/server.js b/lib/server.js
index 286953f1d..3b525699d 100644
--- a/lib/server.js
+++ b/lib/server.js
@@ -224,7 +224,10 @@ class WebServer {
_readAllEntities(cb) {
this._updateDevices()
.then(smartDevices => {
- this._entities = smartDevices;
+ smartDevices.forEach((dev, devidx) => {
+ const foundIndex = this._entities.findIndex(x => x.entity_id === dev.entity_id);
+ if (foundIndex != -1) {this._entities[foundIndex] = dev;} else {this._entities.push(dev);}
+ });
this._getAllEntities(() => {
this._getAllStates(() => {
this._manageSubscribesFromConfig();
@@ -362,9 +365,14 @@ class WebServer {
}
this._ID2entity[obj._id] = this._ID2entity[obj._id] || [];
- this._ID2entity[obj._id].push(entity);
+ this._addID2entity(obj._id, entity);
this._entity2ID[entity.entity_id] = entity;
- this._entities.push(entity);
+ const foundIndex = this._entities.findIndex(x => x.entity_id === entity.entity_id);
+ if (foundIndex !== -1) {
+ this._entities[foundIndex] = entity;
+ } else {
+ this._entities.push(entity);
+ }
return entity;
}
@@ -2508,9 +2516,11 @@ class WebServer {
}
};
- this._entities.map(obj => entity.entity_id === obj.entity_id ? entity : obj);
- //moved update of _entities here because entity variable gets undefined after the _wss call below...
-
+ const foundIndex = this._entities.findIndex(x => x.entity_id === entity.entity_id);
+ if (foundIndex !== -1) {
+ this._entities[foundIndex] = entity;
+ }
+
this._wss.clients.forEach(ws => {
if (ws._subscribes && ws._subscribes.state_changed) {
ws._subscribes.state_changed.forEach(id => {
@@ -2530,6 +2540,11 @@ class WebServer {
if (!id) {
return;
}
+
+ // object might be deleted but still in room/func enums.
+ if (!objects[id]) {
+ return;
+ }
let friendlyName = this._getSmartName(objects, id);
if (typeof friendlyName === 'object' && friendlyName) {
@@ -2565,8 +2580,7 @@ class WebServer {
const _entity = result.find(e => e.entity_id === entity.entity_id);
if (_entity) {
- this.log.debug('Duplicates found for ' + entity.entity_id);
- return;
+ return this.log.debug('Duplicates found for ' + entity.entity_id);
}
result.push(entity);