forked from worm-ee/robart-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robart_cli.py
85 lines (63 loc) · 2.41 KB
/
robart_cli.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
import logging
from operator import attrgetter
from argparse import ArgumentParser
import sys
import time
import robart
def main():
parser = ArgumentParser(description="A cli wrapper for the Robart MyVacBot API")
parser.add_argument("--ip", dest="ip", help="ip address of the robot")
parser.add_argument("--scan", dest="scan", help="ip address of the robot")
cmd = parser.add_argument_group("Commands")
cmd.add_argument("--status", action="store_true", dest="cmd_status", help="command: clean")
cmd.add_argument("--clean", action="store_true", dest="cmd_clean", help="command: clean")
cmd.add_argument("--stop", action="store_true", dest="cmd_stop", help="command: stop")
cmd.add_argument("--home", action="store_true", dest="cmd_home", help="command: go home")
cmd.add_argument("--test", dest="cmd_test", help="command: test")
ip = ''
ips = []
args = parser.parse_args()
command_entered = False
rob = robart.Robart_MyVacBot('10.0.0.31', '10009')
if args.ip:
command_entered = False
ip = args.ip
rob.set_rest_url(ip)
if args.scan:
command_entered = True
network = args.scan
ips = robart.scan(network)
if len(ips) > 0:
print("Found robots at {}".format(ips))
ip = ips[0]
rob.set_rest_timeout(0.5, 3)
rob.set_rest_url(ip)
try:
rob.get_state()
rob.get_robotid()
except:
print("No robot found")
return
if args.cmd_status:
command_entered = True
print('mode: {}, charging: {}, battery_level: {}'.format(rob._mode, rob._charging, rob._battery_level))
print('name: {}, unique_id: {}, camlas_unique_id: {}, model: {}, firmware: {}'.format(rob._name, rob._unique_id, rob._camlas_unique_id, rob._model, rob._firmware))
if args.cmd_clean:
command_entered = True
rob.set_clean()
if args.cmd_stop:
command_entered = True
rob.set_stop()
if args.cmd_home:
command_entered = True
rob.set_home()
if args.cmd_test:
command_entered = True
rob.test(args.cmd_test)
if not command_entered:
parser.print_help()
def printEvents(eventList):
for event in eventList:
print(u"EventType: {} Data: {}".format(event["eventType"], event["data"]))
if __name__ == "__main__":
main()