From 2ee793179e345f3355462c8d2753543bc397a2aa Mon Sep 17 00:00:00 2001 From: root Date: Sun, 16 Jan 2022 13:41:03 +0000 Subject: Reformat code --- circular_queue.py | 4 +++- heating.py | 33 +++++++++------------------------ main.py | 11 ++++++----- queue-test.py | 3 +-- 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: diff --git a/heating.py b/heating.py index 94943cb..ab058d6 100644 --- a/heating.py +++ b/heating.py @@ -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 diff --git a/main.py b/main.py index f58474f..04736c8 100644 --- a/main.py +++ b/main.py @@ -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 - - diff --git a/weather.py b/weather.py index f33cbac..1163dc2 100644 --- a/weather.py +++ b/weather.py @@ -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 -- cgit v1.2.3