Smarthome Functionen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_my_powerplug.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from module import mqtt_test_client, init_state, state_change_by_mqtt
  2. from devices import my_powerplug as test_device
  3. from devices import warning
  4. from mqtt import mqtt_client
  5. import pytest
  6. import time
  7. DUT_CLIENT_ID = "__%s__" % __name__
  8. TOPIC = "__test__/%s" % __name__
  9. #
  10. MQTT_SIGNAL_TIME = 0.2
  11. ALL_STATE_KEYS = ["output/1", "output/2", "output/3", "output/4", ]
  12. BOOL_KEYS = ALL_STATE_KEYS
  13. @pytest.fixture
  14. def this_device():
  15. mc = mqtt_client(DUT_CLIENT_ID, 'localhost')
  16. return test_device(mc, TOPIC)
  17. def test_initial_states(this_device: test_device):
  18. # test all initial values
  19. init_state(ALL_STATE_KEYS, this_device)
  20. def test_state_change_by_mqtt(this_device: test_device):
  21. def state_data(key):
  22. return (True, False)
  23. def mqtt_data(key):
  24. return state_data(key)
  25. # test state changes
  26. tm_warning = state_change_by_mqtt(ALL_STATE_KEYS, 2, mqtt_test_client, TOPIC, this_device,
  27. mqtt_data, state_data, None, MQTT_SIGNAL_TIME)
  28. def test_specific_get_functions(this_device: test_device):
  29. assert this_device.output_0 == this_device.get(this_device.KEY_OUTPUT_0)
  30. assert this_device.output_1 == this_device.get(this_device.KEY_OUTPUT_1)
  31. assert this_device.output_2 == this_device.get(this_device.KEY_OUTPUT_2)
  32. assert this_device.output_3 == this_device.get(this_device.KEY_OUTPUT_3)