@@ -14,7 +14,9 @@ module.exports = function (RED) {
14
14
15
15
const deviceId = 'vshd-' + node . id . replace ( '.' , '' )
16
16
17
- const connectionNode = RED . nodes . getNode ( config . connection )
17
+ const getConnectionNode = ( ) => {
18
+ return RED . nodes . getNode ( config . connection )
19
+ }
18
20
19
21
const validators = getValidators ( config . template )
20
22
const decorator = getDecorator ( config . template , config . diff )
@@ -79,10 +81,10 @@ module.exports = function (RED) {
79
81
return approvedState
80
82
}
81
83
82
- if ( connectionNode ) {
84
+ if ( getConnectionNode ( ) ) {
83
85
//connection is configured
84
86
//register callbacks. This way connectionNode can communicate with us:
85
- connectionNode . registerChildNode ( deviceId , {
87
+ getConnectionNode ( ) . registerChildNode ( deviceId , {
86
88
setStatus : ( status , force = false ) => {
87
89
if ( isActive || force ) {
88
90
node . status ( status )
@@ -106,7 +108,7 @@ module.exports = function (RED) {
106
108
}
107
109
108
110
node . on ( 'input' , function ( msg , send , done ) {
109
- if ( ! connectionNode || ! isActive ) {
111
+ if ( ! getConnectionNode ( ) || ! isActive ) {
110
112
console . log (
111
113
`ignoring inbound msg for non-active device ID ${ deviceId } '`
112
114
)
@@ -152,7 +154,7 @@ module.exports = function (RED) {
152
154
const confirmedNewLocalState = setLocalState ( newLocalState )
153
155
154
156
if ( ! deepEql ( oldLocalState , newLocalState ) ) {
155
- connectionNode . handleLocalDeviceStateChange ( {
157
+ getConnectionNode ( ) . handleLocalDeviceStateChange ( {
156
158
deviceId,
157
159
oldState : oldLocalState ,
158
160
newState : confirmedNewLocalState ,
@@ -169,8 +171,8 @@ module.exports = function (RED) {
169
171
} )
170
172
171
173
node . on ( 'close' , async function ( removed , done ) {
172
- if ( connectionNode ) {
173
- await connectionNode . unregisterChildNode ( deviceId )
174
+ if ( getConnectionNode ( ) ) {
175
+ await getConnectionNode ( ) . unregisterChildNode ( deviceId )
174
176
}
175
177
node . status ( { } )
176
178
return done ( )
0 commit comments