Switch humidifier 1 to the same wiring as humidifier2

This commit is contained in:
Kelvin Ly 2023-09-21 22:07:23 -04:00
parent f69ae9eed2
commit 4bbf387f4f
1 changed files with 5 additions and 3 deletions

View File

@ -136,10 +136,11 @@ class Humidifier:
# the wiring's a little different so the thresholds for detecting on/off are inverted but hopefully a lot more reliable than the original
class HumidifierV2:
def __init__(self):
def __init__(self, toggle_cmd=b"i"):
self.on_threshold = 1.5
self.off_threshold = 2.5
self.toggle_cooldown = 7
self.toggle_command = toggle_cmd
self._on = False
self.history = np.zeros(10)
@ -179,7 +180,7 @@ class HumidifierV2:
def toggle(self, s):
if time.time() > self.switch_timeout:
s.write(b"i")
s.write(self.toggle_command)
s.flush()
self.switch_timeout = time.time() + self.toggle_cooldown
@ -223,6 +224,7 @@ class Controller:
if self.manual_mode and time.time() > self.manual_timeout:
self.manual_mode = False
# TODO add in support for manual control of second humidifier
if self.manual_mode:
if humidifier.off and self.manual_on:
humidifier.toggle(s)
@ -240,7 +242,7 @@ class Controller:
if humidifier2.on:
humidifier2.toggle(s)
humidifier = Humidifier()
humidifier = HumidifierV2(b"n")
humidifier2 = HumidifierV2()
controller = Controller()