Created
June 26, 2019 19:36
-
-
Save joshualyon/272963d21a883525ba5a8e9a093e1b13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Developer: [email protected] | |
metadata { | |
definition (name: "Simulated Fan + Switch", namespace: "sharptools/testing", author: "josh") { | |
capability "Sensor" | |
capability "Switch" | |
capability "Fan Control" | |
capability "Health Check" | |
command "active" | |
command "inactive" | |
} | |
} | |
def installed() { | |
log.trace "Executing 'installed'" | |
initialize() | |
off() | |
setSpeed('off') | |
} | |
def updated() { | |
log.trace "Executing 'updated'" | |
initialize() | |
} | |
private initialize() { | |
log.trace "Executing 'initialize'" | |
sendEvent(name: "DeviceWatch-DeviceStatus", value: "online") | |
sendEvent(name: "healthStatus", value: "online") | |
sendEvent(name: "DeviceWatch-Enroll", value: [protocol: "cloud", scheme:"untracked"].encodeAsJson(), displayed: false) | |
} | |
def on() { | |
log.trace "Executing 'on'" | |
sendEvent(name: "switch", value: "on", isStateChange: true) | |
} | |
def off() { | |
log.trace "Executing 'off'" | |
sendEvent(name: "switch", value: "off", isStateChange: true) | |
} | |
def setSpeed(speed){ | |
log.trace "Executing 'setSpeed' to ${speed}" | |
if(isValidSpeed(speed)) | |
sendEvent(name: "speed", value: speed, isStateChange: true) | |
else | |
log.warn "Invalid speed: ${speed}" | |
} | |
def isValidSpeed(speed){ | |
def speeds = ["low","medium-low","medium","medium-high","high","on","off","auto"] | |
return speeds.contains(speed) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment