def testStandbyInDayMode(base_fixture, target_mockup_fixture): settings = Settings(base_fixture.testdata_path / "integration") settings.set(MOTION_SENSOR_ENABLED, True) settings.set(NIGHT_MODE_BEGIN, 22) settings.set(NIGHT_MODE_END, 5) settings.set(BRIGHTNESS, 70) settings.set(DAY_STANDBY_TIMEOUT, 10) energy_saver = None comps = ComponentRegistry(settings) disp = comps.display # day with freeze_time("2019-01-01 12:59:59"): energy_saver = comps.energy_saver time.sleep(energy_saver.INIT_WAIT_TIME) time.sleep(energy_saver.UPDATE_TIME + 1) assert energy_saver.night_mode_active == False assert disp.get_brightness() == STANDBY_BRIGHTNESS # switch to wake comps.motion_detection_sensor._motion_detected = 1 with freeze_time("2019-01-01 13:00:10"): time.sleep(energy_saver.UPDATE_TIME + 2) assert disp.get_brightness() == settings.get(BRIGHTNESS) time.sleep(10 - energy_saver.UPDATE_TIME) # switch to standby comps.motion_detection_sensor._motion_detected = 0 time.sleep(energy_saver.UPDATE_TIME * 2) assert disp.get_brightness() == STANDBY_BRIGHTNESS energy_saver.stop()
def testWakeUpFromNightMode(base_fixture, target_mockup_fixture): settings = Settings(base_fixture.testdata_path / "integration") settings.set(MOTION_SENSOR_ENABLED, True) settings.set(NIGHT_MODE_BEGIN, 22) settings.set(NIGHT_MODE_END, 5) settings.set(BRIGHTNESS, 70) settings.set(NIGHT_STANDBY_TIMEOUT, 10) energy_saver = None comps = ComponentRegistry(settings) disp = comps.display with freeze_time("2019-01-01 22:59:59"): energy_saver = ESaver(comps, settings) time.sleep(energy_saver.INIT_WAIT_TIME) time.sleep(energy_saver.UPDATE_TIME + 1) assert NIGHT_MODE_BRIGHTNESS == disp.get_brightness() assert energy_saver.night_mode_active == True # set sensor high comps.motion_detection_sensor._motion_detected = 1 time.sleep(energy_saver.UPDATE_TIME + 1) assert disp.get_brightness() == 70 - NIGHTMODE_WAKEUP_DELTA_BRIGHTNESS # set sensor low comps.motion_detection_sensor._motion_detected = 0 time.sleep(10 + 1) assert disp.get_brightness() == NIGHT_MODE_BRIGHTNESS energy_saver.stop()
def testEventScheduler(base_fixture, qtbot, target_mockup_fixture, monkeypatch): with freeze_time(datetime(2020, 12, 24, 22, 59, 45), tick=True) as frozen: settings = Settings(base_fixture.testdata_path / "integration") #settings.set(NIGHT_MODE_END, 0) settings.set(SOUND_ENABLED, True) comp_ctrl = ComponentController(settings) Logger().info("Start") comps = comp_ctrl.components comps.energy_saver wmu = WeatherMainUi(comp_ctrl, settings) from pytestqt.plugin import _qapp_instance config.qt_app = _qapp_instance qtbot.addWidget(wmu) #monkeypatch.setattr('apscheduler.triggers.date.datetime', frozen) ev = EventHandler(comps, settings) t = get_time_of_day() current_date_time = datetime.now() settings._logger.info(current_date_time) assert t ev.gui_background_update_sig = wmu.change_background_sig while not ev._scheduler: time.sleep(1) comps.motion_detection_sensor._motion_detected = 1 time.sleep(8) comps.motion_detection_sensor._motion_detected = 0 time.sleep(10) time.sleep(10) time.sleep(10) time.sleep(10)
def testComponentRegistryDefaultSensors(base_fixture): # disable every hw sensor settings = Settings(base_fixture.testdata_path / "integration") settings.set(DHT_22_PIN, 0) # settings.set() = 0 cr = ComponentRegistry(settings)
def testParser(base_fixture, target_mockup_fixture): settings = Settings(base_fixture.testdata_path / "integration") settings.set(SOUND_ENABLED, True) events = parse_event_file(base_fixture.testdata_path / "events" / "events.json") assert events assert events[0].name == "Daily Greeting" assert events[1].name == "Wakeup" temp_file = tempfile.gettempdir() + "/eventsTest.json" write_events_file(temp_file, events) with open(temp_file) as fp: events_read = json.load(fp) assert events_read.get("events")[0].get("name") == "Daily Greeting" assert events_read.get("events")[1].get("name") == "Wakeup"
def testNightModeEnter(base_fixture, target_mockup_fixture): settings = Settings(base_fixture.testdata_path / "integration") settings.set(MOTION_SENSOR_ENABLED, True) settings.set(NIGHT_MODE_BEGIN, 23) settings.set(NIGHT_MODE_END, 5) settings.set(BRIGHTNESS, 70) energy_saver = None comps = ComponentRegistry(settings) disp = comps.display # day with freeze_time("2019-01-01 22:59:59"): energy_saver = ESaver(comps, settings) time.sleep(energy_saver.INIT_WAIT_TIME) assert not energy_saver._update_thread is None assert not energy_saver.night_mode_active assert disp.get_brightness() == 70 time.sleep(energy_saver.UPDATE_TIME + 1) assert disp.get_brightness() == STANDBY_BRIGHTNESS assert not energy_saver.night_mode_active with freeze_time("2019-01-01 23:00:01"): time.sleep(2 * energy_saver.UPDATE_TIME + 1) assert energy_saver.night_mode_active assert disp.get_brightness() == NIGHT_MODE_BRIGHTNESS with freeze_time("2019-01-02 04:59:01"): time.sleep(energy_saver.UPDATE_TIME + 1) assert energy_saver.night_mode_active assert disp.get_brightness() == NIGHT_MODE_BRIGHTNESS energy_saver.stop()
def testOnSoundDisabled(base_fixture, capsys): settings = Settings(base_fixture.testdata_path / "integration") settings.set(SOUND_ENABLED, "en") comps = ComponentRegistry(settings) tts = TextToSpeach(comps, settings) tts.say("Text1", "en") tts.wait_for_tts() # we can implicitly check, if the Thread has been started by us assert "TTS" in tts._tts_thread.getName() # test that no warning was thrown captured = capsys.readouterr() assert "WARNING" not in captured.out assert "Sound: Cannot play sound" not in captured.out
def testComponentRestartWatchdog(base_fixture, target_mockup_fixture): # test, that a sensor revives after stopping it settings = Settings(base_fixture.testdata_path / "integration") settings.set(DHT_22_PIN, 15) comps = ComponentRegistry(settings) temp = comps.temp_sensor hum = comps.humidity_sensor assert temp comps.stop_component_instance(temp) time.sleep(1) assert not hasattr(comps._components, "DHT22") assert not hasattr(comps._components, "TempSensor") assert not hasattr(comps._components, "HumiditySensor") assert comps.temp_sensor assert comps.humidity_sensor assert comps._components["DHT22"]
def testDefaultComponentCreation(base_fixture, target_mockup_fixture): # test, that all components can be instantiated settings = Settings(base_fixture.testdata_path / "integration") settings.set(MOTION_SENSOR_ENABLED, True) settings.set(DHT_22_PIN, 15) settings.set(BME_280_ENABLED, True) comps = ComponentRegistry(settings) disp = comps.display assert disp temp = comps.temp_sensor assert temp mot = comps.motion_detection_sensor assert mot tts = comps.tts assert tts es = comps.energy_saver assert es weather_info = comps.weather_info assert weather_info au = comps.auto_updater assert au hum = comps.humidity_sensor assert hum ps = comps.pressure_sensor assert ps co2 = comps.co2_sensor assert co2 tvoc = comps.tvoc_sensor assert tvoc rt = comps.remote_temp_sensor assert rt ev = comps.event_handler assert ev
def testNoStandbyIfSensorIsDisabled(base_fixture): settings = Settings(base_fixture.testdata_path / "integration") settings.set(MOTION_SENSOR_ENABLED, False) settings.set(NIGHT_MODE_BEGIN, 23) settings.set(NIGHT_MODE_END, 5) settings.set(BRIGHTNESS, 70) energy_saver = None comps = ComponentRegistry(settings) disp = comps.display # night mode - no wakeup with freeze_time("2019-01-01 12:00:00"): # energy_saver needs to be initalized in freeze time, otherwise testing time will have an impact energy_saver = ESaver(comps, settings) time.sleep(energy_saver.INIT_WAIT_TIME) time.sleep(energy_saver.UPDATE_TIME + 1) assert disp.get_brightness() == settings.get(BRIGHTNESS) energy_saver.stop()