-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgcalDriver
123 lines (114 loc) · 5.62 KB
/
gcalDriver
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* **************** gCalendar Driver ****************
*
* Design Usage:
* Retrieves a Google Calendar to be used with HE Dashboards.
*
* Copyright 2021 Bryan Turcotte (@bptworld)
*
* This App is free. If you like and use this app, please be sure to mention it on the Hubitat forums! Thanks.
*
* Remember...I am not a professional programmer, everything I do takes a lot of time and research (then MORE research)!
* Donations are never necessary but always appreciated. Donations to support development efforts are accepted via:
*
* Paypal at: https://paypal.me/bptworld
*
* Unless noted in the code, ALL code contained within this app is mine. You are free to change, ripout, copy, modify or
* otherwise use the code in anyway you want. This is a hobby, I'm more than happy to share what I have learned and help
* the community grow. Have FUN with it!
*
* ------------------------------------------------------------------------------------------------------------------------------
* 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.
*
* ------------------------------------------------------------------------------------------------------------------------------
*
* If modifying this project, please keep the above header intact and add your comments/credits below - Thank you! - @BPTWorld
*
* App and Driver updates can be found at https://github.com/bptworld/Hubitat
*
* ------------------------------------------------------------------------------------------------------------------------------
*
* Original concept by @TechMedX
*
* Changes:
* MC version 20/05/22
* 1.0.2 - 09/05/21 - Added urlSize Attribute, added additional language for 255 character limit.
* 1.0.1 - 03/01/21 - Fixed a typo
* 1.0.0 - 02/28/21 - Initial release
*/
metadata {
definition (name: "gCalendar Driver", namespace: "BPTWorld", author: "Bryan Turcotte", importUrl: "") {
capability "Actuator"
attribute "bpt-gCal", "text"
attribute "lastUpdated", "text"
attribute "urlSize", "text"
command "refresh"
}
}
preferences {
input title:"<b>Google Calendar Tile</b>", description:"Note: Calendar will be updated once every hour or when 'Refresh' button is pushed.<br><br><b>Setup:</b><br>1) Go to your Google Calendar<br>2) For the calendar you want to display, click Settings<br>3) Scroll down until you see the Embed Code<br>4) Copy that code and paste it into URL field here<br>5) Press 'Save Preferences'", type:"paragraph", element:"paragraph"
input "gCal", "begining", title: "Google Calendar URL begining (URL must be less than 256 characters or it won't work. See urlSize in Attributes.)", required:true, submitOnChange:true
input "gCal1", "src 1"
input "gCal2", "src 2"
input "gCal3", "src 3"
input "gCal4", "src 4"
input "gCal5", "src 5"
input "gCal6", "src 6"
input "gCal7", "src 7"
input "gCal8", "src 8"
input "gCalend", "end"
if(gCal) {
theCount = gCal.size()
sendEvent(name: "urlSize", value: theCount)
}
input "logEnable", "bool", title: "Enable logging", required: true, defaultValue: false, submitOnChange: true
input "logOffTime", "enum", title: "Logs Off Time", required:false, multiple:false, options: ["1 Hour", "2 Hours", "3 Hours", "4 Hours", "5 Hours", "Keep On"], defaultValue: "1 Hour"
}
def refresh() {
if(logEnable) log.debug "In refresh"
if(gCal) {
if(gCal.contains("<iframe src=\"")) gCal = gCal.replace("<iframe src=\"", "").replace(">", "").replace("</iframe>", "")
if(logEnable) log.debug "In refresh - gCal URl: ${gCal}"
lu = new Date()
String NewgCal = gCal
if (gCal1 !=null) NewgCal += gCal1
if (gCal2 !=null) NewgCal += gCal2
if (gCal3 !=null) NewgCal += gCal3
if (gCal4 !=null) NewgCal += gCal4
if (gCal5 !=null) NewgCal += gCal5
if (gCal6 !=null) NewgCal += gCal6
if (gCal7 !=null) NewgCal += gCal7
if (gCal8 !=null) NewgCal += gCal8
if (gCalend !=null) NewgCal += gCalend
theCal = "<div style='height:100%;width:100%'><iframe src='${NewgCal}' ></iframe></div>" //style='height:100%;width:100%;border:none'
sendEvent(name: "bpt-gCal", value: theCal)
sendEvent(name: "lastUpdated", value: lu)
} else {
log.info "gCalendar Driver - Be sure to fill in the Google Calendar URL and click Save Preferences"
}
}
def updated() {
installed()
}
def installed() {
unschedule()
if(logEnable && logOffTime == "1 Hour") runIn(3600, logsOff, [overwrite:false])
if(logEnable && logOffTime == "2 Hours") runIn(7200, logsOff, [overwrite:false])
if(logEnable && logOffTime == "3 Hours") runIn(10800, logsOff, [overwrite:false])
if(logEnable && logOffTime == "4 Hours") runIn(14400, logsOff, [overwrite:false])
if(logEnable && logOffTime == "5 Hours") runIn(18000, logsOff, [overwrite:false])
if(logEnagle && logOffTime == "Keep On") unschedule(logsOff)
refresh()
schedule("0 0 * ? * * *", refresh)
}
def logsOff() {
log.info "${app.label} - Debug logging auto disabled"
app.updateSetting("logEnable",[value:"false",type:"bool"])
}