forked from ekimmagrann/hubitat-elkm1
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Elk-M1-Driver-Lighting-Switch.groovy
99 lines (86 loc) · 3.07 KB
/
Elk-M1-Driver-Lighting-Switch.groovy
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
/***********************************************************************************************************************
*
* A Hubitat Child Driver supporting Elk M1 Lighting/Appliance Switch
*
* License:
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* Name: Elk M1 Driver Lighting Switch
*
*** See Release Notes at the bottom***
***********************************************************************************************************************/
public static String version() { return "v0.1.1" }
metadata {
definition(name: "Elk M1 Driver Lighting Switch", namespace: "captncode", author: "captncode") {
capability "Actuator"
capability "Switch"
capability "Momentary"
command "refresh"
}
preferences {
input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true
}
}
def updated() {
log.info "Updated..."
log.warn "${device.label} description logging is: ${txtEnable == true}"
}
def installed() {
"Installed..."
device.updateSetting("txtEnable", [type: "bool", value: true])
refresh()
}
def uninstalled() {
}
String getUnitCode() {
String DNID = device.deviceNetworkId
return DNID.substring(DNID.length() - 3).take(3)
}
def parse(String description) {
String switchState = description.toInteger() == 0 ? "off" : "on"
if (device.currentState("switch")?.value == null || device.currentState("switch").value != switchState) {
String descriptionText = "${device.label} is ${switchState}"
if (txtEnable)
log.info descriptionText
sendEvent(name: "switch", value: switchState, descriptionText: descriptionText)
}
}
def parse(List description) {
log.warn "parse(List description) received ${description}"
return
}
def off() {
parent.sendMsg(parent.controlLightingOff(getUnitCode()))
}
def on() {
parent.sendMsg(parent.controlLightingOn(getUnitCode()))
}
def push() {
parent.sendMsg(parent.controlLightingToggle(getUnitCode()))
}
def refresh() {
parent.refreshLightingStatus(getUnitCode())
}
/***********************************************************************************************************************
*
* Release Notes (see Known Issues Below)
*
* 0.1.1
* Added descriptionText to lighting events
*
* 0.1.0
* New child driver to Elk M1 Lighting Switch
*
***********************************************************************************************************************/
/***********************************************************************************************************************
*
* Feature Request & Known Issues
*
*
***********************************************************************************************************************/