Skip to content

Instantly share code, notes, and snippets.

@mdobson
Forked from 13protons/app.js
Last active August 29, 2015 14:07
Show Gist options
  • Save mdobson/76466413160a795d7e0c to your computer and use it in GitHub Desktop.
Save mdobson/76466413160a795d7e0c to your computer and use it in GitHub Desktop.
module.exports = function(server) {
var buttonQuery = server.where({type: 'button'});
server.observe([buttonQuery], function(button){
button.on('click', function(b){
//This will log undefined because there are no inputs to this transition
//You can use dot notation to access properties on devices
//console.log(b);
console.log(button.b);
})
});
}
var Device = require('zetta').Device;
var util = require('util');
var Button = module.exports = function(n) {
Device.call(this);
this.name = n || 'Button';
};
util.inherits(Button, Device);
Button.prototype.init = function(config) {
//Name is set in here.
config
.state('ready')
.type('button')
.name(this.name)
.when('ready', { allow: ['click'] })
.map('click', this.Click);
};
Button.prototype.Click = function(cb) {
cb();
};
var zetta = require('zetta');
var Button = require('./devices/button');
var app = require('./apps/app.js');
zetta()
.use(Button, 'Lights')
.use(Button, 'Camera')
.use(app)
.listen(1337);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment