فهرست منبع

refactor: convert static property to method

Fabian Peter Hammerle 2 سال پیش
والد
کامیت
9e0128bdd7
1فایلهای تغییر یافته به همراه9 افزوده شده و 9 حذف شده
  1. 9 9
      vibrating_alarm_m5stickc.py

+ 9 - 9
vibrating_alarm_m5stickc.py

@@ -31,6 +31,14 @@ def _handle_pending_events():
     utime.sleep_ms(11)
 
 
+def _get_current_daytime() -> int:
+    # > [contradictory to] official micropython documentation, to set RTC,
+    # > use particular tuple (year , month, day, week=0, hour, minute, second, timestamp=0)
+    # https://community.m5stack.com/topic/3108/m5stack-core2-micropython-rtc-example
+    hour, minute, seconds = rtc.now()[3:]
+    return (hour * 60 + minute) * 60 + seconds
+
+
 class App:
     # pylint: disable=too-few-public-methods,too-many-instance-attributes
     def __init__(self) -> None:
@@ -45,14 +53,6 @@ class App:
         self._alarm_timer = None
         self._battery_status_text_box = None
 
-    @property
-    def _now_daytime(self) -> int:
-        # > [contradictory to] official micropython documentation, to set RTC,
-        # > use particular tuple (year , month, day, week=0, hour, minute, second, timestamp=0)
-        # https://community.m5stack.com/topic/3108/m5stack-core2-micropython-rtc-example
-        hour, minute, seconds = rtc.now()[3:]
-        return (hour * 60 + minute) * 60 + seconds
-
     @property
     def _alarm_daytime(self) -> int:
         return (self._alarm_hour * 60 + self._alarm_minute) * 60  # type: ignore
@@ -107,7 +107,7 @@ class App:
         micropython.schedule(lambda n: self._configure_alarm_timer(), None)
 
     def _configure_alarm_timer(self) -> None:
-        seconds_until_alarm = (self._alarm_daytime - self._now_daytime - 1) % (
+        seconds_until_alarm = (self._alarm_daytime - _get_current_daytime() - 1) % (
             24 * 60 * 60
         ) + 1
         print("alarm in ", seconds_until_alarm / 60, " min")