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