Skip to content

Instantly share code, notes, and snippets.

@joshualyon
Created June 26, 2019 19:36
Show Gist options
  • Save joshualyon/272963d21a883525ba5a8e9a093e1b13 to your computer and use it in GitHub Desktop.
Save joshualyon/272963d21a883525ba5a8e9a093e1b13 to your computer and use it in GitHub Desktop.
// 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