From f55f62a60cabc526644b85d9e7ed1666df9e7c62 Mon Sep 17 00:00:00 2001 From: mkmer Date: Tue, 19 Sep 2023 12:45:25 +0000 Subject: [PATCH] Fix "complete" with "bad" code --- .vscode/settings.json | 4 ++++ blinkpy/api.py | 4 ++-- tests/test_api.py | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..e137fadb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true +} \ No newline at end of file diff --git a/blinkpy/api.py b/blinkpy/api.py index 4d01c08f..38ea917c 100644 --- a/blinkpy/api.py +++ b/blinkpy/api.py @@ -501,8 +501,8 @@ async def wait_for_command(blink, json_data: dict) -> bool: _LOGGER.debug("Making GET request waiting for command") status = await request_command_status(blink, network_id, command_id) _LOGGER.debug("command status %s", status) - if status.get("complete"): - return True if status.get("status_code", 0) != 908: return False + if status.get("complete"): + return True await sleep(COMMAND_POLL_TIME) diff --git a/tests/test_api.py b/tests/test_api.py index 197c0885..1c6e02d7 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -9,6 +9,7 @@ COMMAND_RESPONSE = {"network_id": "12345", "id": "54321"} COMMAND_COMPLETE = {"complete": True, "status_code": 908} +COMMAND_COMPLETE_BAD = {"complete": True, "status_code": 999} COMMAND_NOT_COMPLETE = {"complete": False, "status_code": 908} @@ -178,3 +179,7 @@ async def test_wait_for_command(self, mock_resp): mock_resp.side_effect = (COMMAND_NOT_COMPLETE, {}) response = await api.wait_for_command(self.blink, COMMAND_RESPONSE) self.assertFalse(response) + + mock_resp.side_effect = (COMMAND_COMPLETE_BAD, {}) + response = await api.wait_for_command(self.blink, COMMAND_RESPONSE) + self.assertFalse(response)