Pull get_temp out of main loop
This commit is contained in:
parent
be6fb4bc3c
commit
cd8204e020
|
@ -13,32 +13,39 @@ import relays
|
||||||
import data
|
import data
|
||||||
|
|
||||||
HI_SETPOINT = 40.0
|
HI_SETPOINT = 40.0
|
||||||
LO_SETPOINT = 30.0
|
LO_SETPOINT = HI_SETPOINT - 10.0
|
||||||
|
|
||||||
|
PUMP_RELAY = relays.RELAY1
|
||||||
FAN_RELAY = relays.RELAY3
|
FAN_RELAY = relays.RELAY3
|
||||||
|
|
||||||
|
async def get_temp():
|
||||||
|
temps = await w1therm.get_temperatures()
|
||||||
|
if len(temps) != len(data.PROBES):
|
||||||
|
raise
|
||||||
|
|
||||||
|
temperature_log = []
|
||||||
|
for id_, temp in temps.items():
|
||||||
|
temperature_log.append('{}: {} C'.format(data.PROBES[id_], temp))
|
||||||
|
logging.info('Temperature probe ' + ', '.join(temperature_log))
|
||||||
|
|
||||||
|
temperature_list = list(temps.values())
|
||||||
|
temperature_mean = mean(temperature_list)
|
||||||
|
return temperature_mean
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
relays.init_relays()
|
relays.init_relays()
|
||||||
|
relays.set_relay(PUMP_RELAY, relays.RELAY_ON)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
temps = await w1therm.get_temperatures()
|
temperature_mean = await get_temp()
|
||||||
if len(temps) != len(data.PROBES):
|
|
||||||
raise
|
|
||||||
except:
|
except:
|
||||||
logging.error('Problem reading temperature probes! Setting fan on and sleeping.')
|
logging.error('Problem reading temperature probes! Turning fan on and sleeping 60s.')
|
||||||
relays.set_relay(FAN_RELAY, relays.RELAY_ON)
|
relays.set_relay(FAN_RELAY, relays.RELAY_ON)
|
||||||
await asyncio.sleep(60)
|
await asyncio.sleep(60)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
temperature_log = []
|
|
||||||
for id_, temp in temps.items():
|
|
||||||
temperature_log.append('{}: {} C'.format(data.PROBES[id_], temp))
|
|
||||||
logging.info('Temperature probe ' + ', '.join(temperature_log))
|
|
||||||
|
|
||||||
temperature_list = list(temps.values())
|
|
||||||
temperature_mean = mean(temperature_list)
|
|
||||||
|
|
||||||
if temperature_mean > HI_SETPOINT:
|
if temperature_mean > HI_SETPOINT:
|
||||||
logging.info('Turning fan on')
|
logging.info('Turning fan on')
|
||||||
relays.set_relay(FAN_RELAY, relays.RELAY_ON)
|
relays.set_relay(FAN_RELAY, relays.RELAY_ON)
|
||||||
|
|
|
@ -31,7 +31,7 @@ async def test():
|
||||||
for r in RELAYS:
|
for r in RELAYS:
|
||||||
set_relay(r, RELAY_ON)
|
set_relay(r, RELAY_ON)
|
||||||
await asyncio.sleep(0.5)
|
await asyncio.sleep(0.5)
|
||||||
#set_relay(r, RELAY_OFF)
|
set_relay(r, RELAY_OFF)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
init_relays()
|
init_relays()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user