summaryrefslogtreecommitdiff
path: root/heating.py
blob: e780cd280514debbd44eb0aec77e03e4a9ec16a1 (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
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