forked from chrowe/opk-1-wire-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpull
executable file
·31 lines (24 loc) · 971 Bytes
/
pull
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
#!/usr/bin/python
import argparse
import json
from w1thermsensor import W1ThermSensor
parser = argparse.ArgumentParser()
parser.add_argument("-p","--path", help="Specify a specific sensor ID. If path not provided returns all.")
parser.add_argument("-s","--scale", help="Choose fahrenheit (f) or celsius (c)")
parser.add_argument("-r","--round", action='store_true', default=False, help="Add to round values")
args = parser.parse_args()
def transform ( temperature ):
if args.scale == "fahrenheit" or args.scale == "f":
temperature = temperature * 1.8 + 32
if args.round == True:
temperature = int(round(temperature))
return temperature
if args.path == None:
data = {}
for sensor in W1ThermSensor.get_available_sensors():
data[sensor.id] = transform(sensor.get_temperature())
print(json.dumps(data))
else:
sensor = W1ThermSensor(sensor_id=args.path)
temp = transform(sensor.get_temperature())
print(temp)