Bläddra i källkod

refactor: add property "seconds_until_next" to _AlarmConfig

Fabian Peter Hammerle 2 år sedan
förälder
incheckning
50d3fdebcc
1 ändrade filer med 6 tillägg och 4 borttagningar
  1. 6 4
      vibrating_alarm_m5stickc.py

+ 6 - 4
vibrating_alarm_m5stickc.py

@@ -59,9 +59,13 @@ class _AlarmConfig:
         self._minute = (self._minute + delta) % 60
 
     @property
-    def daytime(self) -> int:
+    def _daytime(self) -> int:
         return (self._hour * 60 + self._minute) * 60
 
+    @property
+    def seconds_until_next(self) -> int:
+        return (self._daytime - _get_current_daytime() - 1) % (24 * 60 * 60) + 1
+
     def load(self, path: str) -> None:
         with open(path, "r") as alarm_time_file:
             alarm_time = json.load(alarm_time_file)
@@ -126,9 +130,7 @@ class App:
         micropython.schedule(lambda n: self._configure_alarm_timer(), None)
 
     def _configure_alarm_timer(self) -> None:
-        seconds_until_alarm = (
-            self._alarm_config.daytime - _get_current_daytime() - 1
-        ) % (24 * 60 * 60) + 1
+        seconds_until_alarm = self._alarm_config.seconds_until_next
         print("alarm in ", seconds_until_alarm / 60, " min")
         # TODO configure wake from sleep
         self._alarm_timer.init(  # type: ignore