2 * ObyThing Music SmartApp
4 * Copyright 2014 obycode
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13 * for the specific language governing permissions and limitations under the License.
17 name: "ObyThing Music (Connect)",
18 namespace: "com.obycode",
20 description: "Use this free SmartApp in conjunction with the ObyThing Music app for your Mac to control and automate music and more with iTunes and SmartThings.",
21 category: "SmartThings Labs",
22 iconUrl: "http://obycode.com/obything/ObyThingSTLogo.png",
23 iconX2Url: "http://obycode.com/obything/ObyThingSTLogo@2x.png",
28 section("Get the IP address and port for your Mac computer using the ObyThing App (http://obything.obycode.com) and set up the SmartApp below:") {
29 input "theAddr", "string", title: "IP:port (click icon in status bar)", multiple: false, required: true
31 section("on this hub...") {
32 input "theHub", "hub", multiple: false, required: true
38 log.debug "Installed ${app.label} with address '${settings.theAddr}' on hub '${settings.theHub.name}'"
45 log.debug "Updated ${app.label} with address '${settings.theAddr}' on hub '${settings.theHub.name}'"
47 def current = getChildDevices()
48 log.debug "children: $current"
50 if (app.label != current.label) {
51 log.debug "CHANGING name from ${current.label} to ${app.label}"
52 log.debug "label props: ${current.label.getProperties()}"
53 current.label[0] = app.label
59 def parts = theAddr.split(":")
60 def iphex = convertIPtoHex(parts[0])
61 def porthex = convertPortToHex(parts[1])
62 def dni = "$iphex:$porthex"
63 def hubNames = location.hubs*.name.findAll { it }
64 def d = addChildDevice("com.obycode", "ObyThing Music", dni, theHub.id, [label:"${app.label}", name:"ObyThing"])
65 log.trace "created ObyThing '${d.displayName}' with id $dni"
68 private String convertIPtoHex(ipAddress) {
69 String hex = ipAddress.tokenize( '.' ).collect { String.format( '%02X', it.toInteger() ) }.join()
74 private String convertPortToHex(port) {
75 String hexport = port.toString().format( '%04X', port.toInteger() )