コード例 #1
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
コード例 #2
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
コード例 #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_once(self):
        timepoint = datetime(day=1, month=3, year=2020, hour=6, minute=13)

        alarm1 = AlarmConfig(waketime='7:15', days=[], enabled=True)
        self.assertEqual(timepoint.replace(hour=7, minute=15),
                         AlarmManager._alarm_time(alarm1, timepoint))

        alarm2 = AlarmConfig(waketime='5:15', days=[], enabled=True)
        self.assertEqual(timepoint.replace(day=2, hour=5, minute=15),
                         AlarmManager._alarm_time(alarm2, timepoint))
コード例 #5
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))
コード例 #6
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)
コード例 #7
0
    def test_frequently2(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
        alarm1 = AlarmConfig(waketime='7:15', days=[6, 7], enabled=True)
        self.assertEqual(timepoint.replace(hour=7, minute=15),
                         AlarmManager._alarm_time(alarm1, timepoint))

        # test timepoint has passed today + not matching
        alarm2 = AlarmConfig(waketime='5:15', days=[6, 7], enabled=True)
        self.assertEqual(timepoint.replace(day=7, hour=5, minute=15),
                         AlarmManager._alarm_time(alarm2, timepoint))
コード例 #8
0
    def test_frequently1(self):
        # this is a wednesday, so iso weekday=3
        timepoint = datetime(day=4, month=3, year=2020, hour=6, minute=13)

        # test direct matching day
        alarm1 = AlarmConfig(waketime='7:15',
                             days=[1, 2, 3, 4, 5],
                             enabled=True)
        self.assertEqual(timepoint.replace(hour=7, minute=15),
                         AlarmManager._alarm_time(alarm1, timepoint))

        # test timepoint has passed today + matching next day
        alarm2 = AlarmConfig(waketime='5:15',
                             days=[1, 2, 3, 4, 5],
                             enabled=True)
        self.assertEqual(timepoint.replace(day=5, hour=5, minute=15),
                         AlarmManager._alarm_time(alarm2, timepoint))
コード例 #9
0
ファイル: simpledigiclock.py プロジェクト: brederle/myclockpi
    def on_date(self, context, newTime):
        '''
        Output new date with layout taken from the field content in the
        current layout
        '''
        tm = newTime.strftime(self.currentLayout.dateFormat)
        self.currentLayout.dateValue.text = tm

        atime = AlarmManager.str_alarm_relative(newTime)
        Logger.info("Next alarm: " + atime)
        if atime == "":
            self.currentLayout.ids.sleepButton.text = ""
        else:
            self.currentLayout.ids.sleepButton.text = ""
コード例 #10
0
 def test_uninitialized(self):
     self.assertFalse(AlarmManager.is_alarm_now(datetime.now()))
コード例 #11
0
 def str_next_alarm(self):
     return AlarmManager.str_alarm_relative(datetime.now())