def test_websocket_error(fake_home: Home, home_data): global ws_error_called def on_error(err): global ws_error_called ws_error_called = True fake_home.onWsError += on_error fake_home.enable_events() with no_ssl_verification(): fake_home._connection._restCallRequestCounter = 1 fake_home._restCall("ws/sleep", json.dumps({"seconds": 5})) assert ws_error_called # testing automatic reconnection time.sleep(5) # give the reconnection routine time to reconnect client_base_id = "00000000-0000-0000-0000-000000000000" client_changed = home_data["clients"][client_base_id].copy() client_changed["label"] = "CHANGED" send_event(fake_home, EventType.CLIENT_CHANGED, "client", client_changed) time.sleep(1) d = fake_home.search_client_by_id(client_base_id) assert d.label == "CHANGED" assert isinstance(d, Client) fake_home.disable_events()
def send_event(fake_home: Home, pushEventType: EventType, type: str, data): if type: event_data = { "events": {"0": {"pushEventType": str(pushEventType), type: data}} } else: event_data = {"events": {"0": {"pushEventType": str(pushEventType)}}} with no_ssl_verification(): fake_home._restCall("ws/send", json.dumps(event_data))
def test_home_unknown_types(fake_home: Home): with no_ssl_verification(): fake_home._restCall("fake/loadConfig", json.dumps({"file": "unknown_types.json"})) fake_home.get_current_state(clearConfig=True) group = fake_home.groups[0] assert type(group) == Group assert group.groupType == "DUMMY_GROUP" device = fake_home.devices[0] assert type(device) == Device assert device.deviceType == "DUMMY_DEVICE" funcHome = fake_home.functionalHomes[0] assert type(funcHome) == FunctionalHome assert funcHome.solution == "DUMMY_FUNCTIONAL_HOME"
def test_connection_timeout(fake_home: Home): with no_ssl_verification(): fake_home._connection._restCallRequestCounter = 2 fake_home._connection._restCallTimout = 1 result = fake_home._restCall("fake/timeout") assert result["errorCode"] == "TIMEOUT"