Skip to content

Commit

Permalink
Update to Pimatic version 0.9
Browse files Browse the repository at this point in the history
adding Destroy
  • Loading branch information
360manu committed Nov 19, 2016
1 parent 08e13d0 commit 45498bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions MyThermostat.coffee
Expand Up @@ -91,6 +91,14 @@ module.exports = (env) ->
#call device constructor
super()

destroy: () ->
# shutdown device, i.e., remove Timers, de-register event handlers registered with the framework
@modeSchedule.stop()
@modeManual.stop()
@_vars.removeListener("variableAdded", @_variableAddedListener)
@_vars.removeListener("variableValueChanged", @_variableValueChangedListener)
super()

# Getter / Setter of attributes
getMode: () ->
Promise.resolve(@_mode)
Expand Down Expand Up @@ -164,11 +172,11 @@ module.exports = (env) ->
@_observedName = @config.variableTemp
@_vars = plugin.framework.variableManager
# wait till variable is added
@_vars.on "variableAdded", (variable) =>
@_vars.on "variableAdded", @_variableAddedListener = (variable) =>
if variable.name is @_observedName
@_setObservedValue(variable.getCurrentValue())
# when variable is updated
@_vars.on "variableValueChanged", (variable, value) =>
@_vars.on "variableValueChanged", @_variableValueChangedListener = (variable, value) =>
if variable.name is @_observedName
@_setObservedValue(value)

Expand Down
3 changes: 3 additions & 0 deletions controller_ON_OFF.coffee
Expand Up @@ -7,6 +7,9 @@ module.exports = (env) ->
env.logger.debug "Controller : BangBang"
@_interval = setInterval(@_controlHeating, 30 * 1000)

stop: ->
clearTimeout @_interval

setObservedValue: (value) ->
@_observedValue = value

Expand Down
3 changes: 3 additions & 0 deletions controller_PID.coffee
Expand Up @@ -19,6 +19,9 @@ module.exports = (env) ->

@_interval = setInterval(@_controlHeating, 30 * 1000)

stop: ->
clearTimeout @_interval

setObservedValue: (value) ->
env.logger.debug "observed #{value}"
@_observedValue = value
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -19,7 +19,7 @@
"type": "git",
"url": "https://github.com/360manu/pimatic-mythermostat.git"
},
"version": "0.0.1",
"version": "0.0.2",
"dependencies": {},
"peerDependencies": {
"pimatic": "0.8.* && >=0.8.31"
Expand Down

0 comments on commit 45498bc

Please sign in to comment.