da60b36591ad58150ee1b6d3b915838ae2cc2003
[smartthings-infrastructure.git] / SpeechSynthesis / SpeechSynthesis.groovy
1 //Create a class for speech synthesis
2 package SpeechSynthesis
3 import SmartThing.SmartThing
4
5 //Importing mutable integer class
6 import MutableInteger.MutableInteger
7
8 public class SpeechSynthesis extends SmartThing {
9         // id, label, and display name of the device
10         StringBuilder id = new StringBuilder()
11         StringBuilder label = new StringBuilder()
12         StringBuilder displayName = new StringBuilder()
13         // Features with numberical values
14         MutableInteger currentLevel = new MutableInteger()
15         // Maps from features to values
16         HashMap<String, MutableInteger> deviceIntValuesMap = new HashMap<String, MutableInteger>()
17
18         SpeechSynthesis(Closure sendEvent, StringBuilder id, StringBuilder label, StringBuilder displayName, MutableInteger currentLevel) {
19                 deviceIntValuesMap = deviceIntValueSmartThing
20                 idSmartThing = id
21                 labelSmartThing = label
22                 displayNameSmartThing = displayName
23                 sendEventSmartThings = sendEvent
24
25                 // Initialization
26                 this.id = id
27                 this.label = label
28                 this.displayName = displayName
29                 this.currentLevel = currentLevel
30
31                 deviceIntValuesMap.put("level", currentLevel)
32         }
33
34         // Methods to set values
35         def setLevel(int newValue) {
36                 if (!currentLevel.getValue().equals(newValue)) {
37                         String tmpID = id.toString()
38                         currentLevel.setValue(newValue)
39                         println("The level of speech synthesis with id:$tmpID is changed to $currentLevel")
40                 }
41         }
42
43         def speak(String message) {
44                 String tmpID = id.toString()
45                 println("Speech synthesis with id:$tmpID, SPEAKING:\"$message\"!")
46         }
47
48         // Methods to return values
49         def getCurrentLevel() {
50                 return currentLevel.getValue()
51         }
52 }