forked from Mark-C-uk/Hubitat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChromCastConnectApp
75 lines (65 loc) · 2.19 KB
/
ChromCastConnectApp
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
/**
* **************** Chromecast connect ****************
*
*/
definition(
name: "Chromecast connect",
namespace: "mark-c-uk",
author: "mark c",
description: "Keep Google/Nest devices connceted.",
category: "Convenience",
iconUrl: "",
iconX2Url: "",
pausable: true
)
preferences {
section("Set you input and output devices for ${app.label}"){
input "speaker", "capability.speechSynthesis", title: "Choose your Google/Nest speaker(s)", required: true, multiple: true
input "InitRepeat", "number", title: "Initialize Google/Nest devices every X minutes? (recommended: 4) max 59", required: true
//input "gInitRepeatH", "number", title: "Initialize Google/Nest devices every X hours? 23", required: false
input "pauseApp", "bool", title: "Pause App", defaultValue:false
input "logEnable", "bool", title: "Enable Debug Logging", description: "Enable logging for debugging.", defaultValue:false
}
}
void installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
void updated() {
log.debug "Updated with settings: ${settings}"
unschedule()
if(logEnable == true) runIn(3600, logsOff)
initialize()
}
void initialize() {
byte randomSixty = Math.abs(new Random().nextInt() % 60)
if(pauseApp == true){
log.info "${app.label} is Paused or Disabled"
} else {
if(logEnable == null){logEnable = false}
runIn(randomSixty ,initializeSpeaker)
log.info "${app.label} is initializeing in $randomSixty seconds"
schedule("$randomSixty 0/$InitRepeat * 1/1 * ? *", initializeSpeaker)
}
}
void initializeSpeaker() {
if(logEnable == true)log.info "${app.label} doing the busness"
if(pauseApp == false) {
for (dev in settings.speaker) {
dev.initialize()
//if(logEnable == true)log.info "${app.label} doing the busness on $dev"
}
/*
settings.speaker.each { it ->
it.initialize()
}
*/
}
else {
log.info "${app.label} is Paused or Disabled"
}
}
void logsOff() {
log.info "${app.label} - Debug logging auto disabled"
app?.updateSetting("logEnable",[value:"false",type:"bool"])
}