Skip to content

Commit 8d50a99

Browse files
committed
Force the refresh from hue hub, of hue light when button in pressen.
1 parent afbbc4a commit 8d50a99

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

nodes/commonFunctions.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ module.exports = (RED) => {
649649
}
650650
});
651651

652-
RED.httpAdmin.get("/KNXUltimateGetResourcesHUE", (req, res) => {
652+
RED.httpAdmin.get("/KNXUltimateGetResourcesHUE", async (req, res) => {
653653
try {
654654
// °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
655655
const serverId = RED.nodes.getNode(req.query.serverId); // Retrieve node.id of the config node.
@@ -660,7 +660,9 @@ module.exports = (RED) => {
660660
res.json({ devices: jRet });
661661
return;
662662
}
663-
const jRet = serverId.getResources(req.query.rtype);
663+
const refreshFlag = (req.query.forceRefresh || '').toString().toLowerCase();
664+
const forceRefresh = refreshFlag === '1' || refreshFlag === 'true' || refreshFlag === 'yes';
665+
const jRet = await serverId.getResources(req.query.rtype, { forceRefresh });
664666
if (jRet !== undefined) {
665667
res.json(jRet);
666668
} else {

nodes/hue-config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,15 @@ module.exports = (RED) => {
234234
};
235235

236236
// Returns the cached devices (node.hueAllResources) by type.
237-
node.getResources = function getResources(_rtype) {
237+
node.getResources = async function getResources(_rtype, { forceRefresh = false } = {}) {
238238
try {
239+
if (forceRefresh) {
240+
try {
241+
await node.loadResourcesFromHUEBridge();
242+
} catch (error) {
243+
node.sysLogger?.warn(`KNXUltimateHue: getResources force refresh failed ${error.message}`);
244+
}
245+
}
239246
if (node.hueAllResources === undefined) return;
240247
// Returns capitalized string
241248
function capStr(s) {

nodes/knxUltimateHueLight.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@
328328
if ($hueDevicesLoading.length) {
329329
$hueDevicesLoading.show();
330330
}
331-
$.getJSON(`KNXUltimateGetResourcesHUE?rtype=light&serverId=${encodeURIComponent(hueServer.id)}&_=${Date.now()}`, (data) => {
331+
const refreshQuery = forceRefresh ? '&forceRefresh=1' : '';
332+
$.getJSON(`KNXUltimateGetResourcesHUE?rtype=light&serverId=${encodeURIComponent(hueServer.id)}${refreshQuery}&_=${Date.now()}`, (data) => {
332333
const listCandidates = Array.isArray(data) ? data : (Array.isArray(data?.devices) ? data.devices : []);
333334
cachedHueDevices = listCandidates.map((value) => {
334335
const deviceObject = value.deviceObject || value;

0 commit comments

Comments
 (0)