Adding event for Power as variation is needed in power values.
[smartthings-infrastructure.git] / SpeechSynthesis / SpeechSynthesises.groovy
1 //Create a class for speech synthesis
2 package SpeechSynthesis
3 import Timer.SimulatedTimer
4
5 public class SpeechSynthesises {
6         private int deviceNumbers
7         private List speechSynthesises
8         def sendEvent
9
10         //For one device(We cannot have obj.id)-> We should have obj[0].id
11         private String id = "speechSynthesisID0"
12         private String label = "speechSynthesis0"
13         private String displayName = "speechSynthesis0"
14         private int level = 50
15         private boolean oneUser = true
16
17                 
18         SpeechSynthesises(Closure sendEvent, int deviceNumbers, boolean init) {
19                 this.sendEvent = sendEvent              
20                 this.deviceNumbers = deviceNumbers
21                 this.speechSynthesises = []
22
23                 if (init) {
24                         this.level = 50
25                         this.oneUser = true
26                 } else {
27                         this.level = 60
28                         this.oneUser = false
29                 }
30                 speechSynthesises.add(new SpeechSynthesis(id, label, displayName, this.level, this.oneUser))
31         }
32
33         //Methods for closures
34         def count(Closure Input) {
35                 speechSynthesises.count(Input)
36         }
37         def size() {
38                 speechSynthesises.size()
39         }
40         def each(Closure Input) {
41                 speechSynthesises.each(Input)
42         }
43         def find(Closure Input) {
44                 speechSynthesises.find(Input)
45         }
46         def sort(Closure Input) {
47                 speechSynthesises.sort(Input)
48         }
49         def collect(Closure Input) {
50                 speechSynthesises.collect(Input)
51         }
52
53         def setLevel(int level) {
54                 if (level != this.level) {
55                         this.level = level
56                         speechSynthesises[0].setLevel(level)
57                 }
58         }
59
60         def speak(String message) {
61                 speechSynthesises[0].speak(message)
62                 // As a conflict variable
63                 if (oneUser) {
64                         this.oneUser = false
65                 } else {
66                         this.oneUser = true
67                 }
68         }
69
70         def getAt(int ix) {
71                 speechSynthesises[ix]
72         }
73 }