The pimatic-shell-execute changes are
In the directory pimatic-shell-execute
changes in device-config-schema.coffee
add the following to ShellSwitch
autoReset:
description: "
if true and the the device is present, reset the state to absent
after resetTime has been reached.
"
type: "boolean"
default: false
resetTime:
description: "
Time in milliseconds after that the presence value is
reset to absent.
"
type: "integer"
default: 10000
change in file shell-execute.coffee. There are a few changes but its easier to replace the complete class ShellSwitch … with:
class ShellSwitch extends env.devices.PowerSwitch
constructor: (@config, lastState) ->
@name = @config.name
@id = @config.id
@base = commons.base @, @config.class
@forceExecution = @config.forceExecution
@_state = lastState?.state?.value or off
@_triggerAutoReset()
updateValue = =>
if @config.interval > 0
@_updateValueTimeout = null
@getState().finally( =>
@_updateValueTimeout = setTimeout(updateValue, @config.interval)
)
super()
if @config.getStateCommand?
updateValue()
destroy: () ->
clearTimeout @_updateValueTimeout if @_updateValueTimeout?
clearTimeout @_resetStateTimeout if @_resetStateTimeout?
super()
_triggerAutoReset: ->
if @config.autoReset# and @_state
clearTimeout(@_resetStateTimeout) if @_resetStateTimeout?
@_resetStateTimeout = setTimeout(
( () =>
@_setState(off)
@_resetStateTimeout = null
)
, @config.resetTime
)
getState: () ->
if not @config.getStateCommand?
return Promise.resolve @_state
else
return exec(@config.getStateCommand, plugin.execOptions).then( ({stdout, stderr}) =>
stdout = stdout.trim()
switch stdout
when "on", "true", "1", "t", "o"
@_setState(on)
return Promise.resolve @_state
when "off", "false", "0", "f"
@_setState(off)
return Promise.resolve @_state
else
@base.error "stderr output from getStateCommand for #{@name}: #{stderr}" if stderr.length isnt 0
throw new Error "unknown state=\"#{stdout}\"!"
).catch( (error) =>
@base.rejectWithErrorString Promise.reject, transformError(error)
)
changeStateTo: (state) ->
if @_state is state and not @forceExecution then return Promise.resolve()
# and execute it.
if state then @_triggerAutoReset()
command = (if state then @config.onCommand else @config.offCommand)
return exec(command, plugin.execOptions).then( ({stdout, stderr}) =>
@base.error "stderr output from on/offCommand for #{@name}: #{stderr}" if stderr.length isnt 0
@_setState(state)
).catch( (error) =>
@base.rejectWithErrorString Promise.reject, transformError(error)
)
restart Pimatic