summaryrefslogtreecommitdiff
path: root/heating.py
diff options
context:
space:
mode:
Diffstat (limited to 'heating.py')
-rw-r--r--heating.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/heating.py b/heating.py
new file mode 100644
index 0000000..e780cd2
--- /dev/null
+++ b/heating.py
@@ -0,0 +1,66 @@
+import RPi.GPIO as GPIO
+from abc import ABC, abstractmethod
+
+# Abstract Class for heating
+class heating(ABC):
+ def __init__(self, db):
+ self.temperature = 0
+ self.taget = 0
+ self.on = False
+ self.db = db
+ self.setup()
+
+ def up(self, increase=0.5):
+ self.target += increase
+ self.update()
+
+ def down(self, decrease=0.5):
+ self.target -= decrease
+ self.update()
+
+ def update(self):
+ if self.temperature < self.target:
+ self.on = True
+ else:
+ self.on = False
+ '''
+ Abstract methods used so that configuration for different
+ device types other than a Raspberry Pi is easier in the future
+ and all other methods can simply be inherited
+ '''
+
+ # Method for initial setup according to device GPIO
+ @abstractmethod
+ def setup(self):
+ pass
+ # Method to turn the heating on
+ @abstractmethod
+ def turn_on(self):
+ pass
+ # Method to turn the heating off
+ @abstractmethod
+ def turn_off(self):
+ pass
+ # Method to get the current actual temperature, can be changed for
+ # different types of temperature sensor when inheriting this
+ # class
+ @abstractmethod
+ def get_temperature(self):
+ pass
+
+# inherrited from heating class
+# overriding abstract methods from heating class
+class rpi_heating(heating):
+ def setup(self):
+ # GPIO Numbers instead of board numbers
+ GPIO.setmode(GPIO.BCM)
+ # https://tutorials-raspberrypi.com/raspberry-pi-control-relay-switch-via-gpio/
+ # constant value for the relay number
+ self.RELAY = 17
+ GPIO.setup(self.RELAY, GPIO.OUT) # GPIO Assign mode
+ def turn_on(self):
+ GPIO.output(self.RELAY, GPIO.LOW) # out
+ def turn_on(self):
+ GPIO.output(self.RELAY, GPIO.HIGH) # on
+ def get_temperature(self):
+ pass