1 //Create a class for thermostat device
3 import Timer.SimulatedTimer
5 public class Thermostats{
11 //When we have only one device
13 private String label = "thermostat"
14 private String displayName = "thermostat"
15 private int temperature = 66
16 private int currentCoolingSetpoint = 70
17 private int currentHeatingSetpoint = 50
18 private int coolingSetpoint = 70
19 private int thermostatSetpoint = 60
20 private int heatingSetpoint = 50
21 private coolingSetpointRange = [70, 90]
22 private thermostatSetpointRange = [50, 70]
23 private heatingSetpointRange = [20, 50]
24 private supportedThermostatFanModes = ["auto", "fanCirculate", "circulate", "fanOn", "on"]
25 private supportedThermostatModes = ["auto", "cool", "emergencyHeat", "heat", "off"]
26 private String thermostatOperatingState = "cooling"
27 private String thermostatFanMode = "auto"
28 private String thermostatMode = "auto"
30 Thermostats(Closure sendEvent, int deviceNumbers) {
31 this.sendEvent = sendEvent
32 this.timers = new SimulatedTimer()
33 this.deviceNumbers = deviceNumbers
35 for (int i = 0;i < deviceNumbers;i++) {
36 thermostats.add(new Thermostat(sendEvent, i+50, label+i.toString(), displayName+i.toString(), this.temperature, this.currentCoolingSetpoint,
37 this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
38 this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
39 this.thermostatOperatingState, this.thermostatFanMode, this.thermostatMode))
43 //Methods for closures
44 def count(Closure Input) {
45 thermostats.count(Input)
50 def each(Closure Input) {
51 thermostats.each(Input)
55 def setCoolingSetpoint(int coolingSetpoint) {
56 thermostats*.setCoolingSetpoint(coolingSetpoint)
59 def setHeatingSetpoint(int heatingSetpoint) {
60 thermostats*.setHeatingSetpoint(heatingSetpoint)
67 def setThermostatFanMode(String thermostatFanMode) {
68 thermostats*.setThermostatFanMode(thermostatFanMode)
71 def setThermostatMode(String thermostatMode) {
72 thermostats*.setThermostatMode(thermostatMode)
76 //By Model Checker(There is no event based on thermostat?)
77 /*def setValue(LinkedHashMap eventDataMap) {
78 thermostats[eventDataMap["deviceId"]].setValue(eventDataMap["value"])
79 if (deviceNumbers == 1)
80 this.lockState = locks[eventDataMap["deviceId"]].lockState
81 this.currentLock = locks[eventDataMap["deviceId"]].lockState
82 this.lockLatestValue = locks[eventDataMap["deviceId"]].lockLatestValue
83 sendEvent(eventDataMap)