3 #Create directory for files to append in the main file
5 #Extract information from preferences and subscribe method to create required objects
6 os.system("python Extractor/ExtractorScript.py")
9 Out = open("main.groovy", "w+")
10 GlobalVariablesBothApps = open("GlobalVariables/"+"GlobalVariablesBothApps.groovy", "r")
11 eventSimulator = open("eventSimulator/"+"eventSimulator.groovy", "r")
14 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
15 setLocationMode = open("Methods/"+"setLocationMode.groovy", "r")
16 subscribe = open("Methods/"+"subscribe.groovy", "r")
17 runIn = open("Methods/"+"runIn.groovy", "r")
18 runDaily = open("Methods/"+"runDaily.groovy", "r")
19 unschedule = open("Methods/"+"unschedule.groovy", "r")
20 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
21 sendSms = open("Methods/"+"sendSms.groovy", "r")
22 sendPush = open("Methods/"+"sendPush.groovy", "r")
23 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
24 schedule = open("Methods/"+"schedule.groovy", "r")
25 httpPostJson = open("Methods/"+"httpPostJson.groovy", "r")
26 now = open("Methods/"+"now.groovy", "r")
27 getTemperatureScale = open("Methods/"+"getTemperatureScale.groovy", "r")
28 getSunriseAndSunset = open("Methods/"+"getSunriseAndSunset.groovy", "r")
29 runEvery15Minutes = open("Methods/"+"runEvery15Minutes.groovy", "r")
30 timeToday = open("Methods/"+"timeToday.groovy", "r")
31 sendNotification = open("Methods/"+"sendNotification.groovy", "r")
32 canSchedule = open("Methods/"+"canSchedule.groovy", "r")
33 createAccessToken = open("Methods/"+"createAccessToken.groovy", "r")
34 runOnce = open("Methods/"+"runOnce.groovy", "r")
35 parseJson = open("Methods/"+"parseJson.groovy", "r")
36 unsubscribe = open("Methods/"+"unsubscribe.groovy", "r")
37 App1 = open("Extractor/"+"App1/App1.groovy", "r")
38 extractedObjectsApp1 = open("Extractor/"+"App1/extractedObjectsApp1.groovy", "r")
39 extractedObjectsConstructorApp1 = open("Extractor/"+"App1/extractedObjectsConstructorApp1.groovy", "r")
40 extractedFunctionsApp1 = open("Extractor/"+"App1/extractedFunctionsApp1.groovy", "r")
45 Out.write("//Infrastructure for SmartThings Application\n")
46 Out.write("//Importing Libraries\n")
47 Out.write("import groovy.transform.Field\n")
48 Out.write("import groovy.json.JsonSlurper\n")
50 Out.write("//Importing Classes\n")
51 Out.write("import ContactSensor.ContactSensor\n")
52 Out.write("import ContactSensor.ContactSensors\n")
53 Out.write("import DoorControl.DoorControl\n")
54 Out.write("import DoorControl.DoorControls\n")
55 Out.write("import Lock.Lock\n")
56 Out.write("import Lock.Locks\n")
57 Out.write("import Thermostat.Thermostat\n")
58 Out.write("import Thermostat.Thermostats\n")
59 Out.write("import Switch.Switch\n")
60 Out.write("import Switch.Switches\n")
61 Out.write("import PresenceSensor.PresenceSensor\n")
62 Out.write("import PresenceSensor.PresenceSensors\n")
63 Out.write("import Logger.Logger\n")
64 Out.write("import Location.LocationVar\n")
65 Out.write("import Location.Phrase\n")
66 Out.write("import appTouch.Touched\n")
67 Out.write("import NfcTouch.NfcTouch\n")
68 Out.write("import AeonKeyFob.AeonKeyFob\n")
69 Out.write("import AeonKeyFob.AeonKeyFobs\n")
70 Out.write("import MusicPlayer.MusicPlayer\n")
71 Out.write("import MusicPlayer.MusicPlayers\n")
72 Out.write("import MotionSensor.MotionSensor\n")
73 Out.write("import MotionSensor.MotionSensors\n")
74 Out.write("import ImageCapture.ImageCapture\n")
75 Out.write("import ImageCapture.ImageCaptures\n")
76 Out.write("import SmokeDetector.SmokeDetector\n")
77 Out.write("import SmokeDetector.SmokeDetectors\n")
78 Out.write("import Alarm.Alarm\n")
79 Out.write("import Alarm.Alarms\n")
80 Out.write("import SpeechSynthesis.SpeechSynthesis\n")
81 Out.write("import SpeechSynthesis.SpeechSynthesises\n")
82 Out.write("import AccelerationSensor.AccelerationSensor\n")
83 Out.write("import AccelerationSensor.AccelerationSensors\n")
84 Out.write("import Battery.Battery\n")
85 Out.write("import Battery.Batteries\n")
86 Out.write("import BeaconSensor.BeaconSensor\n")
87 Out.write("import BeaconSensor.BeaconSensors\n")
88 Out.write("import CarbonMonoxideDetector.CarbonMonoxideDetector\n")
89 Out.write("import CarbonMonoxideDetector.CarbonMonoxideDetectors\n")
90 Out.write("import ColorControl.ColorControl\n")
91 Out.write("import ColorControl.ColorControls\n")
92 Out.write("import EnergyMeter.EnergyMeter\n")
93 Out.write("import EnergyMeter.EnergyMeters\n")
94 Out.write("import IlluminanceMeasurement.IlluminanceMeasurement\n")
95 Out.write("import IlluminanceMeasurement.IlluminanceMeasurements\n")
96 Out.write("import PowerMeter.PowerMeter\n")
97 Out.write("import PowerMeter.PowerMeters\n")
98 Out.write("import RelativeHumidityMeasurement.RelativeHumidityMeasurement\n")
99 Out.write("import RelativeHumidityMeasurement.RelativeHumidityMeasurements\n")
100 Out.write("import RelaySwitch.RelaySwitch\n")
101 Out.write("import RelaySwitch.RelaySwitches\n")
102 Out.write("import SleepSensor.SleepSensor\n")
103 Out.write("import SleepSensor.SleepSensors\n")
104 Out.write("import StepSensor.StepSensor\n")
105 Out.write("import StepSensor.StepSensors\n")
106 Out.write("import SwitchLevel.SwitchLevel\n")
107 Out.write("import SwitchLevel.SwitchLevels\n")
108 Out.write("import TemperatureMeasurement.TemperatureMeasurement\n")
109 Out.write("import TemperatureMeasurement.TemperatureMeasurements\n")
110 Out.write("import WaterSensor.WaterSensor\n")
111 Out.write("import WaterSensor.WaterSensors\n")
112 Out.write("import Valve.Valve\n")
113 Out.write("import Valve.Valves\n")
114 Out.write("import MobilePresence.MobilePresence\n")
115 Out.write("import MobilePresence.MobilePresences\n")
116 Out.write("import ColorTemperature.ColorTemperature\n")
117 Out.write("import ColorTemperature.ColorTemperatures\n")
118 Out.write("import Button.Button\n")
119 Out.write("import Button.Buttons\n")
120 Out.write("import ThreeAxis.ThreeAxis\n")
121 Out.write("import ThreeAxis.ThreeAxises\n")
122 Out.write("import Momentary.Momentary\n")
123 Out.write("import Momentary.Momentaries\n")
124 Out.write("import Event.Event\n")
125 Out.write("import Timer.SimulatedTimer\n")
127 Out.write("//JPF's Verify API\n")
128 Out.write("import gov.nasa.jpf.vm.Verify\n")
130 Out.write("//Global eventHandler\n")
131 for line in eventHandler:
134 Out.write("//GlobalVariables for both Apps\n")
135 Out.write("@Field def init = Verify.getBoolean()\n\n")
136 for line in GlobalVariablesBothApps:
139 Out.write("//clear init flag now we are done with it\n")
140 Out.write("init = false\n")
141 Out.write("//Application #1\n")
142 Out.write("class App1 {\n")
143 Out.write("\tdef reference\n")
144 Out.write("\tdef location\n")
145 Out.write("\tdef app\n")
147 Out.write("\t//Extracted objects for App1\n")
148 for line in extractedObjectsApp1:
151 Out.write("\t//Extracted objects for functions for App1\n")
152 for line in extractedFunctionsApp1:
155 Out.write("\tApp1(Object obj) {\n")
156 Out.write("\t\treference = obj\n")
157 Out.write("\t\tlocation = obj.locationObject\n")
158 Out.write("\t\tapp = obj.appObject\n")
159 for line in extractedObjectsConstructorApp1:
160 Out.write("\t\t"+line)
162 Out.write("\t//Global variables for each app\n")
163 for line in GlobalVariablesEachApp:
166 Out.write("\t//Methods\n")
167 for line in setLocationMode:
169 for line in subscribe:
173 for line in runDaily:
175 for line in unschedule:
177 for line in sendNotificationToContacts:
181 for line in sendPush:
183 for line in schedule:
187 for line in getTemperatureScale:
189 for line in getSunriseAndSunset:
191 for line in httpPostJson:
193 for line in runEvery15Minutes:
195 for line in timeToday:
197 for line in sendNotification:
199 for line in canSchedule:
201 for line in createAccessToken:
205 for line in parseJson:
207 for line in unsubscribe:
219 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
222 GlobalVariablesEachApp = open("GlobalVariables/"+"GlobalVariablesEachApp.groovy", "r")
223 setLocationMode = open("Methods/"+"setLocationMode.groovy", "r")
224 subscribe = open("Methods/"+"subscribe.groovy", "r")
225 runIn = open("Methods/"+"runIn.groovy", "r")
226 runDaily = open("Methods/"+"runDaily.groovy", "r")
227 unschedule = open("Methods/"+"unschedule.groovy", "r")
228 sendNotificationToContacts = open("Methods/"+"sendNotificationToContacts.groovy", "r")
229 sendSms = open("Methods/"+"sendSms.groovy", "r")
230 sendPush = open("Methods/"+"sendPush.groovy", "r")
231 eventHandler = open("Methods/"+"eventHandler.groovy", "r")
232 schedule = open("Methods/"+"schedule.groovy", "r")
233 now = open("Methods/"+"now.groovy", "r")
234 getTemperatureScale = open("Methods/"+"getTemperatureScale.groovy", "r")
235 getSunriseAndSunset = open("Methods/"+"getSunriseAndSunset.groovy", "r")
236 httpPostJson = open("Methods/"+"httpPostJson.groovy", "r")
237 runEvery15Minutes = open("Methods/"+"runEvery15Minutes.groovy", "r")
238 timeToday = open("Methods/"+"timeToday.groovy", "r")
239 sendNotification = open("Methods/"+"sendNotification.groovy", "r")
240 canSchedule = open("Methods/"+"canSchedule.groovy", "r")
241 createAccessToken = open("Methods/"+"createAccessToken.groovy", "r")
242 runOnce = open("Methods/"+"runOnce.groovy", "r")
243 parseJson = open("Methods/"+"parseJson.groovy", "r")
244 unsubscribe = open("Methods/"+"unsubscribe.groovy", "r")
245 App2 = open("Extractor/"+"App2/App2.groovy", "r")
246 extractedObjectsApp2 = open("Extractor/"+"App2/extractedObjectsApp2.groovy", "r")
247 extractedObjectsConstructorApp2 = open("Extractor/"+"App2/extractedObjectsConstructorApp2.groovy", "r")
248 extractedFunctionsApp2 = open("Extractor/"+"App2/extractedFunctionsApp2.groovy", "r")
250 Out.write("//Application #2\n")
251 Out.write("class App2 {\n")
252 Out.write("\tdef reference\n")
253 Out.write("\tdef location\n")
254 Out.write("\tdef app\n")
256 Out.write("\t//Extracted objects for App2\n")
257 for line in extractedObjectsApp2:
260 Out.write("\t//Extracted objects for functions for App2\n")
261 for line in extractedFunctionsApp2:
264 Out.write("\tApp2(Object obj) {\n")
265 Out.write("\t\treference = obj\n")
266 Out.write("\t\tlocation = obj.locationObject\n")
267 Out.write("\t\tapp = obj.appObject\n")
268 for line in extractedObjectsConstructorApp2:
269 Out.write("\t\t"+line)
271 Out.write("\t//Global variables for each app\n")
272 for line in GlobalVariablesEachApp:
275 Out.write("\t//Methods\n")
276 for line in setLocationMode:
278 for line in subscribe:
282 for line in runDaily:
284 for line in unschedule:
286 for line in sendNotificationToContacts:
290 for line in sendPush:
292 for line in schedule:
296 for line in getTemperatureScale:
298 for line in getSunriseAndSunset:
300 for line in httpPostJson:
302 for line in runEvery15Minutes:
304 for line in timeToday:
306 for line in sendNotification:
308 for line in canSchedule:
310 for line in createAccessToken:
314 for line in parseJson:
316 for line in unsubscribe:
327 Out.write("@Field def app1\n")
328 Out.write("@Field def app2\n")
329 Out.write("//def initOrder = Verify.getBoolean()\n")
330 Out.write("//if (initOrder) {\n")
331 Out.write("\tapp1 = new App1(this)\n")
332 Out.write("\tapp2 = new App2(this)\n")
333 Out.write("//} else {\n")
334 Out.write("\t//app2 = new App2(this)\n")
335 Out.write("\t//app1 = new App1(this)\n")
337 Out.write("//def installOrder = Verify.getBoolean()\n")
338 Out.write("//if (installOrder) {\n")
339 Out.write("\tapp1.installed()\n")
340 Out.write("\tapp2.installed()\n")
341 Out.write("//} else {\n")
342 Out.write("\t//app2.installed()\n")
343 Out.write("\t//app1.installed()\n")
345 for line in eventSimulator: