Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create SmartThingsHelloHome.js #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions accessories/SmartThingsHelloHome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
var types = require("../api").homebridge.hapLegacyTypes;
var request = require("request")

function SmartThingsHelloHomeAccessory(log, config) {
this.log = log
this.appId = config["appId"]
this.accessToken = config["accessToken"]
this.name = config["name"]
}

SmartThingsHelloHomeAccessory.prototype = {
execute: function() {
var that = this
url = "https://graph.api.smartthings.com/api/smartapps/installations/"+this.appId+"/action/execute?access_token="+this.accessToken
console.log(url)
request.get({
url: url,
}, function(err, response) {
if (!err && response.statusCode == 200) {
that.log("Triggered successfully")
} else {
that.log("Error '"+err+"': " + body)
}
})
},
getServices: function() {
if (this.name == undefined) {
return []
} else {
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: "SmartThings",
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: this.appId+"-"+this.name,
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.LIGHTBULB_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: this.name,
supportEvents: true,
supportBonjour: false,
manfDescription: "Name of service",
designedMaxLength: 255
},{
cType: types.POWER_STATE_CTYPE,
onUpdate: function(value) { that.execute() },
perms: ["pw","pr","ev"],
format: "bool",
initialValue: 0,
supportEvents: true,
supportBonjour: false,
manfDescription: "Change the power state of the Bulb",
designedMaxLength: 1
}]
}]
}
}
}

module.exports.accessory = SmartThingsHelloHomeAccessory