aboutsummaryrefslogtreecommitdiff
path: root/bin/timetemp.py
blob: d2da399cfa09dcc733a7cb5138ebce175327115e (plain)
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
#!/usr/bin/python3

import time
import board # type: ignore
import busio # type: ignore

hat_id_file_path = "/proc/device-tree/hat/product"
hat_is_a_rainbow_hat = False

try:
    file=open(hat_id_file_path, "r") 
    content = "" 
    for line in file.readlines():
       content += line
    # print(content) 
    if ('Rainbow HAT' in content):
       hat_is_a_rainbow_hat = True
except FileNotFoundError:
    print("The file was not found. Please check the path.")
    
print("'Rainbow HAT'?" + str(hat_is_a_rainbow_hat) )

if hat_is_a_rainbow_hat:
    import rainbowhat as rh    
    while True:
        rh.display.print_str(time.strftime("%H%M"))
        rh.display.show()
        # display.print(time.strftime("%H:%M"))
        time.sleep(5)
        file=open('/var/lib/prometheus/node-exporter/temp.prom')
        # display.colon = False
        for line in file.readlines():
            values=line.split()[0:2]
            if values[0]=='home_temperature_farenheit':
                rh.display.print_str(str(values[1])[0:3]+'f')
                rh.display.show()
            #    display.print(str(values[1])[0:3]+'f')
        file.close()
        time.sleep(5)
else:    
    from adafruit_ht16k33 import segments # type: ignore

    # Create the I2C interface.
    i2c = busio.I2C(board.SCL, board.SDA)
    # Create the LED segment class.
    # This creates a 7 segment 4 character display:
    display = segments.Seg7x4(i2c)
    # Clear the display.
    display.fill(0)
    while True:
        display.print(time.strftime("%H:%M"))
        time.sleep(5)
        file=open('/var/lib/prometheus/node-exporter/temp.prom')
        display.colon = False
        for line in file.readlines():
            values=line.split()[0:2]
            if values[0]=='home_temperature_farenheit':
                display.print(str(values[1])[0:4]+'f')
        file.close()
        time.sleep(5)