diff options
| author | root <root@turin.home> | 2022-01-16 13:41:03 +0000 |
|---|---|---|
| committer | root <root@turin.home> | 2022-01-16 13:41:03 +0000 |
| commit | 2ee793179e345f3355462c8d2753543bc397a2aa (patch) | |
| tree | d1c68adff555f3dc3fbf8a5702855114119bff10 | |
| parent | befb917ec5cbcbb0aaae33c53e6c0b2c4b92afcf (diff) | |
Reformat code
| -rw-r--r-- | circular_queue.py | 4 | ||||
| -rw-r--r-- | heating.py | 33 | ||||
| -rw-r--r-- | main.py | 11 | ||||
| -rw-r--r-- | queue-test.py | 3 | ||||
| -rw-r--r-- | weather.py | 8 |
5 files changed, 23 insertions, 36 deletions
diff --git a/circular_queue.py b/circular_queue.py index 85516cf..424d1e5 100644 --- a/circular_queue.py +++ b/circular_queue.py @@ -1,15 +1,17 @@ class circular_queue: - def __init__(self,size): + def __init__(self, size): self.size = size self.queue = [] for i in range(self.size): self.queue.append(None) self.pointer = 0 + def add(self, value): self.queue[self.pointer] = value self.pointer += 1 if self.pointer > 49: self.pointer = 0 + def average(self): queue = self.queue while None in queue: @@ -30,7 +30,7 @@ class heating(ABC): else: self.on = False self.turn_off() - ''' + """ self.db.exec( "insert into temperature values (?,?,?,?)", (date, time, self.temperature, self.target), @@ -39,7 +39,7 @@ class heating(ABC): "insert into history values (?,?,?)", (date, time, heatingon(int)), ) - ''' + """ """ Abstract methods used so that configuration for different @@ -68,7 +68,7 @@ class heating(ABC): # inherited from heating class # overriding abstract methods from heating class class rpi_heating(heating): - def __init__(self,db): + def __init__(self, db): # https://tutorials-raspberrypi.com/raspberry-pi-control-relay-switch-via-gpio/ # https://www.ics.com/blog/gpio-programming-using-sysfs-interface # https://medium.com/initial-state/how-to-build-a-raspberry-pi-temperature-monitor-8c2f70acaea9 @@ -82,36 +82,21 @@ class rpi_heating(heating): # setup GPIO for the relay - os.system( - "echo {} >/sys/class/gpio/export".format(self.RELAY) - ) - os.system( - "echo out >/sys/class/gpio/gpio{}/direction".format( - self.RELAY - ) - ) + os.system("echo {} >/sys/class/gpio/export".format(self.RELAY)) + os.system("echo out >/sys/class/gpio/gpio{}/direction".format(self.RELAY)) # file that the temperature gets written t - self.sensor = "/sys/bus/w1/devices/{}/w1_slave".format( - self.SENSORID - ) + self.sensor = "/sys/bus/w1/devices/{}/w1_slave".format(self.SENSORID) def turn_on(self): # turn the heating on by triggering the relay - os.system( - "echo 1 >/sys/class/gpio/gpio{}/value".format(self.RELAY) - ) + os.system("echo 1 >/sys/class/gpio/gpio{}/value".format(self.RELAY)) def turn_off(self): # turn the heating off by triggering the relay - os.system( - "echo 0 >/sys/class/gpio/gpio{}/value".format(self.RELAY) - ) + os.system("echo 0 >/sys/class/gpio/gpio{}/value".format(self.RELAY)) def get_temperature(self): with open(self.sensor, "r") as file: data = file.read() # parse temperature from file - return ( - float(data.split("\n")[1].split(" ")[9].split("=")[1]) - / 1000 - ) + return float(data.split("\n")[1].split(" ")[9].split("=")[1]) / 1000 @@ -16,7 +16,7 @@ DBFILE = "data.db" db = sql.db(DBFILE) -#weather = weather_met_no() +# weather = weather_met_no() # Check if running on correct device : defensive coding against running # on the wrong device @@ -38,7 +38,7 @@ def main_page(): "main.html", actual_temp=boiler.temperature, target_temp=boiler.target - #forecast_temp=weather.temperature() + # forecast_temp=weather.temperature() ) @@ -72,18 +72,19 @@ def export(opt): elif opt == "pdf": pass else: - return render_template( - "error.html", error="Invalid export type" - ) + return render_template("error.html", error="Invalid export type") + def updater(): while True: boiler.update() time.sleep(5) + def webapp(): app.run(host="0.0.0.0") + if __name__ == "__main__": t1 = Thread(target=webapp) t2 = Thread(target=updater) diff --git a/queue-test.py b/queue-test.py index f7b6380..c68ec51 100644 --- a/queue-test.py +++ b/queue-test.py @@ -1,5 +1,6 @@ from circular_queue import circular_queue + def test_queue_average(): a = circular_queue(50) a.add(1) @@ -11,5 +12,3 @@ def test_queue_average(): def test_queue_average_null(): a = circular_queue(50) assert a.average() == 0 - - @@ -36,10 +36,10 @@ class weather_met_no(weather): def get_temperature(self): # https://docs.python-requests.org/en/latest/ try: - data = requests.get( - self.CALL, headers=self.HEADERS - ).json()['properties']['timeseries'][0]['data'] - return data['instant']['details']['air_temperature'] + data = requests.get(self.CALL, headers=self.HEADERS).json()["properties"][ + "timeseries" + ][0]["data"] + return data["instant"]["details"]["air_temperature"] # data['next_1_hours']['summary']['symbol_code'] except: return -1 |
