homebridge-netgear-readynas
Version:
Remote control of ReadyNAS with Homebridge
54 lines (45 loc) • 1.84 kB
JavaScript
const shutdow = require('./commands/shutdown');
const wakeup = require('./commands/wakeup');
const status = require('./commands/status');
function setup(homebridge) {
const Service = homebridge.hap.Service;
const Characteristic = homebridge.hap.Characteristic;
function mySwitch(log, config) {
this.log = log;
this.host = config.host;
this.user = config.user;
this.password = config.password;
this.mac = config.mac;
}
mySwitch.prototype = {
getServices: function () {
let informationService = new Service.AccessoryInformation();
informationService
.setCharacteristic(Characteristic.Manufacturer, "Netgear")
.setCharacteristic(Characteristic.Model, "ReadyNAS")
.setCharacteristic(Characteristic.SerialNumber, "123-456-789");
let switchService = new Service.Switch("ReadyNAS");
switchService
.getCharacteristic(Characteristic.On)
.on('get', this.getSwitchOnCharacteristic.bind(this))
.on('set', this.setSwitchOnCharacteristic.bind(this));
this.informationService = informationService;
this.switchService = switchService;
return [informationService, switchService];
},
getSwitchOnCharacteristic: function (next) {
const nasStatus = status(this.host);
next(null, nasStatus);
},
setSwitchOnCharacteristic: function (on, next) {
if (on) {
wakeup(this.mac);
return next();
}
shutdow(this.user, this.password, this.host);
next();
}
};
homebridge.registerAccessory("switch-plugin", "ReadyNasSwitch", mySwitch);
}
module.exports = setup;