Stagger humidifier toggles to avoid browning out the USB adapter
This commit is contained in:
parent
f69ae9eed2
commit
4ba46b8331
|
@ -18,6 +18,7 @@ try:
|
|||
except KeyError:
|
||||
is_mock = False
|
||||
|
||||
print("controller start")
|
||||
process = None
|
||||
def start_process():
|
||||
global process
|
||||
|
@ -189,6 +190,7 @@ class Controller:
|
|||
self.target_lower = 85
|
||||
self.target_upper = 90
|
||||
self.feedforward_coeff = 50
|
||||
self.last_toggle = 0
|
||||
|
||||
self._manual_mode = False
|
||||
self.manual_on = False
|
||||
|
@ -207,6 +209,11 @@ class Controller:
|
|||
self._manual_mode = on
|
||||
send_update({"status": {"manual_mode": on}})
|
||||
|
||||
def toggle_checked(self, humidifier, s):
|
||||
if time.time() - self.last_toggle > 0.8:
|
||||
humidifier.toggle(s)
|
||||
self.last_toggle = time.time()
|
||||
|
||||
def update(self, humidifier, humidifier2, humidity):
|
||||
if self.first_sample:
|
||||
self.humidifier_history[:] = humidity
|
||||
|
@ -225,20 +232,24 @@ class Controller:
|
|||
|
||||
if self.manual_mode:
|
||||
if humidifier.off and self.manual_on:
|
||||
humidifier.toggle(s)
|
||||
self.toggle_checked(humidifier, s)
|
||||
elif humidifier.on and not self.manual_on:
|
||||
humidifier.toggle(s)
|
||||
self.toggle_checked(humidifier, s)
|
||||
if humidifier2.off and self.manual_on:
|
||||
self.toggle_checked(humidifier2, s)
|
||||
elif humidifier2.on and not self.manual_on:
|
||||
self.toggle_checked(humidifier2, s)
|
||||
else:
|
||||
if comp_humidity < self.target_lower:
|
||||
if humidifier.off:
|
||||
humidifier.toggle(s)
|
||||
self.toggle_checked(humidifier, s)
|
||||
if humidifier2.off:
|
||||
humidifier2.toggle(s)
|
||||
self.toggle_checked(humidifier2, s)
|
||||
elif comp_humidity > self.target_upper:
|
||||
if humidifier.on:
|
||||
humidifier.toggle(s)
|
||||
self.toggle_checked(humidifier, s)
|
||||
if humidifier2.on:
|
||||
humidifier2.toggle(s)
|
||||
self.toggle_checked(humidifier2, s)
|
||||
|
||||
humidifier = Humidifier()
|
||||
humidifier2 = HumidifierV2()
|
||||
|
|
Loading…
Reference in New Issue