From 4e6ad732cc6df370668fc416a7865756c887ca52 Mon Sep 17 00:00:00 2001 From: jaeichel Date: Wed, 23 Feb 2022 23:43:18 -0500 Subject: [PATCH 1/7] Update main.js --- Sources/com.elgato.philips-hue.sdPlugin/pi/js/main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/com.elgato.philips-hue.sdPlugin/pi/js/main.js b/Sources/com.elgato.philips-hue.sdPlugin/pi/js/main.js index 1ddf5d0..8c1e942 100644 --- a/Sources/com.elgato.philips-hue.sdPlugin/pi/js/main.js +++ b/Sources/com.elgato.philips-hue.sdPlugin/pi/js/main.js @@ -87,6 +87,9 @@ function connectElgatoStreamDeckSocket(inPort, inUUID, inRegisterEvent, inInfo, else if (event === 'sendToPropertyInspector') { // Save global cache cache = jsonPayload; + + // Save Cached Bridges + pi.saveCachedBridges(cache); // Load bridges and lights pi.loadBridges(); From e7031ddcf420a50a21506183919dfcc5fa74ca91 Mon Sep 17 00:00:00 2001 From: jaeichel Date: Wed, 23 Feb 2022 23:44:22 -0500 Subject: [PATCH 2/7] Update pi.js --- Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js b/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js index 3260227..9df04e2 100644 --- a/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js +++ b/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js @@ -54,6 +54,14 @@ function PI(inContext, inLanguage, inStreamDeckVersion, inPluginVersion) { document.getElementById('groups').label = instance.localization['GroupsTitle']; } }; + + // Save IP addresses for bridges into global settings + this.saveCachedBridges = function(cache) { + Object.keys(cache).forEach(function(id) { + globalSettings.bridges[id].ip = cache[id].ip; + }); + saveGlobalSettings(inContext); + } // Show all paired bridges this.loadBridges = () => { From b8951a1ae38293e4b594e36432bd27457d471de1 Mon Sep 17 00:00:00 2001 From: jaeichel Date: Wed, 23 Feb 2022 23:45:26 -0500 Subject: [PATCH 3/7] Update cache.js --- .../plugin/js/philips/cache.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js b/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js index 2d1f5e1..15b9320 100644 --- a/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js +++ b/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js @@ -32,6 +32,14 @@ function Cache() { // Init discovery variable to indicate that it ran already discovery = {}; + + // init discovery from previously paired bridges + Object.keys(globalSettings.bridges).forEach(function(id) { + if (globalSettings.bridges[id].hasOwnProperty('ip')) { + log('restoring cached bridge: ' + id + ' - ' + globalSettings.bridges[id].ip); + discovery[id] = { 'ip': globalSettings.bridges[id].ip }; + } + }); // Run discovery Bridge.discover((inSuccess, inBridges) => { @@ -45,6 +53,7 @@ function Cache() { // For all discovered bridges inBridges.forEach(inBridge => { // Add new bridge to discovery object + log('discovered bridge: ' + inBridge.getID() + ' - ' + inBridge.getIP()); discovery[inBridge.getID()] = { ip: inBridge.getIP() }; From ecb690f3bcfdcdbe1d0e09f3bf743139afe592ab Mon Sep 17 00:00:00 2001 From: jaeichel Date: Thu, 24 Feb 2022 00:17:53 -0500 Subject: [PATCH 4/7] Reduce messages by only saving when changed --- Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js b/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js index 9df04e2..ab3fada 100644 --- a/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js +++ b/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js @@ -57,10 +57,16 @@ function PI(inContext, inLanguage, inStreamDeckVersion, inPluginVersion) { // Save IP addresses for bridges into global settings this.saveCachedBridges = function(cache) { + let changed = false; Object.keys(cache).forEach(function(id) { - globalSettings.bridges[id].ip = cache[id].ip; + if (globalSettings.bridges[id].ip != cache[id].ip) { + globalSettings.bridges[id].ip = cache[id].ip; + changed = true; + } }); - saveGlobalSettings(inContext); + if (changed) { + saveGlobalSettings(inContext); + } } // Show all paired bridges From 5da5b24dccec54c4c3aff9d2234b565e51698385 Mon Sep 17 00:00:00 2001 From: jaeichel Date: Thu, 24 Feb 2022 00:21:13 -0500 Subject: [PATCH 5/7] Updated function style --- Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js b/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js index ab3fada..14f9492 100644 --- a/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js +++ b/Sources/com.elgato.philips-hue.sdPlugin/pi/js/pi.js @@ -56,9 +56,9 @@ function PI(inContext, inLanguage, inStreamDeckVersion, inPluginVersion) { }; // Save IP addresses for bridges into global settings - this.saveCachedBridges = function(cache) { + this.saveCachedBridges = cache => { let changed = false; - Object.keys(cache).forEach(function(id) { + Object.keys(cache).forEach(id => { if (globalSettings.bridges[id].ip != cache[id].ip) { globalSettings.bridges[id].ip = cache[id].ip; changed = true; From 9a36f8e87160558743f5cc9b86f61be723f8f2ff Mon Sep 17 00:00:00 2001 From: jaeichel Date: Thu, 24 Feb 2022 00:22:04 -0500 Subject: [PATCH 6/7] Updated function style --- .../com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js b/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js index 15b9320..2b45b50 100644 --- a/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js +++ b/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js @@ -34,7 +34,7 @@ function Cache() { discovery = {}; // init discovery from previously paired bridges - Object.keys(globalSettings.bridges).forEach(function(id) { + Object.keys(globalSettings.bridges).forEach(id => { if (globalSettings.bridges[id].hasOwnProperty('ip')) { log('restoring cached bridge: ' + id + ' - ' + globalSettings.bridges[id].ip); discovery[id] = { 'ip': globalSettings.bridges[id].ip }; From 7160eaf862295d0aa93a2de13ebd439d78b8ba4e Mon Sep 17 00:00:00 2001 From: jaeichel Date: Thu, 24 Feb 2022 01:50:41 -0500 Subject: [PATCH 7/7] Update cache.js --- .../plugin/js/philips/cache.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js b/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js index 2b45b50..29dc34a 100644 --- a/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js +++ b/Sources/com.elgato.philips-hue.sdPlugin/plugin/js/philips/cache.js @@ -34,12 +34,14 @@ function Cache() { discovery = {}; // init discovery from previously paired bridges - Object.keys(globalSettings.bridges).forEach(id => { - if (globalSettings.bridges[id].hasOwnProperty('ip')) { - log('restoring cached bridge: ' + id + ' - ' + globalSettings.bridges[id].ip); - discovery[id] = { 'ip': globalSettings.bridges[id].ip }; - } - }); + if (globalSettings.bridges !== undefined) { + Object.keys(globalSettings.bridges).forEach(id => { + if (globalSettings.bridges[id].hasOwnProperty('ip')) { + log('restoring cached bridge: ' + id + ' - ' + globalSettings.bridges[id].ip); + discovery[id] = { 'ip': globalSettings.bridges[id].ip }; + } + }); + } // Run discovery Bridge.discover((inSuccess, inBridges) => {