mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
Add shim for devices with serial connection (video projectors, screens, receivers, ..)
This commit is contained in:
126
accessories/GenericRS232Device.js
Normal file
126
accessories/GenericRS232Device.js
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
var types = require("HAP-NodeJS/accessories/types.js");
|
||||||
|
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 = {
|
||||||
|
getServices: function() {
|
||||||
|
var that = this;
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
sType: types.ACCESSORY_INFORMATION_STYPE,
|
||||||
|
characteristics: [
|
||||||
|
{
|
||||||
|
cType: types.NAME_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: that.name,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Name of the accessory",
|
||||||
|
designedMaxLength: 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cType: types.MANUFACTURER_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: that.manufacturer,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Manufacturer",
|
||||||
|
designedMaxLength: 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cType: types.MODEL_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: that.model_name,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Model",
|
||||||
|
designedMaxLength: 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cType: types.SERIAL_NUMBER_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: that.id,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "SN",
|
||||||
|
designedMaxLength: 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cType: types.IDENTIFY_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pw"],
|
||||||
|
format: "bool",
|
||||||
|
initialValue: false,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Identify Accessory",
|
||||||
|
designedMaxLength: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sType: types.SWITCH_STYPE,
|
||||||
|
characteristics: [
|
||||||
|
{
|
||||||
|
cType: types.NAME_CTYPE,
|
||||||
|
onUpdate: null,
|
||||||
|
perms: ["pr"],
|
||||||
|
format: "string",
|
||||||
|
initialValue: this.serviceName,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Name of service",
|
||||||
|
designedMaxLength: 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cType: types.POWER_STATE_CTYPE,
|
||||||
|
onUpdate: function(value) {
|
||||||
|
var command = (value == 1 ? that.on_command : that.off_command);
|
||||||
|
var serialPort = new SerialPort(that.device, { baudrate: that.baudrate });
|
||||||
|
serialPort.on("open", function () {
|
||||||
|
serialPort.write(command, function(error, results) {
|
||||||
|
if(error) {
|
||||||
|
console.log('Errors ' + err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
perms: ["pw","pr","ev"],
|
||||||
|
format: "bool",
|
||||||
|
initialValue: false,
|
||||||
|
supportEvents: false,
|
||||||
|
supportBonjour: false,
|
||||||
|
manfDescription: "Set the Power state",
|
||||||
|
designedMaxLength: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.accessory = GenericRS232DeviceAccessory;
|
||||||
@@ -205,7 +205,18 @@
|
|||||||
"window_seconds": 5,
|
"window_seconds": 5,
|
||||||
"sensor_type": "m",
|
"sensor_type": "m",
|
||||||
"inverse": false
|
"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"
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
"q": "1.4.x",
|
"q": "1.4.x",
|
||||||
"tough-cookie": "^2.0.0",
|
"tough-cookie": "^2.0.0",
|
||||||
"request": "2.49.x",
|
"request": "2.49.x",
|
||||||
|
"serialport": "^1.7.4",
|
||||||
"sonos": "0.8.x",
|
"sonos": "0.8.x",
|
||||||
"telldus-live": "0.2.x",
|
"telldus-live": "0.2.x",
|
||||||
"teslams": "1.0.1",
|
"teslams": "1.0.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user