mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
Merge remote-tracking branch 'nfarina/master' into knx-dev
This commit is contained in:
58
accessories/GenericRS232Device.js
Normal file
58
accessories/GenericRS232Device.js
Normal file
@@ -0,0 +1,58 @@
|
||||
var Service = require("HAP-NodeJS").Service;
|
||||
var Characteristic = require("HAP-NodeJS").Characteristic;
|
||||
var SerialPort = require("serialport").SerialPort;
|
||||
|
||||
module.exports = {
|
||||
accessory: GenericRS232DeviceAccessory
|
||||
}
|
||||
|
||||
function GenericRS232DeviceAccessory(log, config) {
|
||||
this.log = log;
|
||||
this.id = config["id"];
|
||||
this.name = config["name"];
|
||||
this.model_name = config["model_name"];
|
||||
this.manufacturer = config["manufacturer"];
|
||||
this.on_command = config["on_command"];
|
||||
this.off_command = config["off_command"];
|
||||
this.device = config["device"];
|
||||
this.baudrate = config["baudrate"];
|
||||
}
|
||||
|
||||
GenericRS232DeviceAccessory.prototype = {
|
||||
setPowerState: function(powerOn, callback) {
|
||||
var that = this;
|
||||
var command = powerOn ? that.on_command : that.off_command;
|
||||
var serialPort = new SerialPort(that.device, { baudrate: that.baudrate }, false);
|
||||
serialPort.open(function (error) {
|
||||
if (error) {
|
||||
callback(new Error('Can not communicate with ' + that.name + " (" + error + ")"))
|
||||
} else {
|
||||
serialPort.write(command, function(err, results) {
|
||||
if (error) {
|
||||
callback(new Error('Can not send power command to ' + that.name + " (" + err + ")"))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getServices: function() {
|
||||
var switchService = new Service.Switch(this.name);
|
||||
var informationService = new Service.AccessoryInformation();
|
||||
|
||||
informationService
|
||||
.setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
|
||||
.setCharacteristic(Characteristic.Model, this.model_name)
|
||||
.setCharacteristic(Characteristic.SerialNumber, this.id);
|
||||
|
||||
switchService
|
||||
.getCharacteristic(Characteristic.On)
|
||||
.on('set', this.setPowerState.bind(this));
|
||||
|
||||
return [informationService, switchService];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.accessory = GenericRS232DeviceAccessory;
|
||||
@@ -140,9 +140,7 @@ WeMoAccessory.prototype.getServices = function() {
|
||||
|
||||
garageDoorService
|
||||
.getCharacteristic(Characteristic.TargetDoorState)
|
||||
.on('set', this.setTargetDoorState.bind(this))
|
||||
.supportsEventNotification = false;
|
||||
|
||||
.on('set', this.setTargetDoorState.bind(this));
|
||||
|
||||
return [garageDoorService];
|
||||
}
|
||||
|
||||
11
app.js
11
app.js
@@ -191,6 +191,16 @@ function createAccessory(accessoryInstance, displayName) {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the setup code in a scannable format.
|
||||
function printPin(pin) {
|
||||
console.log("Scan this code with your HomeKit App on your iOS device:");
|
||||
console.log("\x1b[30;47m%s\x1b[0m", " ");
|
||||
console.log("\x1b[30;47m%s\x1b[0m", " ┌────────────┐ ");
|
||||
console.log("\x1b[30;47m%s\x1b[0m", " │ " + pin + " │ ");
|
||||
console.log("\x1b[30;47m%s\x1b[0m", " └────────────┘ ");
|
||||
console.log("\x1b[30;47m%s\x1b[0m", " ");
|
||||
}
|
||||
|
||||
// Returns a logging function that prepends messages with the given name in [brackets].
|
||||
function createLog(name) {
|
||||
return function(message) {
|
||||
@@ -201,6 +211,7 @@ function createLog(name) {
|
||||
}
|
||||
|
||||
function publish() {
|
||||
printPin(bridgeConfig.pin);
|
||||
bridge.publish({
|
||||
username: bridgeConfig.username || "CC:22:3D:E3:CE:30",
|
||||
port: bridgeConfig.port || 51826,
|
||||
|
||||
@@ -205,7 +205,18 @@
|
||||
"window_seconds": 5,
|
||||
"sensor_type": "m",
|
||||
"inverse": false
|
||||
},
|
||||
{
|
||||
"accessory": "GenericRS232Device",
|
||||
"name": "Projector",
|
||||
"description": "Make sure you set a 'Siri-Name' for your iOS-Device (example: 'Home Cinema') otherwise it might not work.",
|
||||
"id": "TYDYMU044UVNP",
|
||||
"baudrate": 9600,
|
||||
"device": "/dev/tty.usbserial",
|
||||
"manufacturer": "Acer",
|
||||
"model_name": "H6510BD",
|
||||
"on_command": "* 0 IR 001\r",
|
||||
"off_command": "* 0 IR 002\r"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user