Example #1
0
def remove_schedule():
    to_remove = StateChangeRepeating.from_dictionary(request.get_json(force=True))
    result = repeating_schedule.remove({"_id": to_remove.id})
    return Response(json.dumps({"data": result}, default=json_util.default), mimetype='application/json')
Example #2
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")