def test_Sensor(monkeypatch, setup_test): with freeze_time(parse("2000-01-01 00:00:00")) as fdt: global FDT FDT = fdt monkeypatch.setattr(time, 'sleep', sleepless) c = Camera(sw_cam=True) c.save_images = True c.light_sensor.freq = timedelta(minutes=20) c.light_sensor.max_age = timedelta(hours=1) c.configs(""" [location] city = "Brisbane" [camera] interval = 300 # test ON at first light, then off when dark (i.e. all day) on = 'light' off = 'dim' camera_inactive_action = 'WAIT' """) c.mode_button.value = AUTO reset_camera = deepcopy(c) # a copy of the camera after it starts run_until(c, fdt, tomorrow_at(12), reset_camera) run_until(c, fdt, today_at(18, 00), reset_camera) run_until(c, fdt, today_at(23, 59), reset_camera) run_until(c, fdt, tomorrow_at(9, 00), reset_camera) reset_camera.run(1) assert reset_camera.active_timer.light_sensor.level == LightLevel.LIGHT
def test_camera_inactive_action(monkeypatch, setup_test): with freeze_time(parse("2000-01-01 12:00:00")) as fdt: global FDT FDT = fdt monkeypatch.setattr(time, 'sleep', sleepless) c = Camera(sw_cam=True) c.mode_button.value = AUTO c.save_images = False c.configs(""" [camera] interval = 900 # 15 minutes on = 09:00:00 off = 13:00:00 camera_inactive_action = 'EXCEPTION' """) c._camera = FakePiCamera() c.mode_button.value = AUTO with pytest.raises(PowerOff): run_until(c, fdt, today_at(18)) c.configs(""" [camera] on = 09:00:00 off = 13:00:00 camera_inactive_action = 'WAIT' """) run_until(c, fdt, tomorrow_at(18)) # no raise
def test_SunCalc(monkeypatch, setup_test): # dawn: datetime.time(4, 28, 38, 892410) # sunrise:datetime.time(4, 55, 38, 480930) # noon: datetime.time(11, 50, 59) # sunset datetime.time(18, 46, 18, 926896) # dusk datetime.time(19, 13, 17, 159158) with freeze_time(parse("2000-01-01 00:00:00")) as fdt: global FDT FDT = fdt monkeypatch.setattr(time, 'sleep', sleepless) c = Camera(sw_cam=True) c.save_images = False c.configs(""" [camera] city = 'Brisbane' interval = 600 on = 'dawn' off = 'sunset' # (2000, 1, 1, 18, 46, 18, 926896, tzinfo=tzlocal()) camera_inactive_action = 'WAIT' """) c._camera = FakePiCamera() assert c.active_timer.active() is False run_until(c, fdt, today_at(4, 30)) assert c.active_timer.active() is True run_until(c, fdt, today_at(12, 30)) assert c.active_timer.active() is True run_until(c, fdt, today_at(18, 30)) assert c.active_timer.active() is True run_until(c, fdt, today_at(18, 40)) run_until(c, fdt, today_at(18, 50)) assert c.active_timer.active() is False run_until(c, fdt, tomorrow_at(8)) assert c.active_timer.active() is True
def test_camera_inactive_action_2(monkeypatch, setup_test): with freeze_time(parse("2000-01-01 12:00:00")) as fdt: global FDT FDT = fdt monkeypatch.setattr(time, 'sleep', sleepless) c = Camera(sw_cam=True) c.save_images = False c.configs(""" [camera] interval = 900 # 15 minutes on = 'dim' off = 'dark' camera_inactive_action = 'EXCEPTION' """) # with pytest.raises(PowerOff): run_until(c, fdt, today_at(14)) assert c.light_sensor.level == LightLevel.LIGHT assert c.active_timer.active() assert c.active_timer.camera_active()