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

Master #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
82 changes: 82 additions & 0 deletions accessories/HelloHomeBridge.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* HelloHomeBridge
*
* Copyright 2015 Jesse Newland
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition(
name: "Hello HomeBridge",
namespace: "jnewland",
author: "Jesse Newland",
description: "A SmartThings app designed to work with https://github.com/jnewland/homebridge to provide Siri control for your HelloHome actions.",
category: "SmartThings Labs",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]",
oauth: true)


def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}

def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}

def initialize() {
if (!state.accessToken) {
createAccessToken()
}
}

preferences {
page(name: "copyConfig")
}

def copyConfig() {
dynamicPage(name: "copyConfig", title: "Config", install:true) {
section() {
paragraph "Copy/Paste the below into your homebridge's config.json to create HomeKit accessories for your Hello Home actions"
href url:"https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/config?access_token=${state.accessToken}", style:"embedded", required:false, title:"Config", description:"Tap, select, copy, then click \"Done\""
}
}
}

def renderConfig() {
def configJson = new groovy.json.JsonOutput().toJson(location?.helloHome?.getPhrases().collect({
[
accessory: "SmartThingsHelloHome",
name: it.label,
appId: it.id,
accessToken: state.accessToken
]
}))

def configString = new groovy.json.JsonOutput().prettyPrint(configJson)
render contentType: "text/plain", data: configString
}

mappings {
if (!params.access_token || (params.access_token && params.access_token != state.accessToken)) {
path("/config") { action: [GET: "authError"] }
} else {
path("/config") { action: [GET: "renderConfig"] }
}
}

def authError() {
[error: "Permission denied"]
}
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("../lib/HAP-NodeJS/accessories/types.js")
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