mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
89
accessories/mpdclient.js
Normal file
89
accessories/mpdclient.js
Normal file
@@ -0,0 +1,89 @@
|
||||
var Service = require("HAP-NodeJS").Service;
|
||||
var Characteristic = require("HAP-NodeJS").Characteristic;
|
||||
var request = require("request");
|
||||
var komponist = require('komponist')
|
||||
|
||||
module.exports = {
|
||||
accessory: MpdClient
|
||||
}
|
||||
|
||||
function MpdClient(log, config) {
|
||||
this.log = log;
|
||||
this.host = config["host"] || 'localhost';
|
||||
this.port = config["port"] || 6600;
|
||||
}
|
||||
|
||||
MpdClient.prototype = {
|
||||
|
||||
setPowerState: function(powerOn, callback) {
|
||||
|
||||
var log = this.log;
|
||||
|
||||
komponist.createConnection(this.port, this.host, function(error, client) {
|
||||
|
||||
if (error) {
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
if (powerOn) {
|
||||
client.play(function(error) {
|
||||
log("start playing");
|
||||
client.destroy();
|
||||
callback(error);
|
||||
});
|
||||
} else {
|
||||
client.stop(function(error) {
|
||||
log("stop playing");
|
||||
client.destroy();
|
||||
callback(error);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
getPowerState: function(callback) {
|
||||
|
||||
komponist.createConnection(this.port, this.host, function(error, client) {
|
||||
|
||||
if (error) {
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
client.status(function(error, status) {
|
||||
|
||||
client.destroy();
|
||||
|
||||
if (status['state'] == 'play') {
|
||||
callback(error, 1);
|
||||
} else {
|
||||
callback(error, 0);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
identify: function(callback) {
|
||||
this.log("Identify requested!");
|
||||
callback(); // success
|
||||
},
|
||||
|
||||
getServices: function() {
|
||||
|
||||
var informationService = new Service.AccessoryInformation();
|
||||
|
||||
informationService
|
||||
.setCharacteristic(Characteristic.Manufacturer, "MPD")
|
||||
.setCharacteristic(Characteristic.Model, "MPD Client")
|
||||
.setCharacteristic(Characteristic.SerialNumber, "81536334");
|
||||
|
||||
var switchService = new Service.Switch();
|
||||
|
||||
switchService.getCharacteristic(Characteristic.On)
|
||||
.on('get', this.getPowerState.bind(this))
|
||||
.on('set', this.setPowerState.bind(this));
|
||||
|
||||
return [informationService, switchService];
|
||||
}
|
||||
};
|
||||
@@ -189,6 +189,13 @@
|
||||
"description": "Control the Hyperion TV backlight server. https://github.com/tvdzwan/hyperion",
|
||||
"host": "localhost",
|
||||
"port": "19444"
|
||||
},
|
||||
{
|
||||
"accessory": "mpdclient",
|
||||
"name" : "mpd",
|
||||
"host" : "localhost",
|
||||
"port" : 6600,
|
||||
"description": "Allows some control of an MPD server"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"wink-js": "0.0.5",
|
||||
"xml2js": "0.4.x",
|
||||
"xmldoc": "0.1.x",
|
||||
"komponist" : "0.1.0",
|
||||
"yamaha-nodejs": "0.4.x",
|
||||
"debug": "^2.2.0"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user