Initial commit
This commit is contained in:
50
heat/_Heat.py
Normal file
50
heat/_Heat.py
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
import datetime
|
||||
import threading
|
||||
import time
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
class Heat(threading.Thread):
|
||||
def __init__(self, pin):
|
||||
super(Heat, self).__init__()
|
||||
self.__pin = pin
|
||||
self.__state = False
|
||||
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(pin, GPIO.OUT)
|
||||
|
||||
if GPIO.input(pin):
|
||||
self.__state = True
|
||||
self.__run_condition = True
|
||||
self.__next_update = datetime.datetime.now()
|
||||
|
||||
def on(self):
|
||||
self.__state = True
|
||||
GPIO.output(self.__pin, 0)
|
||||
|
||||
def off(self):
|
||||
self.__state = False
|
||||
GPIO.output(self.__pin, 1)
|
||||
|
||||
def run(self):
|
||||
self.__next_update = datetime.datetime.now()
|
||||
while self.__run_condition:
|
||||
now = datetime.datetime.now()
|
||||
if now >= self.__next_update:
|
||||
if self.__state:
|
||||
# Do a power cycle to prevent auto-poweroff
|
||||
GPIO.output(self.__pin, 1)
|
||||
time.sleep(5)
|
||||
GPIO.output(self.__pin, 0)
|
||||
self.__next_update = now + datetime.timedelta(minutes=5)
|
||||
time.sleep(1)
|
||||
self.off()
|
||||
|
||||
def stop(self):
|
||||
self.__run_condition = False
|
||||
self.join()
|
||||
|
||||
def state(self):
|
||||
return self.__state
|
1
heat/__init__.py
Normal file
1
heat/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from ._Heat import Heat
|
Reference in New Issue
Block a user