Skip to content

Commit 296b502

Browse files
committed
feat: update gpio_list method to return a list of GPIO pins and handle errors
1 parent 8a158b9 commit 296b502

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/wokwi_client/client.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
# SPDX-License-Identifier: MIT
44

55
from pathlib import Path
6-
from typing import Any, Optional, Union
6+
from typing import Any, Optional, Union, cast
77

8+
from wokwi_client.exceptions import ProtocolError
89
from wokwi_client.framebuffer import (
910
compare_framebuffer_png,
1011
framebuffer_png_bytes,
@@ -251,9 +252,17 @@ async def listen_pin(self, part: str, pin: str, listen: bool = True) -> Response
251252
"""
252253
return await pin_listen(self._transport, part=part, pin=pin, listen=listen)
253254

254-
async def gpio_list(self) -> ResponseMessage:
255-
"""Get a list of all GPIO pins available in the simulation."""
256-
return await gpio_list(self._transport)
255+
async def gpio_list(self) -> list[str]:
256+
"""Get a list of all GPIO pins available in the simulation.
257+
258+
Returns:
259+
list[str]: Example: ["esp32:GPIO0", "esp32:GPIO1", ...]
260+
"""
261+
resp = await gpio_list(self._transport)
262+
pins_val: Any = resp.get("result", {}).get("pins")
263+
if not isinstance(pins_val, list) or not all(isinstance(p, str) for p in pins_val):
264+
raise ProtocolError("Malformed gpio:list response: expected result.pins: list[str]")
265+
return cast(list[str], pins_val)
257266

258267
async def set_control(
259268
self, part: str, control: str, value: Union[int, bool, float]

0 commit comments

Comments
 (0)