Fix fan reset on resume from sleep

This commit is contained in:
NGnius (Graham) 2022-05-09 12:53:36 -04:00
parent 088acc4301
commit d7b63fe64f

View file

@ -1,6 +1,7 @@
import json import json
import os import os
import asyncio import asyncio
import time
import logging import logging
@ -179,8 +180,14 @@ class Plugin:
self.settings["curve"] = DEFAULT_DATA["curve"] self.settings["curve"] = DEFAULT_DATA["curve"]
self.is_changed = True self.is_changed = True
on_set_enable(self.settings["enable"]) on_set_enable(self.settings["enable"])
last_time = time.time()
# work loop # work loop
while True: while True:
if (time.time() - last_time) * 0.9 > self.period_s:
# detect sleep
logging.debug("Detected resume from sleep, overriding fan again")
on_set_enable(self.settings["enable"])
last_time = time.time()
if self.is_changed: if self.is_changed:
self.save(self) self.save(self)
self.is_changed = False self.is_changed = False