コード例 #1
0
ファイル: clockcontroller.py プロジェクト: brederle/myclockpi
    def build(self):
        self._screenManager = ScreenManager(transition=SlideTransition())

        # main screen has to be added first to screenmanager
        self.clockFace = SimpleDigiClock()
        self.clockFace.register_actions(self.on_settings, self.on_sleep,
                                        self.on_stop, self.on_mic)

        clockFaceScreen = Screen(name="clockface")
        clockFaceScreen.add_widget(self.clockFace.currentLayout)
        self._screenManager.add_widget(clockFaceScreen)

        # this is the first "satelite" screen
        settingsScreen = Screen(name="settings")
        # settingsScreen.add_widget(ClockSettings())
        self._screenManager.add_widget(settingsScreen)
        # TODO: some default sizes; make configurable?
        self.font_size = 36

        # initialize clock scheduling
        self.currentTime = datetime.now()
        AlarmManager.next_alarm(self.settings.alarms, self.currentTime)
        self.changeTime(self.currentTime)
        self.changeDate(self.currentTime)
        Clock.schedule_interval(self.updateClockFace, 0.2)
        # self.testalarm.on_alarm(self.context)

        return self._screenManager
コード例 #2
0
ファイル: clockcontroller.py プロジェクト: brederle/myclockpi
    def updateClockFace(self, delta):
        newDateTime = datetime.now()

        newBrightness = self.context.brightnessSensor.isDayLight()
        if (self.brightness != newBrightness):
            self.changeBrightness(newBrightness)
        self.brightness = newBrightness

        #newDirection = self.context.directionSensor.getDirection()
        # if (self.direction != newDirection):
        #    self.changeDirection(newDirection)
        #self.direction = newDirection

        if (self.currentTime.second != newDateTime.second):
            # update on_time every second
            self.changeTime(newDateTime)

        if (self.currentTime.minute != newDateTime.minute):
            # check for alarm only every minute
            if AlarmManager.is_alarm_now(newDateTime):
                # start Alarm effect, do callback
                effect = filter(
                    lambda e: e.name == AlarmManager.alarm_config.effect,
                    self.settings.effects)
                EffectType = type(effect.effect_type, (), {})
                self.currentEffect = Effect(effects.links[0])
                self.currentEffect.on_alarm(self.context)
            if AlarmManager.alarm_time < newDateTime:
                # compute new alarm if old one is in the past
                AlarmManager.next_alarm(self.settings.alarms, newDateTime)

        if (self.currentTime.day != newDateTime.day):
            # notify on date changes
            self.changeDate(newDateTime)
        self.currentTime = newDateTime
コード例 #3
0
    def test_is_alarm_now(self):
        # test direct matching day
        alarm_configs_once = [
            AlarmConfig(waketime='6:12', days=[], enabled=True),
        ]
        AlarmManager.next_alarm(
            alarm_configs_once,
            datetime(day=18, month=3, year=2020, hour=6, minute=13))

        atime = datetime(day=19,
                         month=3,
                         year=2020,
                         hour=6,
                         minute=12,
                         second=44,
                         microsecond=123)
        self.assertTrue(AlarmManager.is_alarm_now(atime))

        atime = datetime(day=19,
                         month=3,
                         year=2020,
                         hour=6,
                         minute=13,
                         second=44,
                         microsecond=123)
        self.assertFalse(AlarmManager.is_alarm_now(atime))

        atime = datetime(day=19,
                         month=3,
                         year=2020,
                         hour=6,
                         minute=11,
                         second=59,
                         microsecond=123)
        self.assertFalse(AlarmManager.is_alarm_now(atime))
コード例 #4
0
    def test_str_alarm_relative_none(self):
        # test direct matching day
        alarm_configs_once = [
            AlarmConfig(waketime='6:12', days=[], enabled=False),
        ]
        AlarmManager.next_alarm(
            alarm_configs_once,
            datetime(day=18, month=3, year=2020, hour=15, minute=13))

        todayalarm = datetime(day=18, month=3, year=2020, hour=6, minute=13)
        self.assertEqual("", AlarmManager.str_alarm_relative(todayalarm))
コード例 #5
0
    def test_next_alarm_none(self):
        # this is a sunday, so iso weekday=7
        timepoint = datetime(day=1, month=3, year=2020, hour=6, minute=13)

        # test direct matching day
        alarm_configs_none = [
            AlarmConfig(waketime='7:15', days=[6, 7], enabled=False),
            AlarmConfig(waketime='5:12', days=[], enabled=False),
            AlarmConfig(waketime='6:00', days=[1, 2, 3, 4, 5], enabled=False),
        ]
        AlarmManager.next_alarm(alarm_configs_none, timepoint)
        self.assertEqual(timepoint.max, AlarmManager.alarm_time)