aboutsummaryrefslogtreecommitdiff
path: root/bin/timetemp.py
blob: 03f147b9e0ae609a6fd42d2588871c72fbae3c1c (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
62
63
64
65
66
67
68
69
#!/usr/bin/python3
# References : SPDX-FileCopyrightText: 2019 Mikey Sklar for Adafruit Industries
# SPDX-License-Identifier: MIT

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)