@@ -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 */
238238def 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 */
10151037def getDeviceIP () {
10161038 return parent. resolveDNI2Address(device. deviceNetworkId)
1039+ }
1040+
1041+ def TRACE (text ) {
1042+ log. trace " ${ text} "
10171043}
0 commit comments