Skip to content

Commit 8cd824e

Browse files
committed
Update VirtualAutoOffSwitchWithTimerAndConsumable.groovy
1 parent e41355e commit 8cd824e

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Drivers/Virtual/VirtualAutoOffSwitchWithTimerAndConsumable.groovy

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ metadata {
2929
capability 'PushableButton'
3030
capability 'Consumable' //consumableStatus - ENUM ['missing', 'order', 'maintenance_required', 'good', 'replace']
3131

32+
attribute 'assignee', 'STRING' // To be used for auto-off 'chore switches'
33+
command 'setAssignee'
34+
command 'setMaintenanceRequired'
35+
command 'setMaintenanceRequiredIfSwitchOff'
36+
3237
}
3338
preferences() {
3439
section(){
@@ -89,18 +94,42 @@ void on() {
8994
sendEvent(name: 'switch', value: 'on')
9095
push(1)
9196
setConsumableStatus('good')
97+
setAssignee('unassigned')
98+
parent?.update()
9299
}
93100

94101
void off() {
95102
unschedule('autoOff')
96103
sendEvent(name: 'switch', value: 'off')
104+
parent?.update()
97105
}
98106

99107
void setConsumableStatus(String status) {
100108
if(status in ['missing', 'order', 'maintenance_required', 'good', 'replace']) {
101109
sendEvent(name: 'consumableStatus', value: status)
110+
parent?.update()
102111
}
103112
}
104113

114+
void setAssignee(String assigneeName) {
115+
sendEvent(name: 'assignee', value: assigneeName)
116+
parent?.update()
117+
}
118+
105119
void autoOff() { off() }
106-
void push(buttonNumber) { sendEvent(name: 'pushed', value: buttonNumber, isStateChange:true) }
120+
void push(buttonNumber) {
121+
sendEvent(name: 'pushed', value: buttonNumber, isStateChange:true)
122+
parent?.update()
123+
}
124+
125+
void setMaintenanceRequired() {
126+
off()
127+
setConsumableStatus('maintenance_required')
128+
}
129+
130+
void setMaintenanceRequiredIfSwitchOff() {
131+
if(device.currentValue('switch') == 'off') {
132+
setConsumableStatus('maintenance_required')
133+
setAssignee('unassigned')
134+
}
135+
}

0 commit comments

Comments
 (0)