|
6 | 6 | from pathlib import Path |
7 | 7 | from typing import Any, Optional, Union, cast |
8 | 8 |
|
9 | | -from wokwi_client.framebuffer import ( |
10 | | - read_framebuffer_png_bytes, |
11 | | - save_framebuffer_png, |
12 | | -) |
13 | | - |
14 | 9 | from .__version__ import get_version |
15 | 10 | from .constants import DEFAULT_WS_URL |
16 | 11 | from .control import set_control |
17 | 12 | from .event_queue import EventQueue |
| 13 | +from .exceptions import ProtocolError |
18 | 14 | from .file_ops import download, upload, upload_file |
19 | | -from .pins import PinReadMessage, pin_listen, pin_read |
| 15 | +from .framebuffer import ( |
| 16 | + read_framebuffer_png_bytes, |
| 17 | + save_framebuffer_png, |
| 18 | +) |
| 19 | +from .pins import PinReadMessage, gpio_list, pin_listen, pin_read |
20 | 20 | from .protocol_types import EventMessage |
21 | 21 | from .serial import monitor_lines, write_serial |
22 | 22 | from .simulation import pause, restart, resume, start |
@@ -237,6 +237,18 @@ async def listen_pin(self, part: str, pin: str, listen: bool = True) -> None: |
237 | 237 | """ |
238 | 238 | await pin_listen(self._transport, part=part, pin=pin, listen=listen) |
239 | 239 |
|
| 240 | + async def gpio_list(self) -> list[str]: |
| 241 | + """Get a list of all GPIO pins available in the simulation. |
| 242 | +
|
| 243 | + Returns: |
| 244 | + list[str]: Example: ["esp32:GPIO0", "esp32:GPIO1", ...] |
| 245 | + """ |
| 246 | + resp = await gpio_list(self._transport) |
| 247 | + pins_val: Any = resp.get("result", {}).get("pins") |
| 248 | + if not isinstance(pins_val, list) or not all(isinstance(p, str) for p in pins_val): |
| 249 | + raise ProtocolError("Malformed gpio:list response: expected result.pins: list[str]") |
| 250 | + return cast(list[str], pins_val) |
| 251 | + |
240 | 252 | async def set_control(self, part: str, control: str, value: Union[int, bool, float]) -> None: |
241 | 253 | """Set a control value (e.g. simulate button press). |
242 | 254 |
|
|
0 commit comments