generated from selabhvl/ing301-projectpartA-startcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
101 lines (87 loc) · 3.25 KB
/
main.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from smarthouse import SmartHouse
from devices import *
def build_demo_house() -> SmartHouse:
house = SmartHouse()
# TODO! her skal du legge inn etasjer, rom og enheter som at resultatet tilsvarer demo huset!
return house
def do_device_list(smart_house: SmartHouse):
print("Listing Devices...")
idx = 0
for d in smart_house.get_all_devices():
print(f"{idx}: {d}")
idx += 1
def do_room_list(smart_house: SmartHouse):
print("Listing Rooms...")
idx = 0
for r in smart_house.get_all_rooms():
print(f"{idx}: {r}")
idx += 1
def do_find(smart_house: SmartHouse):
print("Please enter serial no: ")
serial_no = input()
device = smart_house.find_device_by_serial_no(serial_no)
if device:
devices = smart_house.get_all_devices()
rooms = smart_house.get_all_rooms()
room = smart_house.get_room_with_device(device)
device_idx = devices.index(device)
room_idx = rooms.index(room)
print(f"Device No {device_idx}:")
print(device)
print(f"is located in room No {room_idx}:")
print(room)
else:
print(f"Could not locate device with serial no {serial_no}")
def do_move(smart_house):
devices = smart_house.get_all_devices()
rooms = smart_house.get_all_rooms()
print("Please choose device:")
device_id = input()
device = None
if device_id.isdigit():
device = devices[int(device_id)]
else:
device = smart_house.find_device_by_serial_no(device_id)
if device:
print("Please choose target room")
room_id = input()
if room_id.isdigit() and rooms[int(room_id)]:
to_room = rooms[int(room_id)]
from_room = smart_house.get_room_with_device(device)
smart_house.move_device(device, from_room, to_room)
else:
print(f"Room with no {room_id} does not exist!")
else:
print(f"Device wit id '{device_id}' does not exist")
def main(smart_house: SmartHouse):
print("************ Smart House Control *****************")
print(f"No of Rooms: {smart_house.get_no_of_rooms()}")
print(f"Total Area: {smart_house.get_total_area()}")
print(f"Connected Devices: {smart_house.get_no_of_devices()} ({smart_house.get_no_of_sensors()} Sensors | {smart_house.get_no_of_actuators()} Actuators)")
print("**************************************************")
print()
print("Management Interface v.0.1")
while (True):
print()
print("Please select one of the following options:")
print("- List all devices in the house (l)")
print("- List all rooms in the house (r) ")
print("- Find a device via its serial number (f)")
print("- Move a device from one room to another (m)")
print("- Quit (q)")
char = input()
if char == "l":
do_device_list(smart_house)
elif char == "r":
do_room_list(smart_house)
elif char == "f":
do_find(smart_house)
elif char == "m":
do_move(smart_house)
elif char == "q":
break
else:
print(f"Error! Could not interpret input '{char}'!")
if __name__ == '__main__':
house = build_demo_house()
main(house)