Skip to content

Commit

Permalink
Fix ReadWriteClient.get_message() result type (#119)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
jparise committed Jul 22, 2023
1 parent e131820 commit 1e076c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion vesta/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1e076c1

Please sign in to comment.