-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
218 lines (182 loc) Β· 7.76 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import time
import os
from src.BardiHelper import BardiConnector
import inquirer
from colorama import Fore, init
from alive_progress import alive_bar
init(autoreset=True)
print(Fore.GREEN + """
___ _ _ __ _ _ _ _ _
/ __\ __ _ _ __ __| (_) / / ___ __| | /_\ _ _| |_ ___ _ __ ___ __ _| |_(_) ___ _ __
/__\/// _` | '__/ _` | | / / / _ \/ _` | //_\\| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \
/ \/ \ (_| | | | (_| | | / /__| __/ (_| | / _ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | |
\_____/\__,_|_| \__,_|_| \____/\___|\__,_| \_/ \_/\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|
Code by @sandrocods
""")
def menu(connector_bardi=None, sleep_condition=None):
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
print(Fore.GREEN + "[!] Connected to device: {}".format(connector_bardi.device_name))
if sleep_condition:
connector_bardi.sleep_device(status=True)
questions_wake = [
inquirer.List('wake',
message="Wake device?",
choices=['Yes', 'No'],
),
]
answers_wake = inquirer.prompt(questions_wake)
if answers_wake['wake'] == 'Yes':
connector_bardi.sleep_device(status=False)
time.sleep(1)
menu(connector_bardi=connector_bardi, sleep_condition=False)
else:
menu(connector_bardi=connector_bardi, sleep_condition=True)
else:
questions_menu = [
inquirer.List('menu',
message="What do you want to do?",
choices=[
'Sleep Phone',
'Change Color LED',
'Change Theme LED',
'Change Power Device',
'Change Brightness LED',
'Exit'
],
),
]
answers_menu = inquirer.prompt(questions_menu)
if answers_menu['menu'] == 'Change Color LED':
dict = connector_bardi.location_color
dict['Sepia'] = 'Sepia'
dict['White'] = 'White'
dict['Half White'] = 'Half White'
questions_color = [
inquirer.List('color',
message="What color do you want to set?",
choices=dict,
carousel=True,
),
]
answers_color = inquirer.prompt(questions_color)
connector_bardi.change_color(answers_color['color'])
menu(connector_bardi)
elif answers_menu['menu'] == 'Change Brightness LED':
questions_brightness = [
inquirer.List('brightness',
message="What brightness do you want to set?",
choices=connector_bardi.brightness,
),
]
answers_brightness = inquirer.prompt(questions_brightness)
connector_bardi.change_brightness(answers_brightness['brightness'])
menu(connector_bardi)
elif answers_menu['menu'] == 'Change Theme LED':
questions_theme = [
inquirer.List('theme',
message="What theme do you want to set?",
choices=["Music", "Normal"],
),
]
answers_theme = inquirer.prompt(questions_theme)
if answers_theme['theme'] == "Music":
connector_bardi.get_theme_by_music()
questions_theme_music = [
inquirer.List('theme_music',
message="What theme music do you want to set?",
choices=connector_bardi.theme_data,
),
]
answers_theme_music = inquirer.prompt(questions_theme_music)
connector_bardi.change_theme(theme_name=answers_theme_music['theme_music']['theme_name'],
theme_type="music")
del connector_bardi.theme_data
menu(connector_bardi)
else:
connector_bardi.get_theme()
questions_theme_normal = [
inquirer.List('theme_normal',
message="What theme normal do you want to set?",
choices=connector_bardi.theme_data,
),
]
answers_theme_normal = inquirer.prompt(questions_theme_normal)
connector_bardi.change_theme(theme_name=answers_theme_normal['theme_normal']['theme_name'],
theme_type="normal")
del connector_bardi.theme_data
menu(connector_bardi)
elif answers_menu['menu'] == 'Change Power Device':
questions_power = [
inquirer.List('power',
message="What power do you want to set?",
choices=['on', 'off'],
),
]
answers_power = inquirer.prompt(questions_power)
connector_bardi.change_state(answers_power['power'])
menu(connector_bardi)
elif answers_menu['menu'] == 'Sleep Phone':
menu(connector_bardi, sleep_condition=True)
elif answers_menu['menu'] == 'Exit':
exit()
global connector_bardi
questions_connection = [
inquirer.List('connection_type',
message="Select connection type",
choices=['usb', 'wifi', 'ngrok'],
),
]
answers_connection = inquirer.prompt(questions_connection)
if answers_connection["connection_type"] == "wifi":
questions_wifi = [
inquirer.Text('address',
message="Enter address",
),
]
connector_bardi = BardiConnector(
timeout=10.0,
connection_type="wifi",
address=inquirer.prompt(questions_wifi)["address"]
)
elif answers_connection["connection_type"] == "usb":
connector_bardi = BardiConnector(
timeout=10.0,
connection_type="usb",
)
elif answers_connection["connection_type"] == "ngrok":
questions_ngrok = [
inquirer.Text('address',
message="Enter address",
),
]
connector_bardi = BardiConnector(
timeout=10.0,
connection_type="ngrok",
address=inquirer.prompt(questions_ngrok)["address"]
)
get_device_bardi = connector_bardi.get_bardi_device()
if get_device_bardi["status"]:
with alive_bar(total=len(get_device_bardi["data_device"]), title="Get Device Bardi", force_tty=True) as bar:
for device in get_device_bardi["data_device"]:
bar()
time.sleep(0.5)
questions_device = [
inquirer.List('device',
message="Select device",
choices=get_device_bardi["data_device"],
),
]
answers_device = inquirer.prompt(questions_device)["device"]
connect_device_bardi = connector_bardi.connect_bardi_device(answers_device)
if connect_device_bardi["status"]:
print(Fore.GREEN + "[!] Device {} connected".format(answers_device))
menu(
connector_bardi=connector_bardi,
)
else:
print(Fore.RED + "[!] Device not connected")
else:
print(Fore.RED + "[!] Device not found")