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(); 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..14f9492 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,20 @@ function PI(inContext, inLanguage, inStreamDeckVersion, inPluginVersion) { document.getElementById('groups').label = instance.localization['GroupsTitle']; } }; + + // Save IP addresses for bridges into global settings + this.saveCachedBridges = cache => { + let changed = false; + Object.keys(cache).forEach(id => { + if (globalSettings.bridges[id].ip != cache[id].ip) { + globalSettings.bridges[id].ip = cache[id].ip; + changed = true; + } + }); + if (changed) { + saveGlobalSettings(inContext); + } + } // Show all paired bridges this.loadBridges = () => { 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..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 @@ -32,6 +32,16 @@ function Cache() { // Init discovery variable to indicate that it ran already discovery = {}; + + // init discovery from previously paired bridges + 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) => { @@ -45,6 +55,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() };