From 1d1381f390f86fd6fff8af2427a5dd8cd6b65a0f Mon Sep 17 00:00:00 2001 From: William Moore Date: Mon, 4 Apr 2022 18:48:07 -0500 Subject: [PATCH] Use a more precise way for float comparison --- temperato.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/temperato.py b/temperato.py index 6f240b6..455ecfb 100644 --- a/temperato.py +++ b/temperato.py @@ -22,6 +22,7 @@ import threading import time import os import json +import math set_point = 82.22 sleep_timer = 15 @@ -34,7 +35,7 @@ class tempThread (threading.Thread): def run(self): while True: temp = sensor.temperature - if temp >= set_point: + if math.isclose(temp,set_point): print(requests.post(os.environ.get('NOTIF_URL'), headers={'Content-Type': 'application/json', 'Authorization': 'Bearer ' + os.environ.get('ACCESS_TOKEN')}, data=json.dumps({'message': '@all ' + os.environ.get('MESSAGE'), 'channel_id': os.environ.get('CHANNEL_ID')}), timeout=5)) time.sleep(sleep_timer)