Smarthome Functionen
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

test_silvercrest_powerplug.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from module import mqtt_test_client, init_state, state_change_by_mqtt
  2. from devices import silvercrest_powerplug as test_device
  3. from devices.base 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 = ["state"]
  12. BOOL_KEYS = ["state"]
  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. if key in BOOL_KEYS:
  23. return (True, False)
  24. else:
  25. raise IndexError("No return value defined for key %s" % key)
  26. def mqtt_data(key):
  27. if key in BOOL_KEYS:
  28. return ('ON', 'OFF')
  29. else:
  30. return state_data(key)
  31. # test state changes
  32. tm_warning = state_change_by_mqtt(ALL_STATE_KEYS, 2, mqtt_test_client, TOPIC, this_device,
  33. mqtt_data, state_data, None, MQTT_SIGNAL_TIME)
  34. def test_specific_get_functions(this_device: test_device):
  35. assert this_device.linkquality == this_device.get(this_device.KEY_LINKQUALITY)
  36. assert this_device.output_0 == this_device.get(this_device.KEY_OUTPUT_0)