-
Notifications
You must be signed in to change notification settings - Fork 44
Cache and restore bridge IP addresses into global settings #30
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get the use of that function. I mean, I get your intention. But this function replaces the IP in the global settings every time by the ip from the cache. I don't get why doing this is better. An this would inflict every dhcp connected bridge too, or not? |
||
let changed = false; | ||
Object.keys(cache).forEach(id => { | ||
if (globalSettings.bridges[id].ip != cache[id].ip) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weak typecheck. Also no check if |
||
globalSettings.bridges[id].ip = cache[id].ip; | ||
changed = true; | ||
} | ||
}); | ||
if (changed) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space missing. ;) |
||
saveGlobalSettings(inContext); | ||
} | ||
} | ||
|
||
// Show all paired bridges | ||
this.loadBridges = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use template strings. |
||
discovery[id] = { 'ip': globalSettings.bridges[id].ip }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is js, not json. Don't use quotes for object properties. ;) And mybe use indention like the rest of the code. |
||
} | ||
}); | ||
} | ||
|
||
// 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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use template strings. |
||
discovery[inBridge.getID()] = { | ||
ip: inBridge.getIP() | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like this location in the code... is there a better one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the process either. Saving all bridges right before loading them seems counterintuitive. ;) But let's speak about the process first, because as I mentioned it may not be a good idea ...