Beispiel #1
0
def test_repeating_schedule():
    from src.services.database import StateChangeRepeating
    from src.services.database import repeating_schedule

    repeating_schedule.remove()

    now = datetime.datetime(2017, 1, 2, 0)
    StateChangeRepeating(10 * 60 ** 2, 10, 100, False).save()
    StateChangeRepeating(10 * 60 ** 2 + 1, 10, 100, True).save()

    assert StateChangeRepeating.get_current(now).fan is True
    repeating_schedule.remove()

    now = datetime.datetime(2017, 1, 2, 0)
    StateChangeRepeating(7 * 24 * 60 ** 2 - 1, 10, 100, False).save()
    StateChangeRepeating(0, 10, 100, True).save()
    assert StateChangeRepeating.get_current(now).fan is True
    repeating_schedule.remove()

    now = datetime.datetime(2017, 1, 2, 1)
    StateChangeRepeating(7 * 24 * 60 ** 2 + 1, 10, 100, False).save()
    StateChangeRepeating(60*60+1, 10, 100, True).save()
    assert StateChangeRepeating.get_current(now).fan is False
    repeating_schedule.remove()

    now = datetime.datetime(2017, 1, 2, 0)
    StateChangeRepeating(7 * 24 * 60 ** 2, 10, 100, False).save()
    StateChangeRepeating(1, 10, 100, True).save()
    assert StateChangeRepeating.get_current(now).fan is False
    repeating_schedule.remove()


    id = StateChangeRepeating(1, 10, 100, True).save()

    to_remove = StateChangeRepeating.from_dictionary({
      "week_time": 1430,
      "state": {
        "heater_target": 20,
        "AC_target": 36,
        "fan": False
      },
      "_id": id
    })

    assert repeating_schedule.remove({"_id": to_remove.id})["n"] == 1


    print("repeating schedule passed")
Beispiel #2
0
    def tick(self, now):
        scheduled = StateChange.get_current(now)

        if scheduled is None:
            scheduled = StateChangeRepeating.get_current(now)

        self.set_AC_target(scheduled.AC_target)
        self.set_fan(scheduled.fan)
        self.set_heater_target(scheduled.heater_target)