basically trying my hands on Action handler/ provider… still learning coffeescript.
kindly let me know what exactly i’m doing wrong. getting “mysensorsactionhandler not defined” error each time i type “send Ir” or 'Ir" in rule window… following is the code snippet and error logs
class MySensors extends env.plugins.Plugin
init: (app, @framework, @config) =>
@board = new Board(@framework, @config)
@board.connect().then( =>
env.logger.info("Connected to MySensors Gateway.")
)
deviceConfigDef = require("./device-config-schema")
@framework.ruleManager.addActionProvider(new MySensorsActionProvider @framework,@board, config)
class MySensorsActionHandler extends env.actions.ActionHandler
constructor: (@framework,@board,@nodeid,@sensorid,@cmdCode) ->
env.logger.info " MySensorsActionHandler................."
executeAction: (simulate) =>
Promise.all( [
@framework.variableManager.evaluateStringExpression(@nodeid)
@framework.variableManager.evaluateStringExpression(@sensorid)
@framework.variableManager.evaluateStringExpression(@cmdCode)
]).then( ([node, sensor, Code]) =>
if simulate
# just return a promise fulfilled with a description about what we would do.
return __("would send IR \"%s\"", cmdCode)
else
datas = {}
datas =
{
"destination": node,
"sensor": sensor,
"type" : V_LIGHT,
"value" : Code,
"ack" : 1
}
env.logger.info " Initial MySensorsActionHandler "
return @board._rfWrite(datas).then ( () =>
env.logger.info " MySensorsActionHandler "
)
)
module.exports.MySensorsActionHandler = MySensorsActionHandler
class MySensorsActionProvider extends env.actions.ActionProvider
constructor: (@framework,@board) ->
env.logger.info " MySensorsActionProvider................."
parseAction: (input, context) =>
retVal = null
cmdCode = 0x3434434
nodeid = 16
sensorid = 6
fullMatch = no
setCmdCode = (m, tokens) => cmdCode = tokens
setSensorid = (m, tokens) => sensorid = tokens
setNodeid = (m, tokens) => nodeid = tokens
onEnd = => fullMatch = yes
m = M(input, context)
.match('send ', optional: yes)
.match('Ir')
next = m.match(' nodeid:').matchStringWithVars(setNodeid)
if next.hadMatch() then m = next
next = m.match(' sensorid:').matchStringWithVars(setSensorid)
if next.hadMatch() then m = next
next = m.match(' cmdCode:').matchStringWithVars(setCmdCode)
if next.hadMatch() then m = next
if m.hadMatch()
match = m.getFullMatch()
return {
token: match
nextInput: input.substring(match.length)
actionHandler: new MysensorsActionHandler(@framework,@board,nodeid,sensorid,cmdCode)
}
else
return null
error logs -------->
20:47:00.949 [pimatic] error: MysensorsActionHandler is not defined
20:47:01.131 [pimatic] debug: ReferenceError: MysensorsActionHandler is not defined
20:47:01.131 [pimatic] debug:> at MySensorsActionProvider.parseAction (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic-mysensors/MySensors.coffee:657:30)
20:47:01.131 [pimatic] debug:> at MySensorsActionProvider.parseAction (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic-mysensors/MySensors.coffee:1:1)
20:47:01.131 [pimatic] debug:> at RuleManager._parseAction (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/rules.coffee:486:35)
20:47:01.131 [pimatic] debug:> at RuleManager._parseAction (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/rules.coffee:1:1)
20:47:01.131 [pimatic] debug:> at RuleManager._parseRuleActions (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/rules.coffee:432:41)
20:47:01.131 [pimatic] debug:> at RuleManager.getRuleActionsHints (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/rules.coffee:1015:17)
20:47:01.131 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:261:34
20:47:01.131 [pimatic] debug:> at tryCatch1 (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/node_modules/bluebird/js/main/util.js:45:21)
20:47:01.131 [pimatic] debug:> at Function.Promise$_Try (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/node_modules/bluebird/js/main/promise.js:257:11)
20:47:01.131 [pimatic] debug:> at callActionFromReq (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:259:24)
20:47:01.131 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:316:14
20:47:01.131 [pimatic] debug:> at tryCatch1 (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/node_modules/bluebird/js/main/util.js:45:21)
20:47:01.131 [pimatic] debug:> at Function.Promise$_Try (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/node_modules/bluebird/js/main/promise.js:257:11)
20:47:01.131 [pimatic] debug:> at callActionFromReqAndRespond (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:314:24)
20:47:01.131 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:342:18
20:47:01.131 [pimatic] debug:> at callbacks (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:164:37)
20:47:01.131 [pimatic] debug:> at param (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:138:11)
20:47:01.131 [pimatic] debug:> at pass (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:145:5)
20:47:01.131 [pimatic] debug:> at nextRoute (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:100:7)
20:47:01.131 [pimatic] debug:> at callbacks (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:167:11)
20:47:01.131 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/framework.coffee:882:19
20:47:01.131 [pimatic] debug:> at callbacks (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:164:37)
20:47:01.131 [pimatic] debug:> at param (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:138:11)
20:47:01.131 [pimatic] debug:> at pass (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:145:5)
20:47:01.131 [pimatic] debug:> at Router._dispatch (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:173:5)
20:47:01.131 [pimatic] debug:> at Object.router (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:33:10)
20:47:01.131 [pimatic] debug:> at next (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/proto.js:193:15)
20:47:01.131 [pimatic] debug:> at Object.handle (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/framework.coffee:258:18)
20:47:01.131 [pimatic] debug:> at next (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/proto.js:193:15)
20:47:01.131 [pimatic] debug:> at Object.cookieSession [as handle] (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/middleware/cookieSession.js:120:5)
20:47:01.131 [pimatic] debug:> at next (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/proto.js:193:15)
20:47:01.131 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/middleware/json.js:81:7
20:47:01.131 [pimatic] debug:> at IncomingMessage.onEnd (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:109:7)
20:47:01.131 [pimatic] debug:> at IncomingMessage.g (events.js:180:16)
20:47:01.131 [pimatic] debug:> at IncomingMessage.EventEmitter.emit (events.js:92:17)
20:47:01.131 [pimatic] debug:> at _stream_readable.js:920:16
20:47:01.131 [pimatic] debug:> at process._tickCallback (node.js:415:13)
20:47:01.691 [pimatic] error: MysensorsActionHandler is not defined
20:47:01.703 [pimatic] debug: ReferenceError: MysensorsActionHandler is not defined
20:47:01.703 [pimatic] debug:> at MySensorsActionProvider.parseAction (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic-mysensors/MySensors.coffee:657:30)
20:47:01.703 [pimatic] debug:> at MySensorsActionProvider.parseAction (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic-mysensors/MySensors.coffee:1:1)
20:47:01.703 [pimatic] debug:> at RuleManager._parseAction (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/rules.coffee:486:35)
20:47:01.703 [pimatic] debug:> at RuleManager._parseAction (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/rules.coffee:1:1)
20:47:01.703 [pimatic] debug:> at RuleManager._parseRuleActions (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/rules.coffee:432:41)
20:47:01.703 [pimatic] debug:> at RuleManager.getRuleActionsHints (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/rules.coffee:1015:17)
20:47:01.703 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:261:34
20:47:01.703 [pimatic] debug:> at tryCatch1 (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/node_modules/bluebird/js/main/util.js:45:21)
20:47:01.703 [pimatic] debug:> at Function.Promise$_Try (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/node_modules/bluebird/js/main/promise.js:257:11)
20:47:01.703 [pimatic] debug:> at callActionFromReq (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:259:24)
20:47:01.703 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:316:14
20:47:01.703 [pimatic] debug:> at tryCatch1 (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/node_modules/bluebird/js/main/util.js:45:21)
20:47:01.703 [pimatic] debug:> at Function.Promise$_Try (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/node_modules/bluebird/js/main/promise.js:257:11)
20:47:01.703 [pimatic] debug:> at callActionFromReqAndRespond (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:314:24)
20:47:01.703 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/decl-api/index.js:342:18
20:47:01.703 [pimatic] debug:> at callbacks (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:164:37)
20:47:01.703 [pimatic] debug:> at param (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:138:11)
20:47:01.703 [pimatic] debug:> at pass (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:145:5)
20:47:01.703 [pimatic] debug:> at nextRoute (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:100:7)
20:47:01.703 [pimatic] debug:> at callbacks (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:167:11)
20:47:01.703 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/framework.coffee:882:19
20:47:01.703 [pimatic] debug:> at callbacks (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:164:37)
20:47:01.703 [pimatic] debug:> at param (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:138:11)
20:47:01.703 [pimatic] debug:> at pass (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:145:5)
20:47:01.703 [pimatic] debug:> at Router._dispatch (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:173:5)
20:47:01.703 [pimatic] debug:> at Object.router (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/lib/router/index.js:33:10)
20:47:01.703 [pimatic] debug:> at next (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/proto.js:193:15)
20:47:01.703 [pimatic] debug:> at Object.handle (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/lib/framework.coffee:258:18)
20:47:01.703 [pimatic] debug:> at next (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/proto.js:193:15)
20:47:01.703 [pimatic] debug:> at Object.cookieSession [as handle] (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/middleware/cookieSession.js:120:5)
20:47:01.703 [pimatic] debug:> at next (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/proto.js:193:15)
20:47:01.703 [pimatic] debug:> at /home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/lib/middleware/json.js:81:7
20:47:01.703 [pimatic] debug:> at IncomingMessage.onEnd (/home/dheeraj/Documents/Work/pimatic-app/node_modules/pimatic/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:109:7)
20:47:01.703 [pimatic] debug:> at IncomingMessage.g (events.js:180:16)
20:47:01.703 [pimatic] debug:> at IncomingMessage.EventEmitter.emit (events.js:92:17)
20:47:01.703 [pimatic] debug:> at _stream_readable.js:920:16
20:47:01.703 [pimatic] debug:> at process._tickCallback (node.js:415:13)/