-
Notifications
You must be signed in to change notification settings - Fork 1
/
jvm.GenericComponentDimmerwithlevelcontrol.groovy
85 lines (66 loc) · 2.69 KB
/
jvm.GenericComponentDimmerwithlevelcontrol.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
metadata {
definition(name: "Generic Component Dimmer with level control", namespace: "jvm", author: "jvm", component: true) {
capability "Switch"
capability "Refresh"
capability "Actuator"
capability "SwitchLevel"
}
preferences {
input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true
input name: "minDimLevel", type: "number", title: "Minimum Dimmer Level", defaultValue: 1, range:"1..100"
}
}
void updated() {
log.info "Updated..."
log.warn "description logging is: ${txtEnable == true}"
}
void installed() {
log.info "Installed..."
device.updateSetting("txtEnable",[type:"bool",value:true])
refresh()
}
void parse(String description) { log.warn "parse(String description) not implemented" }
void parse(List description) {
description.each {
if (device.hasAttribute (it.name)) {
if (txtEnable) log.info it.descriptionText
if ((it.name == "level") && (it.value < (minDimLevel as Integer)) && (it.value > 0)) {
if (txtEnable) log.info "Device ${device.displayName}: tried to set a level ${it.value} which is below the minimum allowed value for this device of ${minDimLevel}"
parent?.componentSetLevel(this.device, (minDimLevel as Integer))
it.value = minDimLevel
}
sendEvent(it)
}
}
}
void on() {
parent?.componentOn(this.device)
}
void off() {
parent?.componentOff(this.device)
}
void setLevel(level) {
if ((level > 0) && (level < (minDimLevel as Integer))) { // Allow 0 to be sent to turn off device, else level must be at least the minimum.
if (txtEnable) log.info "Device ${device.displayName}: tried to set a level ${level} which is below the minimum allowed value for this device of ${minDimLevel}. Setting to ${minDimLevel} instead."
parent?.componentSetLevel(this.device, (minDimLevel as Integer))
} else {
parent?.componentSetLevel(this.device, level)
}
}
void setLevel(level, ramp) {
if ((level > 0) && (level < (minDimLevel as Integer))) { // Allow 0 to be sent to turn off device, else level must be at least the minimum.
if (txtEnable) log.info "Device ${device.displayName}: tried to set a level ${level} which is below the minimum allowed value for this device of ${minDimLevel}. Setting to ${minDimLevel} instead."
parent?.componentSetLevel(this.device, (minDimLevel as Integer), ramp)
} else {
parent?.componentSetLevel(this.device, level, ramp)
}
}
void startLevelChange(direction) {
parent?.componentStartLevelChange(this.device,direction)
}
void stopLevelChange() {
parent?.componentStopLevelChange(this.device)
}
void refresh() {
parent?.componentRefresh(this.device)
}