From 1e076c1f15a4d84243b4c22d50996fc50a59d8b7 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Sat, 22 Jul 2023 15:30:59 -0700 Subject: [PATCH] Fix ReadWriteClient.get_message() result type (#119) This method was previously returning a JSON-encoded string value representing the rows. We instead want to decode that string and return a full `Rows` value (list of lists). --- tests/test_clients.py | 2 +- vesta/clients.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_clients.py b/tests/test_clients.py index a2949b9..0cb3cd6 100644 --- a/tests/test_clients.py +++ b/tests/test_clients.py @@ -178,7 +178,7 @@ def test_headers(self): def test_read_message(self, rw_client: ReadWriteClient, respx_mock: MockRouter): chars = [[0] * COLS] * ROWS respx_mock.get("https://rw.vestaboard.com/").respond( - json={"currentMessage": {"layout": chars}}, + json={"currentMessage": {"layout": json.dumps(chars)}}, ) message = rw_client.read_message() assert message == chars diff --git a/vesta/clients.py b/vesta/clients.py index d8f46e5..081a848 100644 --- a/vesta/clients.py +++ b/vesta/clients.py @@ -248,9 +248,12 @@ def read_message(self) -> Optional[Rows]: r = self.http.get("") r.raise_for_status() try: - return r.json().get("currentMessage", {}).get("layout") + layout = r.json().get("currentMessage", {}).get("layout") except json.JSONDecodeError: return None + if layout: + return json.loads(layout) + return None def write_message(self, message: Rows) -> bool: """Write a message to the Vestaboard.