-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
33 lines (25 loc) · 911 Bytes
/
Copy pathmain.py
File metadata and controls
33 lines (25 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import asyncio
from models.devices import *
from models import Controller, DeviceLocation
async def main(controller: Controller):
devices = [
SmartCamera("Garage Camera", DeviceLocation.GARAGE, 100),
SmartBulb("Bedroom Light", DeviceLocation.BEDROOM, 100),
SmartThermostat(
"Living Room Thermostat", DeviceLocation.LIVING_ROOM, 22.0, 23.0, 30.0
),
]
async with asyncio.TaskGroup() as tg:
tg.create_task(controller.consume())
for device in devices:
tg.create_task(device.run(controller))
if __name__ == "__main__":
# initialize controller
controller = Controller()
try:
asyncio.run(main(controller))
except KeyboardInterrupt:
print("Shutting down IoT system...")
# end storage worker thread
# by inserting "None" into storage queue
controller.end_storage_thread()