Skip to content

Instantly share code, notes, and snippets.

@danielvlopes
Created March 9, 2017 09:24
Show Gist options
  • Select an option

  • Save danielvlopes/868c60a32f49229d6ba4931d09fd6255 to your computer and use it in GitHub Desktop.

Select an option

Save danielvlopes/868c60a32f49229d6ba4931d09fd6255 to your computer and use it in GitHub Desktop.
const cmd = Ingredients.TextField.toLowerCase()
const supportedColors = [
'white', 'red', 'orange', 'yellow',
'cyan', 'green', 'blue', 'purple', 'pink'
]
const skipAllBut = (exception:string)=> {
const msg = "Unknown command"
if (exception != 'color') Lifx.color.skip(msg)
if (exception != 'toggle') Lifx.toggle.skip(msg)
if (exception != 'turnOff') Lifx.turnOff.skip(msg)
if (exception != 'turnOn') Lifx.turnOn.skip(msg)
}
// alias
const skipAll = skipAllBut
if (cmd.indexOf("dim") != -1) {
skipAllBut('color')
index = cmd.indexOf("more") != -1 ? 0.3 : 0.5
Lifx.color.setAdvancedOptions(
`brightness: ${index}; fade_in_duration: 1`
)
} else if (cmd.indexOf("on") != -1) {
skipAllBut('turnOn')
} else if (cmd.indexOf("off") != -1) {
skipAllBut('turnOff')
} else if (supportedColors.indexOf(cmd) != -1)
skipAllBut('color')
Lifx.color.setAdvancedOptions(`color: ${cmd}; fade_in_duration: 1`)
} else {
skipAll()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment