44
55import base64
66from pathlib import Path
7- from typing import Any , Optional , Union
7+ from typing import Any , Optional , Union , cast
88
99from wokwi_client .framebuffer import (
1010 read_framebuffer_png_bytes ,
1616from .control import set_control
1717from .event_queue import EventQueue
1818from .file_ops import download , upload , upload_file
19- from .pins import pin_listen , pin_read
20- from .protocol_types import EventMessage , ResponseMessage
19+ from .pins import PinReadMessage , pin_listen , pin_read
20+ from .protocol_types import EventMessage
2121from .serial import monitor_lines , write_serial
2222from .simulation import pause , restart , resume , start
2323from .transport import Transport
@@ -64,33 +64,25 @@ async def disconnect(self) -> None:
6464 """
6565 await self ._transport .close ()
6666
67- async def upload (self , name : str , content : bytes ) -> ResponseMessage :
67+ async def upload (self , name : str , content : bytes ) -> None :
6868 """
6969 Upload a file to the simulator from bytes content.
7070
7171 Args:
7272 name: The name to use for the uploaded file.
7373 content: The file content as bytes.
74-
75- Returns:
76- The response message from the server.
7774 """
78- return await upload (self ._transport , name , content )
75+ await upload (self ._transport , name , content )
7976
80- async def upload_file (
81- self , filename : str , local_path : Optional [Path ] = None
82- ) -> ResponseMessage :
77+ async def upload_file (self , filename : str , local_path : Optional [Path ] = None ) -> None :
8378 """
8479 Upload a local file to the simulator.
8580
8681 Args:
8782 filename: The name to use for the uploaded file.
8883 local_path: Optional path to the local file. If not provided, uses filename as the path.
89-
90- Returns:
91- The response message from the server.
9284 """
93- return await upload_file (self ._transport , filename , local_path )
85+ await upload_file (self ._transport , filename , local_path )
9486
9587 async def download (self , name : str ) -> bytes :
9688 """
@@ -126,7 +118,7 @@ async def start_simulation(
126118 elf : Optional [str ] = None ,
127119 pause : bool = False ,
128120 chips : list [str ] = [],
129- ) -> ResponseMessage :
121+ ) -> None :
130122 """
131123 Start a new simulation with the given parameters.
132124
@@ -149,38 +141,29 @@ async def start_simulation(
149141 elf: The ELF file filename (optional).
150142 pause: Whether to start the simulation paused (default: False).
151143 chips: List of custom chips to load into the simulation (default: empty list).
152-
153- Returns:
154- The response message from the server.
155144 """
156- return await start (
145+ await start (
157146 self ._transport ,
158147 firmware = firmware ,
159148 elf = elf ,
160149 pause = pause ,
161150 chips = chips ,
162151 )
163152
164- async def pause_simulation (self ) -> ResponseMessage :
153+ async def pause_simulation (self ) -> None :
165154 """
166155 Pause the running simulation.
167-
168- Returns:
169- The response message from the server.
170156 """
171- return await pause (self ._transport )
157+ await pause (self ._transport )
172158
173- async def resume_simulation (self , pause_after : Optional [int ] = None ) -> ResponseMessage :
159+ async def resume_simulation (self , pause_after : Optional [int ] = None ) -> None :
174160 """
175161 Resume the simulation, optionally pausing after a given number of nanoseconds.
176162
177163 Args:
178164 pause_after: Number of nanoseconds to run before pausing again (optional).
179-
180- Returns:
181- The response message from the server.
182165 """
183- return await resume (self ._transport , pause_after )
166+ await resume (self ._transport , pause_after )
184167
185168 async def wait_until_simulation_time (self , seconds : float ) -> None :
186169 """
@@ -196,17 +179,14 @@ async def wait_until_simulation_time(self, seconds: float) -> None:
196179 await resume (self ._transport , int (remaining_nanos ))
197180 await self ._pause_queue .get ()
198181
199- async def restart_simulation (self , pause : bool = False ) -> ResponseMessage :
182+ async def restart_simulation (self , pause : bool = False ) -> None :
200183 """
201184 Restart the simulation, optionally starting paused.
202185
203186 Args:
204187 pause: Whether to start the simulation paused (default: False).
205-
206- Returns:
207- The response message from the server.
208188 """
209- return await restart (self ._transport , pause )
189+ await restart (self ._transport , pause )
210190
211191 async def serial_monitor_cat (self , decode_utf8 : bool = True , errors : str = "replace" ) -> None :
212192 """
@@ -234,16 +214,17 @@ async def serial_write(self, data: Union[bytes, str, list[int]]) -> None:
234214 def _on_pause (self , event : EventMessage ) -> None :
235215 self .last_pause_nanos = int (event ["nanos" ])
236216
237- async def read_pin (self , part : str , pin : str ) -> ResponseMessage :
217+ async def read_pin (self , part : str , pin : str ) -> PinReadMessage :
238218 """Read the current state of a pin.
239219
240220 Args:
241221 part: The part id (e.g. "uno").
242222 pin: The pin name (e.g. "A2").
243223 """
244- return await pin_read (self ._transport , part = part , pin = pin )
224+ pin_data = await pin_read (self ._transport , part = part , pin = pin )
225+ return cast (PinReadMessage , pin_data ["result" ])
245226
246- async def listen_pin (self , part : str , pin : str , listen : bool = True ) -> ResponseMessage :
227+ async def listen_pin (self , part : str , pin : str , listen : bool = True ) -> None :
247228 """Start or stop listening for changes on a pin.
248229
249230 When enabled, "pin:change" events will be delivered via the transport's
@@ -254,19 +235,17 @@ async def listen_pin(self, part: str, pin: str, listen: bool = True) -> Response
254235 pin: The pin name.
255236 listen: True to start listening, False to stop.
256237 """
257- return await pin_listen (self ._transport , part = part , pin = pin , listen = listen )
238+ await pin_listen (self ._transport , part = part , pin = pin , listen = listen )
258239
259- async def set_control (
260- self , part : str , control : str , value : Union [int , bool , float ]
261- ) -> ResponseMessage :
240+ async def set_control (self , part : str , control : str , value : Union [int , bool , float ]) -> None :
262241 """Set a control value (e.g. simulate button press).
263242
264243 Args:
265244 part: Part id (e.g. "btn1").
266245 control: Control name (e.g. "pressed").
267246 value: Control value to set (float).
268247 """
269- return await set_control (self ._transport , part = part , control = control , value = value )
248+ await set_control (self ._transport , part = part , control = control , value = value )
270249
271250 async def read_framebuffer_png_bytes (self , id : str ) -> bytes :
272251 """Return the current framebuffer as PNG bytes."""
0 commit comments