Skip to content

Commit 4b44460

Browse files
committed
CHF-420 Add device health check to Bose DTH
1 parent 84323af commit 4b44460

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

devicetypes/smartthings/bose-soundtouch.src/bose-soundtouch.groovy

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ metadata {
2727
capability "Switch"
2828
capability "Refresh"
2929
capability "Music Player"
30-
capability "Polling"
30+
capability "Health Check"
3131

3232
/**
3333
* Define all commands, ie, if you have a custom action not
@@ -236,7 +236,33 @@ def parse(String event) {
236236
* @return action(s) to take or null
237237
*/
238238
def installed() {
239-
onAction("refresh")
239+
// Notify health check about this device with timeout interval 12 minutes
240+
sendEvent(name: "checkInterval", value: 12 * 60, data: [protocol: "lan", hubHardwareId: device.hub.hardwareID], displayed: false)
241+
startPoll()
242+
}
243+
244+
/**
245+
* Called by health check if no events been generated in the last 12 minutes
246+
* If device doesn't respond it will be marked offline (not available)
247+
*/
248+
def ping() {
249+
TRACE("ping")
250+
boseSendGetNowPlaying()
251+
}
252+
253+
/**
254+
* Schedule a 2 minute poll of the device to refresh the
255+
* tiles so the user gets the correct information.
256+
*/
257+
def startPoll() {
258+
TRACE("startPoll")
259+
unschedule()
260+
// Schedule 2 minute polling of speaker status (song average length is 3-4 minutes)
261+
def sec = Math.round(Math.floor(Math.random() * 60))
262+
//def cron = "$sec 0/5 * * * ?" // every 5 min
263+
def cron = "$sec 0/2 * * * ?" // every 2 min
264+
log.debug "schedule('$cron', boseSendGetNowPlaying)"
265+
schedule(cron, boseSendGetNowPlaying)
240266
}
241267

242268
/**
@@ -316,14 +342,6 @@ def onAction(String user, data=null) {
316342
return actions
317343
}
318344

319-
/**
320-
* Called every so often (every 5 minutes actually) to refresh the
321-
* tiles so the user gets the correct information.
322-
*/
323-
def poll() {
324-
return boseRefreshNowPlaying()
325-
}
326-
327345
/**
328346
* Joins this speaker into the everywhere zone
329347
*/
@@ -837,6 +855,10 @@ def boseRefreshNowPlaying(delay=0) {
837855
return boseGET("/now_playing")
838856
}
839857

858+
def boseSendGetNowPlaying() {
859+
sendHubCommand(boseGET("/now_playing"))
860+
}
861+
840862
/**
841863
* Requests the list of presets
842864
*
@@ -1014,4 +1036,8 @@ def boseGetDeviceID() {
10141036
*/
10151037
def getDeviceIP() {
10161038
return parent.resolveDNI2Address(device.deviceNetworkId)
1039+
}
1040+
1041+
def TRACE(text) {
1042+
log.trace "${text}"
10171043
}

smartapps/smartthings/bose-soundtouch-connect.src/bose-soundtouch-connect.groovy

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
author: "SmartThings",
2020
description: "Control your Bose SoundTouch speakers",
2121
category: "SmartThings Labs",
22-
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23-
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
24-
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
22+
iconUrl: "https://d3azp77rte0gip.cloudfront.net/smartapps/fcf1d93a-ba0b-4324-b96f-e5b5487dfaf5/images/BoseST_icon.png",
23+
iconX2Url: "https://d3azp77rte0gip.cloudfront.net/smartapps/fcf1d93a-ba0b-4324-b96f-e5b5487dfaf5/images/BoseST_icon@2x.png",
24+
iconX3Url: "https://d3azp77rte0gip.cloudfront.net/smartapps/fcf1d93a-ba0b-4324-b96f-e5b5487dfaf5/images/BoseST_icon@2x-1.png",
2525
singleInstance: true
2626
)
2727

@@ -104,7 +104,7 @@ def deviceDiscovery()
104104

105105
return dynamicPage(name:"deviceDiscovery", title:"Discovery Started!", nextPage:"", refreshInterval:refreshInterval, install:true, uninstall: true) {
106106
section("Please wait while we discover your ${getDeviceName()}. Discovery can take five minutes or more, so sit back and relax! Select your device below once discovered.") {
107-
input "selecteddevice", "enum", required:false, title:"Select ${getDeviceName()} (${numFound} found)", multiple:true, options:devices
107+
input "selecteddevice", "enum", required:false, title:"Select ${getDeviceName()} (${numFound} found)", multiple:true, options:devices, submitOnChange: true
108108
}
109109
}
110110
}
@@ -196,6 +196,8 @@ def addDevice(){
196196
d = addChildDevice(getNameSpace(), getDeviceName(), dni, newDevice?.value.hub, [label:"${deviceName}"])
197197
d.boseSetDeviceID(newDevice.value.deviceID)
198198
log.trace "Created ${d.displayName} with id $dni"
199+
// sync DTH with device, done here as it currently don't work from the DTH's installed() method
200+
d.refresh()
199201
} else {
200202
log.trace "${d.displayName} with id $dni already exists"
201203
}

0 commit comments

Comments
 (0)