コード例 #1
0
    def test_time_program_before_first(self) -> None:
        tpds1 = TimePeriodSetting('01:00', 25, SettingModes.ON)
        tpds2 = TimePeriodSetting('02:00', 20, SettingModes.OFF)

        tpds_sunday = TimePeriodSetting('15:00', 15, SettingModes.OFF)

        sunday = TimeProgramDay([tpds_sunday])
        monday = TimeProgramDay([tpds1, tpds2])

        timeprogram = TimeProgram({'monday': monday, 'sunday': sunday})

        current = timeprogram.get_for(datetime(2019, 2, 18, 0, 30))
        self._assert(tpds_sunday, current)
コード例 #2
0
    def test_time_program_simple(self) -> None:
        tpds1 = TimePeriodSetting("00:00", 25, SettingModes.ON)
        tpds2 = TimePeriodSetting("02:00", 20, SettingModes.OFF)

        monday = TimeProgramDay([tpds1, tpds2])

        timeprogram = TimeProgram({
            "monday": monday,
            "sunday": TimeProgramDay([])
        })

        current = timeprogram.get_for(datetime(2019, 2, 18, 1, 0))
        self._assert(tpds1, current)
コード例 #3
0
    def test_time_program_after_last(self) -> None:
        tpds1 = TimePeriodSetting('00:00', 25, SettingModes.ON)
        tpds2 = TimePeriodSetting('02:00', 20, SettingModes.OFF)

        monday = TimeProgramDay([tpds1, tpds2])

        timeprogram = TimeProgram(
            {
                'monday': monday,
                'sunday': TimeProgramDay([])
            }
        )

        current = timeprogram.get_for(datetime(2019, 2, 18, 3, 0))
        self._assert(tpds2, current)
コード例 #4
0
def _get_setting_for_sunday(
        time_program: TimeProgram) -> Optional[TimePeriodSetting]:
    today = datetime.now()
    sunday = today - timedelta(days=today.weekday() - 6)
    return time_program.get_for(sunday)