-
Notifications
You must be signed in to change notification settings - Fork 12
/
ObyThingMusicManager.groovy
76 lines (64 loc) · 2.7 KB
/
ObyThingMusicManager.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* ObyThing Music Manager
*
* Copyright 2015 obycode
*
* 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: "ObyThing Music Manager",
namespace: "com.obycode",
author: "obycode",
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.",
category: "SmartThings Labs",
iconUrl: "http://obycode.com/obything/ObyThingSTLogo.png",
iconX2Url: "http://obycode.com/obything/[email protected]")
preferences {
section("Get the IP address and port for your Mac computer using the ObyThing Music App (http://obything.obycode.com) and set up the SmartApp below:") {
input "theAddr", "string", title: "IP:port (click icon in status bar)", multiple: false, required: true
}
section("on this hub...") {
input "theHub", "hub", multiple: false, required: true
}
}
def installed() {
log.debug "Installed ${app.label} with address '${settings.theAddr}' on hub '${settings.theHub.name}'"
initialize()
}
def updated() {
/*
log.debug "Updated ${app.label} with address '${settings.theAddr}' on hub '${settings.theHub.name}'"
def current = getChildDevices()
log.debug "children: $current"
if (app.label != current.label) {
log.debug "CHANGING name from ${current.label} to ${app.label}"
log.debug "label props: ${current.label.getProperties()}"
current.label[0] = app.label
}
*/
}
def initialize() {
def parts = theAddr.split(":")
def iphex = convertIPtoHex(parts[0])
def porthex = convertPortToHex(parts[1])
def dni = "$iphex:$porthex"
def hubNames = location.hubs*.name.findAll { it }
def d = addChildDevice("com.obycode", "ObyThing Music", dni, theHub.id, [label:"${app.label}", name:"ObyThing", completedSetup: true])
log.trace "created ObyThing '${d.displayName}' with id $dni"
}
private String convertIPtoHex(ipAddress) {
String hex = ipAddress.tokenize( '.' ).collect { String.format( '%02X', it.toInteger() ) }.join()
return hex
}
private String convertPortToHex(port) {
String hexport = port.toString().format( '%04X', port.toInteger() )
return hexport
}