This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtransformers.py
68 lines (61 loc) · 2.65 KB
/
transformers.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
import os
def device_transform(device_name, fields):
# Create a dict copy to work on...
# So we're not iterating a changing dict
new_fields = fields.copy()
if device_name == "bme680":
print("Transforming {0} value(s)...".format(device_name))
for field in fields:
if field == "humidityrelative":
new_fields["humidity"] = new_fields.pop("humidityrelative")
elif field == "temp":
x = fields[field]
if os.getenv('TEMP_UNIT', 'C') == 'F':
new_fields[field]= ((x/1000) * 1.8) + 32
else:
new_fields[field] = x/1000
new_fields["temperature"] = new_fields.pop("temp")
elif device_name == "bme280":
print("Transforming {0} value(s)...".format(device_name))
for field in fields:
if field == "humidityrelative":
new_fields[field] = fields[field]/1000
new_fields["humidity"] = new_fields.pop("humidityrelative")
elif field == "temp":
x = fields[field]
if os.getenv('TEMP_UNIT', 'C') == 'F':
new_fields[field]= ((x/1000) * 1.8) + 32
else:
new_fields[field] = x/1000
new_fields["temperature"] = new_fields.pop("temp")
elif field == "pressure":
x = fields[field]
new_fields[field] = x * 10
elif device_name == "bmp280":
print("Transforming {0} value(s)...".format(device_name))
for field in fields:
if field == "temp":
x = fields[field]
if os.getenv('TEMP_UNIT', 'C') == 'F':
new_fields[field] = ((x/1000) * 1.8) + 32
else:
new_fields[field] = x/1000
new_fields["temperature"] = new_fields.pop("temp")
elif field == "pressure":
x = fields[field]
new_fields[field] = x * 10
elif device_name == "htu21":
print("Transforming {0} value(s)...".format(device_name))
for field in fields:
if field == "temp":
x = fields[field]
if os.getenv('TEMP_UNIT', 'C') == 'F':
new_fields[field]= ((x/1000) * 1.8) + 32
else:
new_fields[field] = x/1000
new_fields["temperature"] = new_fields.pop("temp")
if field == "humidityrelative":
x = fields[field]
new_fields[field] = x/1000
new_fields["humidity"] = new_fields.pop("humidityrelative")
return new_fields