Created
March 9, 2017 09:24
-
-
Save danielvlopes/868c60a32f49229d6ba4931d09fd6255 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
| 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