4
4
5
5
import base64
6
6
from pathlib import Path
7
- from typing import Any , Optional , Union
7
+ from typing import Any , Optional , Union , cast
8
8
9
9
from wokwi_client .framebuffer import (
10
10
read_framebuffer_png_bytes ,
16
16
from .control import set_control
17
17
from .event_queue import EventQueue
18
18
from .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
21
21
from .serial import monitor_lines , write_serial
22
22
from .simulation import pause , restart , resume , start
23
23
from .transport import Transport
@@ -64,33 +64,25 @@ async def disconnect(self) -> None:
64
64
"""
65
65
await self ._transport .close ()
66
66
67
- async def upload (self , name : str , content : bytes ) -> ResponseMessage :
67
+ async def upload (self , name : str , content : bytes ) -> None :
68
68
"""
69
69
Upload a file to the simulator from bytes content.
70
70
71
71
Args:
72
72
name: The name to use for the uploaded file.
73
73
content: The file content as bytes.
74
-
75
- Returns:
76
- The response message from the server.
77
74
"""
78
- return await upload (self ._transport , name , content )
75
+ await upload (self ._transport , name , content )
79
76
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 :
83
78
"""
84
79
Upload a local file to the simulator.
85
80
86
81
Args:
87
82
filename: The name to use for the uploaded file.
88
83
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.
92
84
"""
93
- return await upload_file (self ._transport , filename , local_path )
85
+ await upload_file (self ._transport , filename , local_path )
94
86
95
87
async def download (self , name : str ) -> bytes :
96
88
"""
@@ -126,7 +118,7 @@ async def start_simulation(
126
118
elf : Optional [str ] = None ,
127
119
pause : bool = False ,
128
120
chips : list [str ] = [],
129
- ) -> ResponseMessage :
121
+ ) -> None :
130
122
"""
131
123
Start a new simulation with the given parameters.
132
124
@@ -149,38 +141,29 @@ async def start_simulation(
149
141
elf: The ELF file filename (optional).
150
142
pause: Whether to start the simulation paused (default: False).
151
143
chips: List of custom chips to load into the simulation (default: empty list).
152
-
153
- Returns:
154
- The response message from the server.
155
144
"""
156
- return await start (
145
+ await start (
157
146
self ._transport ,
158
147
firmware = firmware ,
159
148
elf = elf ,
160
149
pause = pause ,
161
150
chips = chips ,
162
151
)
163
152
164
- async def pause_simulation (self ) -> ResponseMessage :
153
+ async def pause_simulation (self ) -> None :
165
154
"""
166
155
Pause the running simulation.
167
-
168
- Returns:
169
- The response message from the server.
170
156
"""
171
- return await pause (self ._transport )
157
+ await pause (self ._transport )
172
158
173
- async def resume_simulation (self , pause_after : Optional [int ] = None ) -> ResponseMessage :
159
+ async def resume_simulation (self , pause_after : Optional [int ] = None ) -> None :
174
160
"""
175
161
Resume the simulation, optionally pausing after a given number of nanoseconds.
176
162
177
163
Args:
178
164
pause_after: Number of nanoseconds to run before pausing again (optional).
179
-
180
- Returns:
181
- The response message from the server.
182
165
"""
183
- return await resume (self ._transport , pause_after )
166
+ await resume (self ._transport , pause_after )
184
167
185
168
async def wait_until_simulation_time (self , seconds : float ) -> None :
186
169
"""
@@ -196,17 +179,14 @@ async def wait_until_simulation_time(self, seconds: float) -> None:
196
179
await resume (self ._transport , int (remaining_nanos ))
197
180
await self ._pause_queue .get ()
198
181
199
- async def restart_simulation (self , pause : bool = False ) -> ResponseMessage :
182
+ async def restart_simulation (self , pause : bool = False ) -> None :
200
183
"""
201
184
Restart the simulation, optionally starting paused.
202
185
203
186
Args:
204
187
pause: Whether to start the simulation paused (default: False).
205
-
206
- Returns:
207
- The response message from the server.
208
188
"""
209
- return await restart (self ._transport , pause )
189
+ await restart (self ._transport , pause )
210
190
211
191
async def serial_monitor_cat (self , decode_utf8 : bool = True , errors : str = "replace" ) -> None :
212
192
"""
@@ -234,16 +214,17 @@ async def serial_write(self, data: Union[bytes, str, list[int]]) -> None:
234
214
def _on_pause (self , event : EventMessage ) -> None :
235
215
self .last_pause_nanos = int (event ["nanos" ])
236
216
237
- async def read_pin (self , part : str , pin : str ) -> ResponseMessage :
217
+ async def read_pin (self , part : str , pin : str ) -> PinReadMessage :
238
218
"""Read the current state of a pin.
239
219
240
220
Args:
241
221
part: The part id (e.g. "uno").
242
222
pin: The pin name (e.g. "A2").
243
223
"""
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" ])
245
226
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 :
247
228
"""Start or stop listening for changes on a pin.
248
229
249
230
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
254
235
pin: The pin name.
255
236
listen: True to start listening, False to stop.
256
237
"""
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 )
258
239
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 :
262
241
"""Set a control value (e.g. simulate button press).
263
242
264
243
Args:
265
244
part: Part id (e.g. "btn1").
266
245
control: Control name (e.g. "pressed").
267
246
value: Control value to set (float).
268
247
"""
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 )
270
249
271
250
async def read_framebuffer_png_bytes (self , id : str ) -> bytes :
272
251
"""Return the current framebuffer as PNG bytes."""
0 commit comments