File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments