A home automation framework
Create issues for feature requests or bugs. - Make your feature in a new branch `git checkout -b my-feature-branch` - Add unit tests for testable features - Push the branch `git push origin my-feature-branch` - Make a pull request from the GitHub site - Ask someone to make sure your changes don't break anything existing before merging - Wait for the tests to run before merging Things are moving fast, so if you need changes from master that were added after you branched off, do this: - Commit your changes - Update master `git fetch origin` - Rebase your feature branch from master `git rebase origin/master` - Force push your changes onto your branch `git push origin +my-feature-branch` In `app.js`, start Pluto like this: ```javascript var pluto = require("./Pluto/pluto.js")({ "id": "IP" });//Add modules here
pluto.listen(process.env.PORT || 3000);
IDs for users can be generated by `IP` to use their unique IP on the local network, `COOKIE` to generate a random string and store it in a cookie, and `TEST` to specify your own function to get the ip for a user given a request (see the Testing section for more details).
New modules are added like this:
```javascript
pluto.addModule(require("./plugins/example-module.js")(pluto));
Modules tend to fall into two categories, sources and responders.
Modules can interact with the system in a few ways: - Respond to HTTP endpoints - Emit events - Listen and respond to events - Schedule tasks - Save storageA typical module looks like this:
module.exports = function(pluto) {
var module = {};
//Load existing data
var data = pluto.getStorage("example-module");
if (!data.counter) {
data.counter = 0;
pluto.saveStorage("example-module");
}
//Register a routing handler
pluto.get("/", function(req, res) {
data.counter++;
//Display a response in the browser
res.send("There have been " + data.counter + " visits");
//Send an event for modules to listen for
pluto.emitEvent("example-source::visit", data.counter);
//Save data for the next time the server is restarted
pluto.saveStorage("example-source");
});
//Register listeners
pluto.addListener("example-source::visit", function(visits) {
console.log("Hello, visitor #" + visits + "!");
};
return module;
};
Pluto can use test IDs for users by specifying a function to be called when an ID is requested:
```javascript
var pluto = require("../Pluto/pluto.js")({
id: "TEST",
getId: function(req, res) {
//Assume the user making the request always has the ID "test"
return "test";
}
});
Requests made using pluto.request
can be spoofed:
var pluto = require("../Pluto/pluto.js")({
testRequests: {
"https://api.spotify.com/v1/search?q=Slim%20Shady&type=track": {
body: {
tracks: [ ... ]
},
status: 200
}
},
});
Use supertest to test HTTP endpoints:
var request = require('supertest');
it("should sign in a user who is out when they GET /users/io", function(done) {
request(pluto.app)
.get("/users/io")
.expect(200)
.end(function(err, res) {
if (err) return done(err);
assert.equal(pluto.getStorage("users")["test"].in, true)
done()
});
});
Tests can be run with: npm test
On windows, download and install the binaries from http://downloads.sourceforge.net/e-guidedog/festival-2.1.1-win.7z specifically to the directory C:\festival
and then add C:\festival\bin
to your $PATH.