@@ -51,7 +51,22 @@ module.exports = function (RED) {
5151 node . exposedGAs = [ ] ;
5252 node . commandText = [ ] ; // Raw list Respond To
5353 node . timerSaveExposedGAs = null ;
54- if ( node . serverKNX === null ) { node . status ( { fill : 'red' , shape : 'dot' , text : '[NO GATEWAY SELECTED]' } ) ; return ; }
54+
55+ const shouldDisplayStatus = ( color ) => {
56+ const provider = node . serverKNX ;
57+ if ( provider && typeof provider . shouldDisplayStatus === 'function' ) {
58+ return provider . shouldDisplayStatus ( color ) ;
59+ }
60+ return true ;
61+ } ;
62+
63+ const updateStatus = ( status ) => {
64+ if ( ! status ) return ;
65+ if ( shouldDisplayStatus ( status . fill ) ) {
66+ node . status ( status ) ;
67+ }
68+ } ;
69+ if ( node . serverKNX === null ) { updateStatus ( { fill : 'red' , shape : 'dot' , text : '[NO GATEWAY SELECTED]' } ) ; return ; }
5570
5671 try {
5772 const baseLogLevel = ( node . serverKNX && node . serverKNX . loglevel ) ? node . serverKNX . loglevel : 'error' ;
@@ -109,7 +124,7 @@ module.exports = function (RED) {
109124
110125 // Add the ETS CSV file list to exposedGAs
111126 if ( node . serverKNX . csv === undefined || node . serverKNX . csv === '' || node . serverKNX . csv . length === 0 ) {
112- node . status ( { fill : 'grey' , shape : 'ring' , text : 'No ETS file imported' , payload : '' , dpt : '' , devicename : '' } ) ;
127+ updateStatus ( { fill : 'grey' , shape : 'ring' , text : 'No ETS file imported' , payload : '' , dpt : '' , devicename : '' } ) ;
113128 //return;
114129 } else {
115130 node . serverKNX . csv . forEach ( element => {
@@ -120,14 +135,14 @@ module.exports = function (RED) {
120135 curGa . enabled = false ;
121136 }
122137 } )
123- node . status ( { fill : 'green' , shape : 'ring' , text : 'ETS file loaded' , payload : '' , dpt : '' , devicename : '' } ) ;
138+ updateStatus ( { fill : 'green' , shape : 'ring' , text : 'ETS file loaded' , payload : '' , dpt : '' , devicename : '' } ) ;
124139 }
125140
126141 // Fill the filter list
127142 try {
128143 node . commandText = JSON . parse ( config . commandText ) ;
129144 } catch ( error ) {
130- node . status ( { fill : 'red' , shape : 'dot' , text : 'JSON error: ' + error . message , payload : '' , dpt : '' , devicename : '' } ) ;
145+ updateStatus ( { fill : 'red' , shape : 'dot' , text : 'JSON error: ' + error . message , payload : '' , dpt : '' , devicename : '' } ) ;
131146 if ( node . sysLogger !== undefined && node . sysLogger !== null ) node . sysLogger . error ( `knxUltimateAutoResponder: node.commandText = JSON.parse(config.commandText) ${ error . stack } ` ) ;
132147 return ;
133148 }
@@ -164,10 +179,10 @@ module.exports = function (RED) {
164179 // Delete all not wanted GAs, that aren't in the node.commandText directive list.
165180 node . exposedGAs = node . exposedGAs . filter ( a => ( a . enabled !== undefined && a . enabled === true ) ) ;
166181
167- node . status ( { fill : 'green' , shape : 'ring' , text : 'JSON parsed: ' + node . commandText . length + " directive(s)." , payload : '' , dpt : '' , devicename : '' } ) ;
182+ updateStatus ( { fill : 'green' , shape : 'ring' , text : 'JSON parsed: ' + node . commandText . length + " directive(s)." , payload : '' , dpt : '' , devicename : '' } ) ;
168183 } else {
169184 // Error
170- node . status ( { fill : 'red' , shape : 'dot' , text : 'JSON error: ga or default keys not set. Abort.' , payload : '' , dpt : '' , devicename : '' } ) ;
185+ updateStatus ( { fill : 'red' , shape : 'dot' , text : 'JSON error: ga or default keys not set. Abort.' , payload : '' , dpt : '' , devicename : '' } ) ;
171186 if ( node . sysLogger !== undefined && node . sysLogger !== null ) node . sysLogger . error ( `knxUltimateAutoResponder: node.commandText.forEach(element.. JSON error: ga or default keys not set. Abort.` ) ;
172187 return ;
173188 }
@@ -191,7 +206,7 @@ module.exports = function (RED) {
191206 // Take only RAW data and decode it with the dpt specified by the commandText directive
192207 decodedPayload = dptlib . fromBuffer ( msg . knx . rawValue , dptlib . resolve ( oGa . dpt ) ) ;
193208 } catch ( error ) {
194- node . status ( { fill : 'red' , shape : 'dot' , text : 'const decodedPayload = dptlib.fromBuffer(msg.knx.rawValue, dptlib.resolve(oGa.dpt)); ' + error . message , payload : '' , dpt : '' , devicename : '' } ) ;
209+ updateStatus ( { fill : 'red' , shape : 'dot' , text : 'const decodedPayload = dptlib.fromBuffer(msg.knx.rawValue, dptlib.resolve(oGa.dpt)); ' + error . message , payload : '' , dpt : '' , devicename : '' } ) ;
195210 if ( node . sysLogger !== undefined && node . sysLogger !== null ) node . sysLogger . error ( `knxUltimateAutoResponder: const decodedPayload = dptlib.fromBuffer(msg.knx.rawValue, dptlib.resolve(oGa.dpt)); ${ error . stack } ` ) ;
196211 }
197212 oGa . payload = decodedPayload
@@ -211,9 +226,9 @@ module.exports = function (RED) {
211226 const dDate = new Date ( )
212227 if ( oFoundGA . address !== undefined && oFoundGA . dpt !== undefined && retVal !== undefined ) {
213228 node . serverKNX . sendKNXTelegramToKNXEngine ( { grpaddr : oFoundGA . address , payload : retVal , dpt : oFoundGA . dpt , outputtype : 'response' , nodecallerid : node . id } ) ;
214- node . status ( { fill : 'blue' , shape : 'dot' , text : 'Respond ' + oFoundGA . address + ' => ' + retVal + ' (' + dDate . getDate ( ) + ', ' + dDate . toLocaleTimeString ( ) + ')' } )
229+ updateStatus ( { fill : 'blue' , shape : 'dot' , text : 'Respond ' + oFoundGA . address + ' => ' + retVal + ' (' + dDate . getDate ( ) + ', ' + dDate . toLocaleTimeString ( ) + ')' } )
215230 } else {
216- node . status ( { fill : 'yellow' , shape : 'ring' , text : 'Issue responding ' + oFoundGA . address + ' => ' + retVal + ' (' + dDate . getDate ( ) + ', ' + dDate . toLocaleTimeString ( ) + ')' } )
231+ updateStatus ( { fill : 'yellow' , shape : 'ring' , text : 'Issue responding ' + oFoundGA . address + ' => ' + retVal + ' (' + dDate . getDate ( ) + ', ' + dDate . toLocaleTimeString ( ) + ')' } )
217232 }
218233 }
219234 } catch ( error ) {
0 commit comments