-
Notifications
You must be signed in to change notification settings - Fork 2
/
commands.py
58 lines (49 loc) · 1.61 KB
/
commands.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
from utils import merge
import re
def get_para(target, node, para, timeout=1):
data = target.run_command("nodeparaget {} {}".format(node, para), timeout=timeout)
return data[2][4:]
def get_temperature(target):
return int(get_para(target, 4, 73))/10.0 # degC
def get_co2(target):
return int(get_para(target, 4, 74)) # ppm
def get_humidity(target):
return int(get_para(target, 4, 75))/100.0 # %
def get_network_data(target):
line_regex = re.compile(r'^((?:[^\|]+?\|){19}[^\|]+?)$')
field_regex = re.compile(r'([^ \|\n]+) *(?:\||$)')
fields = \
list(
list(
i.group(1) for i in field_regex.finditer(l)
)
for l
in (
i.group(1) for i in (
line_regex.match(l)
for l
in target.run_command("network")
) if i is not None
)
)
keys = fields[0]
values = fields[1:]
return dict((fields[0], dict(zip(keys, ((v if v != "-" else None) for v in fields)))) for fields in values)
def get_fan_speed(target):
line_regex = re.compile(r'^FanSpeed:(.+)$')
field_regex = re.compile(r'([A-Z][a-z]+) ([0-9]+) \[rpm\]')
fields = \
list(
dict(
(i.group(1), int(i.group(2))) for i in field_regex.finditer(l)
)
for l
in (
i.group(1) for i in (
line_regex.match(l)
for l
in target.run_command("fanspeed")
) if i is not None
)
)
return merge(fields)