Skip to content

Instantly share code, notes, and snippets.

@hplato
Created July 21, 2015 02:11
Show Gist options
  • Save hplato/e1f73f8fe2dbd1565709 to your computer and use it in GitHub Desktop.
Save hplato/e1f73f8fe2dbd1565709 to your computer and use it in GitHub Desktop.
Http_GarageDoor.js
var types = require("HAP-NodeJS/accessories/types.js");
var request = require("request");
function Http_GarageAccessory(log, config) {
this.log = log;
// url info
this.open_url = config["open_url"];
this.close_url = config["close_url"];
this.status_url = config["status_url"];
this.http_method = config["http_method"];
// device info
this.name = config["name"];
}
Http_GarageAccessory.prototype = {
httpRequest: function(url, method, callback) {
request({
url: url,
method: method
},
function (error, response, body) {
callback(error, response, body)
})
},
setDoorState: function(state) {
var url;
if (state) {
url = this.close_url
this.log("Setting "+state+" state on the '"+this.name+"' to close");
}else{
url = this.open_url
this.log("Setting "+state+" state on the '"+this.name+"' to open");
}
this.httpRequest(url, this.http_method, function(error, response, body){
if (error) {
return console.error('http function failed:', error);
}else{
return console.log('http function succeeded!');
}
});
//console.log("url="+url);
},
getServices: function() {
var that = this;
return [{
sType: types.ACCESSORY_INFORMATION_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: this.name,
supportEvents: false,
supportBonjour: false,
manfDescription: "Name of the accessory",
designedMaxLength: 255
},{
cType: types.MANUFACTURER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Http",
supportEvents: false,
supportBonjour: false,
manfDescription: "Manufacturer",
designedMaxLength: 255
},{
cType: types.MODEL_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Rev-1",
supportEvents: false,
supportBonjour: false,
manfDescription: "Model",
designedMaxLength: 255
},{
cType: types.SERIAL_NUMBER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "A1S2NASF88EW",
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.GARAGE_DOOR_OPENER_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: this.name,
supportEvents: false,
supportBonjour: false,
manfDescription: "Name of service",
designedMaxLength: 255
},{
cType: types.CURRENT_DOOR_STATE_CTYPE,
onUpdate: function(value) {
console.log("Garage Door - current door state Change"+value);
},
onRead: function(callback) {
console.log("Garage Door - current door state Read");
callback(undefined); // only testing, we have no physical device to read from
},
perms: ["pr","ev"],
format: "int",
initialValue: 0,
supportEvents: false,
supportBonjour: false,
manfDescription: "BlaBla",
designedMinValue: 0,
designedMaxValue: 4,
designedMinStep: 1,
designedMaxLength: 1
},{
cType: types.TARGET_DOORSTATE_CTYPE,
onUpdate: function(value) { that.setDoorState(value); },
perms: ["pw","pr","ev"],
format: "int",
initialValue: 0,
supportEvents: false,
supportBonjour: false,
manfDescription: "Change the door state",
designedMinValue: 0,
designedMaxValue: 1,
designedMinStep: 1,
designedMaxLength: 1
},{
cType: types.OBSTRUCTION_DETECTED_CTYPE,
onUpdate: function(value) {
console.log("Garage Door Obstruction Change:",value);
},
onRead: function(callback) {
console.log("Garage Door Obstruction Read:");
},
perms: ["pr","ev"],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "BlaBla",
}]
}];
}
};
module.exports.accessory = Http_GarageAccessory;
@TRIROG
Copy link

TRIROG commented Dec 15, 2015

How can this plugin be installed and where for the latest version of homebridge?

@JoshKitson
Copy link

as questioned above, curious if anyone can help getting this working with the latest version of homebridge

@tommyd75
Copy link

Did you guys ever get this working on the latest version of Homebridge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment