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)
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)
def test_get_next_after_last(self) -> None: tpds1 = TimePeriodSetting('01:00', 25, SettingModes.ON) tpds2 = TimePeriodSetting('05:00', 20, SettingModes.OFF) tpds3 = TimePeriodSetting('08:00', 20, SettingModes.OFF) tpds_day_after = TimePeriodSetting('03:00', 20, SettingModes.OFF) monday = TimeProgramDay([tpds1, tpds2, tpds3]) tuesday = TimeProgramDay([tpds_day_after]) timeprogram = TimeProgram({'monday': monday, 'tuesday': tuesday}) next_setting = timeprogram.get_next(datetime(2019, 2, 18, 9, 30)) self._assert(next_setting, tpds_day_after)
def test_get_next_between_same_day(self) -> None: tpds1 = TimePeriodSetting("01:00", 25, SettingModes.ON) tpds2 = TimePeriodSetting("05:00", 20, SettingModes.OFF) tpds3 = TimePeriodSetting("08:00", 20, SettingModes.OFF) tpds_day_after = TimePeriodSetting("03:00", 20, SettingModes.OFF) monday = TimeProgramDay([tpds1, tpds2, tpds3]) tuesday = TimeProgramDay([tpds_day_after]) timeprogram = TimeProgram({"monday": monday, "tuesday": tuesday}) next_setting = timeprogram.get_next(datetime(2019, 2, 18, 4, 30)) self._assert(next_setting, tpds2)
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)
def test_get_active_mode_circulation_empty_timeprogram(self) -> None: """Test get active mode for circulation.""" dhw = Dhw(circulation=_circulation()) dhw.circulation.time_program = TimeProgram(days={}) system = System(dhw=dhw) active_mode = system.get_active_mode_circulation() self.assertEqual(OperatingModes.AUTO, active_mode.current) self.assertEqual(SettingModes.OFF, active_mode.sub)
def test_get_active_mode_hotwater_empty_timeprogram(self) -> None: """Test get active mode for hot water.""" dhw = Dhw(hotwater=_hotwater()) dhw.hotwater.time_program = TimeProgram(days={}) system = System(dhw=dhw) active_mode = system.get_active_mode_hot_water() self.assertEqual(OperatingModes.AUTO, active_mode.current) self.assertEqual(SettingModes.ON, active_mode.sub) self.assertEqual(50, active_mode.target)
def _time_program(mode: Optional[SettingMode] = SettingModes.ON, temperature: Optional[float] = None) -> TimeProgram: if mode in [SettingModes.DAY, SettingModes.NIGHT]: timeprogram_day_setting = TimePeriodSetting("00:00", None, mode) else: timeprogram_day_setting = TimePeriodSetting("00:00", temperature, mode) timeprogram_day = TimeProgramDay([timeprogram_day_setting]) timeprogram_days = { "monday": timeprogram_day, "tuesday": timeprogram_day, "wednesday": timeprogram_day, "thursday": timeprogram_day, "friday": timeprogram_day, "saturday": timeprogram_day, "sunday": timeprogram_day, } return TimeProgram(timeprogram_days)
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)