50 rivejä
1.4 KiB
Python
50 rivejä
1.4 KiB
Python
from module import mqtt_test_client, init_state, state_change_by_mqtt
|
|
from devices import silvercrest_powerplug as test_device
|
|
from devices.base import warning
|
|
from mqtt import mqtt_client
|
|
import pytest
|
|
import time
|
|
|
|
DUT_CLIENT_ID = "__%s__" % __name__
|
|
TOPIC = "__test__/%s" % __name__
|
|
#
|
|
MQTT_SIGNAL_TIME = 0.2
|
|
|
|
|
|
ALL_STATE_KEYS = ["state"]
|
|
BOOL_KEYS = ["state"]
|
|
|
|
|
|
@pytest.fixture
|
|
def this_device():
|
|
mc = mqtt_client(DUT_CLIENT_ID, 'localhost')
|
|
return test_device(mc, TOPIC)
|
|
|
|
|
|
def test_initial_states(this_device: test_device):
|
|
# test all initial values
|
|
init_state(ALL_STATE_KEYS, this_device)
|
|
|
|
|
|
def test_state_change_by_mqtt(this_device: test_device):
|
|
def state_data(key):
|
|
if key in BOOL_KEYS:
|
|
return (True, False)
|
|
else:
|
|
raise IndexError("No return value defined for key %s" % key)
|
|
|
|
def mqtt_data(key):
|
|
if key in BOOL_KEYS:
|
|
return ('ON', 'OFF')
|
|
else:
|
|
return state_data(key)
|
|
|
|
# test state changes
|
|
tm_warning = state_change_by_mqtt(ALL_STATE_KEYS, 2, mqtt_test_client, TOPIC, this_device,
|
|
mqtt_data, state_data, None, MQTT_SIGNAL_TIME)
|
|
|
|
|
|
def test_specific_get_functions(this_device: test_device):
|
|
assert this_device.linkquality == this_device.get(this_device.KEY_LINKQUALITY)
|
|
assert this_device.output_0 == this_device.get(this_device.KEY_OUTPUT_0)
|