creazione degli oggetti di programmazione

This commit is contained in:
jops 2015-12-14 02:45:35 +01:00
parent 5e692c8c4b
commit aa1cd182a1

View file

@ -1,12 +1,73 @@
#!/usr/bin/python
import bluetooth
import sys
import time
import datetime
import time as tm
import datetime as dt
from datetime import datetime, date, time
class Programma:
def __init__(self, inizio, fine, temperatura):
self.inizio = inizio
self.fine = fine
self.temperatura = temperatura
def inOrario(self):
if (type(self.inizio) is datetime and type(self.fine) is datetime):
if (self.ripeti == False):
return self.inizio < datetime.now() < self.fine
if (self.ripeti == True):
return self.inizio.time() < datetime.now().time() < self.inizio.time()
else:
if(type(self.inizio) is time and type(self.fine) is time):
return self.inizio < datetime.now().time() < self.fine
else:
return False
def inTemperaturaDesiderata(self, temperaturaAmbiente):
return self.temperatura >= temperaturaAmbiente
def accediCaldaia(self, temperaturaAmbiente):
return self.inOrario() and self.inTemperaturaDesiderata(temperaturaAmbiente)
bt_add = "98:D3:31:B2:35:33" #termostato
br_add = "30:14:06:26:04:18" #rele
print datetime.now().time()
t1 = dt.time(7, 0, 0)
t2 = dt.time(9, 0, 0)
mattina = Programma(t1, t2,2000)
t3 = dt.time(18, 0, 0)
t4 = dt.time(20, 0, 0)
sera = Programma(t2, t3,2000)
t5 = dt.time(00, 0, 0)
t6 = dt.time(23, 0, 0)
sempre = Programma(t5, t6,1800)
programmazioni = [mattina, sera, sempre]
print mattina.accediCaldaia(2015)
print sera.accediCaldaia(2015)
print sempre.accediCaldaia(1500)
for ndx, member in enumerate(programmazioni):
print member.accediCaldaia(2015)
#print datetime.now()
#print t1
#print t2
#p1Inizio = datetime(2015, 11, 21, 16, 30)
#p1Fine = datetime(2015, 11, 22, 16, 30)
#long_rectangle = Programma(p1Inizio, p1Fine,2014)
#connessione ai dispositivi
portRele = 1
@ -18,6 +79,7 @@ sockRele=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sockRele.connect((br_add, portRele))
print 'Connesso al rele'
sockTerm.settimeout(1.0)
sockRele.settimeout(1.0)
@ -65,3 +127,4 @@ sockRele.close()
sockTerm.close()