mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-04-03 22:04:41 +01:00
Merge pull request #660 from juano2310/hue_discover
Added hubVerification()
This commit is contained in:
@@ -17,16 +17,13 @@ metadata {
|
|||||||
|
|
||||||
tiles(scale: 2) {
|
tiles(scale: 2) {
|
||||||
multiAttributeTile(name:"rich-control"){
|
multiAttributeTile(name:"rich-control"){
|
||||||
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
|
tileAttribute ("", key: "PRIMARY_CONTROL") {
|
||||||
attributeState "default", label: "Hue Bridge", action: "", icon: "st.Lighting.light99-hue", backgroundColor: "#F3C200"
|
attributeState "default", label: "Hue Bridge", action: "", icon: "st.Lighting.light99-hue", backgroundColor: "#F3C200"
|
||||||
}
|
}
|
||||||
tileAttribute ("serialNumber", key: "SECONDARY_CONTROL") {
|
tileAttribute ("serialNumber", key: "SECONDARY_CONTROL") {
|
||||||
attributeState "default", label:'SN: ${currentValue}'
|
attributeState "default", label:'SN: ${currentValue}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
standardTile("icon", "icon", width: 1, height: 1, canChangeIcon: false, inactiveLabel: true, canChangeBackground: false) {
|
|
||||||
state "default", label: "Hue Bridge", action: "", icon: "st.Lighting.light99-hue", backgroundColor: "#FFFFFF"
|
|
||||||
}
|
|
||||||
valueTile("serialNumber", "device.serialNumber", decoration: "flat", height: 1, width: 2, inactiveLabel: false) {
|
valueTile("serialNumber", "device.serialNumber", decoration: "flat", height: 1, width: 2, inactiveLabel: false) {
|
||||||
state "default", label:'SN: ${currentValue}'
|
state "default", label:'SN: ${currentValue}'
|
||||||
}
|
}
|
||||||
@@ -34,7 +31,7 @@ metadata {
|
|||||||
state "default", label:'${currentValue}', height: 1, width: 2, inactiveLabel: false
|
state "default", label:'${currentValue}', height: 1, width: 2, inactiveLabel: false
|
||||||
}
|
}
|
||||||
|
|
||||||
main (["icon"])
|
main (["rich-control"])
|
||||||
details(["rich-control", "networkAddress"])
|
details(["rich-control", "networkAddress"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +72,7 @@ def parse(description) {
|
|||||||
}
|
}
|
||||||
else if (contentType?.contains("xml")) {
|
else if (contentType?.contains("xml")) {
|
||||||
log.debug "HUE BRIDGE ALREADY PRESENT"
|
log.debug "HUE BRIDGE ALREADY PRESENT"
|
||||||
|
parent.hubVerification(device.hub.id, msg.body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ def bridgeDiscovery(params=[:])
|
|||||||
}
|
}
|
||||||
|
|
||||||
//setup.xml request every 3 seconds except on discoveries
|
//setup.xml request every 3 seconds except on discoveries
|
||||||
if(((bridgeRefreshCount % 1) == 0) && ((bridgeRefreshCount % 5) != 0)) {
|
if(((bridgeRefreshCount % 3) == 0) && ((bridgeRefreshCount % 5) != 0)) {
|
||||||
verifyHueBridges()
|
verifyHueBridges()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +175,7 @@ private discoverHueBulbs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private verifyHueBridge(String deviceNetworkId, String host) {
|
private verifyHueBridge(String deviceNetworkId, String host) {
|
||||||
|
log.trace "Verify Hue Bridge $deviceNetworkId"
|
||||||
sendHubCommand(new physicalgraph.device.HubAction([
|
sendHubCommand(new physicalgraph.device.HubAction([
|
||||||
method: "GET",
|
method: "GET",
|
||||||
path: "/description.xml",
|
path: "/description.xml",
|
||||||
@@ -602,6 +603,20 @@ def parse(childDevice, description) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def hubVerification(bodytext) {
|
||||||
|
log.trace "Bridge sent back description.xml for verification"
|
||||||
|
def body = new XmlSlurper().parseText(bodytext)
|
||||||
|
if (body?.device?.modelName?.text().startsWith("Philips hue bridge")) {
|
||||||
|
def bridges = getHueBridges()
|
||||||
|
def bridge = bridges.find {it?.key?.contains(body?.device?.UDN?.text())}
|
||||||
|
if (bridge) {
|
||||||
|
bridge.value << [name:body?.device?.friendlyName?.text(), serialNumber:body?.device?.serialNumber?.text(), verified: true]
|
||||||
|
} else {
|
||||||
|
log.error "/description.xml returned a bridge that didn't exist"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def on(childDevice) {
|
def on(childDevice) {
|
||||||
log.debug "Executing 'on'"
|
log.debug "Executing 'on'"
|
||||||
put("lights/${getId(childDevice)}/state", [on: true])
|
put("lights/${getId(childDevice)}/state", [on: true])
|
||||||
|
|||||||
Reference in New Issue
Block a user