@@ -7,12 +7,15 @@ import {
77} from 'node-red'
88import { util } from '@node-red/util'
99import { ISmallTimerProperties , Rule } from '../nodes/common'
10- import { SmallTimerChangeMessage , ISmallTimerMessage } from './interfaces'
10+ import {
11+ SmallTimerChangeMessage ,
12+ ISmallTimerMessage ,
13+ Trigger ,
14+ State ,
15+ } from './interfaces'
1116import { TimeCalc } from './time-calculation'
1217import { Timer } from './timer'
1318
14- type Override = 'auto' | 'tempOn' | 'tempOff'
15-
1619type NodeFunctions = Node
1720
1821type Position = {
@@ -29,7 +32,7 @@ export class SmallTimerRunner {
2932 // Timing variables
3033 private tickTimer : ReturnType < typeof setInterval > | undefined = undefined
3134
32- private override : Override = 'auto'
35+ private override : State = 'auto'
3336 private currentState = false
3437
3538 private topic : string
@@ -102,7 +105,7 @@ export class SmallTimerRunner {
102105 } as NodeMessage // we cheat a bit to escape type checking in typescript
103106 }
104107
105- private generateMsg ( ) : SmallTimerChangeMessage {
108+ private generateMsg ( trigger : Trigger ) : SmallTimerChangeMessage {
106109 const on = this . getCurrentState ( )
107110
108111 const payload = on
@@ -118,14 +121,15 @@ export class SmallTimerRunner {
118121 timeout : this . timer . timeLeft ( ) ,
119122 payload : payload ,
120123 topic : this . topic ,
124+ trigger,
121125 }
122126 }
123127
124- private publishState ( ) : void {
128+ private publishState ( trigger : Trigger ) : void {
125129 if ( this . debugMode ) {
126- this . node . send ( [ this . generateMsg ( ) , this . generateDebug ( ) ] )
130+ this . node . send ( [ this . generateMsg ( trigger ) , this . generateDebug ( ) ] )
127131 } else {
128- this . node . send ( this . generateMsg ( ) )
132+ this . node . send ( this . generateMsg ( trigger ) )
129133 }
130134 }
131135
@@ -177,14 +181,14 @@ export class SmallTimerRunner {
177181 this . updateNodeStatus ( )
178182
179183 if ( change || this . repeat ) {
180- this . publishState ( )
184+ this . publishState ( 'timer' )
181185 }
182186 }
183187
184- private forceSend ( ) : void {
188+ private forceSend ( trigger : Trigger = 'timer' ) : void {
185189 this . calcState ( )
186190 this . updateNodeStatus ( )
187- this . publishState ( )
191+ this . publishState ( trigger )
188192 }
189193
190194 /**
@@ -269,7 +273,7 @@ export class SmallTimerRunner {
269273 this . node . status ( status )
270274 }
271275
272- private doOverride ( override : Override , timeout ?: number ) : void {
276+ private doOverride ( override : State , timeout ?: number ) : void {
273277 this . override = override
274278 if ( override === 'auto' ) {
275279 this . timer . stop ( )
@@ -309,7 +313,7 @@ export class SmallTimerRunner {
309313 // eslint-disable-next-line no-extra-boolean-cast
310314 if ( incomingMsg . reset !== undefined ) {
311315 this . doOverride ( 'auto' )
312- this . forceSend ( )
316+ this . forceSend ( 'input' )
313317 return
314318 }
315319
@@ -348,7 +352,7 @@ export class SmallTimerRunner {
348352 default :
349353 throw new Error ( `Did not understand the command '${ incomingMsg . payload } ' supplied in payload` )
350354 }
351- this . forceSend ( )
355+ this . forceSend ( 'input' )
352356 }
353357
354358 /**
0 commit comments