From 9457488fa702a44f582104ccb841397954cf8929 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Wed, 30 Apr 2025 16:04:07 -0500 Subject: [PATCH 1/2] Updated Sammi API Fixed delete_variable(), made button_id optional. Fixed incorrect api_path string. --- addons/sammi/lib/sammi_api.gd | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/sammi/lib/sammi_api.gd b/addons/sammi/lib/sammi_api.gd index dbd35c6..340db5c 100644 --- a/addons/sammi/lib/sammi_api.gd +++ b/addons/sammi/lib/sammi_api.gd @@ -74,13 +74,16 @@ func set_variable(name: String, value: Variant, button_id: String = "") -> bool: last_error_description = response.error_message return false -func delete_variable(name: String, button_id) -> bool: - var api_path: String = "/api" % name +func delete_variable(name: String, button_id: String = "") -> bool: + var api_path: String = "/api" var req: Dictionary = { "request": "deleteVariable", - "name": name, - "buttonID": button_id + "name": name } + + if button_id != "": + req["buttonID"] = button_id + client.request(SammiClient.Method.POST, api_path, JSON.stringify(req)) var response: SammiClient.SammiResponse = await client.request_completed if response.code == 200: From 4f949a723931a256fd42e0af176eb58159ec6a77 Mon Sep 17 00:00:00 2001 From: Mario Steele Date: Wed, 30 Apr 2025 16:05:10 -0500 Subject: [PATCH 2/2] Updated SammiClient Fixed missing method being not set. Removed State.CLOSED check to disconnect and null the client variable Moved request_completed signal emit to after we clear headers, buffer disconnect client connection, and null out client variable. --- addons/sammi/lib/sammi_client.gd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/sammi/lib/sammi_client.gd b/addons/sammi/lib/sammi_client.gd index ac40636..db23a3a 100644 --- a/addons/sammi/lib/sammi_client.gd +++ b/addons/sammi/lib/sammi_client.gd @@ -43,6 +43,7 @@ func request(method: Method, api_path: String, body: String) -> void: self.query = api_path self.body = body + self.method = method self.client = StreamPeerTCP.new() self.client.connect_to_host(host, port) self.state = State.CONNECTING @@ -51,11 +52,6 @@ func _process(_delta: float) -> void: if not client: return - if state == State.CLOSED: - client.disconnect_from_host() - client = null - return - client.poll() if client.get_status() == StreamPeerTCP.Status.STATUS_CONNECTED and state == State.CONNECTING: state = State.REQUESTING @@ -130,8 +126,12 @@ func _read_response() -> void: buffer.append_array(chunk[1]) else: response = SammiResponse.new(headers, buffer, query) - request_completed.emit(response) state = State.CLOSED + headers = [] + buffer = [] + client.disconnect_from_host() + client = null + request_completed.emit(response) class SammiResponse: