pybricks 4.1.0b1__tar.gz → 4.1.0b2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/PKG-INFO +2 -1
  2. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/pyproject.toml +1 -1
  3. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/ev3devices.py +1 -36
  4. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/hubs.py +20 -0
  5. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/messaging.py +199 -0
  6. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/AUTHORS.md +0 -0
  7. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/LICENSE +0 -0
  8. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/README.rst +0 -0
  9. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/micropython/__init__.py +0 -0
  10. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/micropython/py.typed +0 -0
  11. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/__init__.py +0 -0
  12. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/_common.py +0 -0
  13. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/iodevices.py +0 -0
  14. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/nxtdevices.py +0 -0
  15. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/parameters.py +0 -0
  16. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/pupdevices.py +0 -0
  17. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/py.typed +0 -0
  18. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/robotics.py +0 -0
  19. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/pybricks/tools.py +0 -0
  20. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/uerrno/__init__.py +0 -0
  21. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/uerrno/py.typed +0 -0
  22. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/uio/__init__.py +0 -0
  23. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/uio/py.typed +0 -0
  24. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/ujson/__init__.py +0 -0
  25. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/umath/__init__.py +0 -0
  26. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/umath/py.typed +0 -0
  27. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/urandom/__init__.py +0 -0
  28. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/urandom/py.typed +0 -0
  29. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/uselect/__init__.py +0 -0
  30. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/uselect/py.typed +0 -0
  31. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/ustruct/__init__.py +0 -0
  32. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/usys/__init__.py +0 -0
  33. {pybricks-4.1.0b1 → pybricks-4.1.0b2}/src/usys/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybricks
3
- Version: 4.1.0b1
3
+ Version: 4.1.0b2
4
4
  Summary: Documentation and user-API stubs for Pybricks MicroPython
5
5
  License: MIT
6
6
  License-File: AUTHORS.md
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
18
19
  Classifier: Programming Language :: Python :: Implementation :: MicroPython
19
20
  Project-URL: Documentation, https://docs.pybricks.com
20
21
  Project-URL: Homepage, https://pybricks.com
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pybricks"
3
- version = "4.1.0b1"
3
+ version = "4.1.0b2"
4
4
  description = "Documentation and user-API stubs for Pybricks MicroPython"
5
5
  authors = ["The Pybricks Authors <team@pybricks.com>"]
6
6
  maintainers = ["Laurens Valk <laurens@pybricks.com>", "David Lechner <david@pybricks.com>" ]
@@ -13,7 +13,6 @@ from .parameters import Direction
13
13
  if TYPE_CHECKING:
14
14
  from ._common import (
15
15
  MaybeAwaitableBool,
16
- MaybeAwaitableColor,
17
16
  MaybeAwaitableInt,
18
17
  MaybeAwaitableSet,
19
18
  MaybeAwaitableTuple,
@@ -46,7 +45,7 @@ class TouchSensor:
46
45
  """
47
46
 
48
47
 
49
- class ColorSensor:
48
+ class ColorSensor(_common.CommonColorSensor):
50
49
  """LEGO® MINDSTORMS® EV3 Color Sensor."""
51
50
 
52
51
  def __init__(self, port: Port):
@@ -56,39 +55,6 @@ class ColorSensor:
56
55
  port (Port): Port to which the sensor is connected.
57
56
  """
58
57
 
59
- def color(self) -> MaybeAwaitableColor:
60
- """color() -> Color
61
-
62
- Measures the color of a surface.
63
-
64
- Returns:
65
- ``Color.BLACK``, ``Color.BLUE``, ``Color.GREEN``,
66
- ``Color.YELLOW``, ``Color.RED``, ``Color.WHITE``, ``Color.BROWN``,
67
- or ``Color.NONE`` if no color is detected.
68
-
69
- """
70
-
71
- def ambient(self) -> MaybeAwaitableInt:
72
- """ambient() -> int: %
73
-
74
- Measures the ambient light intensity.
75
-
76
- Returns:
77
- Ambient light intensity, ranging from 0% (dark)
78
- to 100% (bright).
79
- """
80
-
81
- def reflection(self) -> MaybeAwaitableInt:
82
- """reflection() -> int: %
83
-
84
- Measures how much a surface reflects the light emitted by the
85
- sensor.
86
-
87
- Returns:
88
- Measured reflection, ranging from 0% (no reflection) to
89
- 100% (high reflection).
90
- """
91
-
92
58
  def rgb(self) -> MaybeAwaitableTuple[int, int, int]:
93
59
  """rgb() -> tuple[int, int, int]
94
60
 
@@ -266,7 +232,6 @@ if TYPE_CHECKING:
266
232
  del Button
267
233
  del Direction
268
234
  del MaybeAwaitableBool
269
- del MaybeAwaitableColor
270
235
  del MaybeAwaitableInt
271
236
  del MaybeAwaitableSet
272
237
  del MaybeAwaitableTuple
@@ -31,6 +31,26 @@ class EV3Brick:
31
31
  speaker = _common.Speaker()
32
32
  battery = _common.Battery()
33
33
  light = _common.ColorLight()
34
+ system = _common.System()
35
+
36
+
37
+ class NXTBrick:
38
+ """LEGO® MINDSTORMS® NXT Brick."""
39
+
40
+ # These class attributes are here for auto-documentation only.
41
+ # In reality, they are instance attributes created by __init__.
42
+ buttons = _common.Keypad(
43
+ [
44
+ _Button.LEFT,
45
+ _Button.RIGHT,
46
+ _Button.CENTER,
47
+ _Button.DOWN,
48
+ ]
49
+ )
50
+ screen = _Image("_screen_")
51
+ speaker = _common.Speaker()
52
+ battery = _common.Battery()
53
+ system = _common.System()
34
54
 
35
55
 
36
56
  class MoveHub:
@@ -146,6 +146,205 @@ class BLERadio:
146
146
  """
147
147
 
148
148
 
149
+ class HubNetwork:
150
+ """
151
+ Send and receive messages between supported hubs using Bluetooth.
152
+
153
+ Create this object in every program that takes part in the network. One
154
+ hub, called the *manager*, then connects to others identified by their
155
+ address. For example: :meth:`connect('00:16:53:12:34:56') <connect>`.
156
+ After that, all hubs are equal: each one can send messages to any other
157
+ brick.
158
+
159
+ You can find the address of each hub in the EV3 settings menu, or print it
160
+ with the :meth:`address` method. Connections are preserved when you
161
+ restart a program.
162
+
163
+ The protocol ensures that messages get delivered. But they will only be
164
+ seen in your program if there is enough room. The manager takes care of
165
+ relaying messages in the background, which only works while the manager
166
+ program is still running.
167
+
168
+ .. versionadded:: 4.1
169
+ """
170
+
171
+ def __init__(self, inbox_size: int = 1024):
172
+ """HubNetwork(inbox_size=1024)
173
+
174
+ Arguments:
175
+ inbox_size (int): How many bytes of messages to store for each
176
+ brick that sends them.
177
+
178
+ Raises:
179
+ RuntimeError: If a ``HubNetwork`` object already exists, or if
180
+ this is used after multitasking has started.
181
+ OSError: If this brick has no working Bluetooth.
182
+ ValueError: If ``inbox_size`` is too small to hold one message.
183
+ """
184
+
185
+ def address(self) -> str:
186
+ """address() -> str
187
+
188
+ Gets the Bluetooth address of this brick.
189
+
190
+ This is the same address that is shown on the brick's screen. You can
191
+ print it to find out which address to type in the programs of the
192
+ other bricks.
193
+
194
+ Returns:
195
+ The address of this brick, such as ``'00:16:53:AB:CD:EF'``. The
196
+ letters are always uppercase.
197
+ """
198
+ return ""
199
+
200
+ def connect(self, address: str) -> MaybeAwaitable:
201
+ """connect(address)
202
+
203
+ Connects to one other hub (EV3 Brick) to set up the network.
204
+
205
+ Only one hub in the network does this. That hub is called the manager.
206
+ The other hubs don't have to run a program yet. They just won't
207
+ receive messages until their programs run.
208
+
209
+ Connecting is slow. It takes up to about fifteen seconds per brick,
210
+ and it does not always work on the first try, so it tries again a few
211
+ times before it gives up. This is why you normally do this at the
212
+ start of your program.
213
+
214
+ A brick that is already connected is ready right away, so it is safe
215
+ to use this again later. This makes the second run very quick to start.
216
+
217
+ Arguments:
218
+ address (str): The Bluetooth address of the brick to connect to,
219
+ such as ``'00:16:53:12:34:56'``. You can connect to up to
220
+ seven other bricks.
221
+
222
+ Raises:
223
+ OSError: If the brick could not be reached. ValueError: If
224
+ ``address`` is not a valid Bluetooth address, or if it is the
225
+ address of this brick.
226
+ """
227
+
228
+ def is_connected(self, address: str | None = None) -> bool:
229
+ """
230
+ is_connected() -> bool
231
+ is_connected(address) -> bool
232
+
233
+ Checks whether a brick has joined the network.
234
+
235
+ This is useful on the bricks that wait. They can keep checking
236
+ ``is_connected()`` until the manager brick has reached them, instead
237
+ of guessing how long the network takes to set up.
238
+
239
+ Only the manager brick can use the ``address`` argument to check
240
+ individual bricks.
241
+
242
+ Arguments:
243
+ address (str): The Bluetooth address of the hub to check.
244
+
245
+ Returns:
246
+ ``True`` if the hub has joined the network, ``False`` if not. If
247
+ no address is given, it is ``True`` if any hub is connected.
248
+
249
+ Raises:
250
+ ValueError: If ``address`` is not a valid Bluetooth address.
251
+ """
252
+ return False
253
+
254
+ def send(
255
+ self,
256
+ data: bool
257
+ | float
258
+ | str
259
+ | bytes
260
+ | None
261
+ | tuple[bool | int | float | str | bytes | None, ...],
262
+ address: str | None = None,
263
+ ) -> MaybeAwaitable:
264
+ """
265
+ send(data) send(data, address)
266
+
267
+ Sends a message to all hubs on the network, or to one specific hub.
268
+
269
+ A message is one object, or a tuple of objects. An object may be of
270
+ type ``int``, ``float``, ``str``, ``bytes``, ``True``, ``False``, or
271
+ ``None``. The brick that receives it gets the same objects back, so
272
+ sending ``(60, "left")`` arrives as ``(60, "left")``.
273
+
274
+ A message that is only ``bytes`` is sent just as it is, which is what
275
+ you want if you build your own messages. Such a message can hold 255
276
+ bytes. Every other message also carries a short description of the
277
+ objects in it, so a little less fits: ``True``, ``False`` and ``None``
278
+ take 2 bytes each, ``int`` and ``float`` take 5 bytes each, and
279
+ ``str`` and ``bytes`` take the number of bytes in them plus 2 to 4.
280
+ One message holds up to 32 objects.
281
+
282
+ Messages from this brick to one other brick arrive in the order that
283
+ you sent them.
284
+
285
+ Arguments:
286
+ data: The message to send.
287
+ address (str): The Bluetooth address of
288
+ the brick to send to. Leave out to send to every other brick
289
+ on the network. A brick never receives its own messages.
290
+
291
+ Raises:
292
+ ValueError: If ``address`` is not a valid Bluetooth address, or if
293
+ the message is too big to send.
294
+ TypeError: If the message holds an object that cannot be sent.
295
+ """
296
+
297
+ def inbox(
298
+ self, latest: bool = False
299
+ ) -> tuple[
300
+ tuple[
301
+ str,
302
+ bool
303
+ | int
304
+ | float
305
+ | str
306
+ | bytes
307
+ | None
308
+ | tuple[bool | int | float | str | bytes | None, ...],
309
+ ],
310
+ ...,
311
+ ]:
312
+ """inbox(latest=False) -> tuple
313
+
314
+ Gets the messages that have arrived since you last read them.
315
+
316
+ This never waits. If nothing has arrived, you get an empty result, so
317
+ a ``for`` loop over it simply does nothing. Reading removes the messages from this brick's memory, so each message
318
+ is given to you only once.
319
+
320
+ Every brick that sends to you gets an inbox of its own internally.
321
+ When one brick sends more than fits in its inbox, its oldest message
322
+ is dropped. A brick that sends all the time cannot push another
323
+ brick's messages out.
324
+
325
+ A program never receives messages that were sent before it started.
326
+ Messages are given to you in the order that they arrived, no matter
327
+ which brick sent them.
328
+
329
+ Arguments:
330
+ latest (bool): Choose ``True`` to keep only the newest message
331
+ from each brick and throw the older ones away. This is what
332
+ you want when a brick keeps sending you its latest value, such
333
+ as a sensor reading, and only the newest one is of any use.
334
+
335
+ Returns:
336
+ A tuple of ``(address, data)`` pairs, where ``address`` is the
337
+ Bluetooth address of the brick that sent the message, and ``data``
338
+ is the message in the same form as it was sent. With ``latest``,
339
+ there is at most one pair per brick.
340
+
341
+ Raises:
342
+ ValueError: If a message does not match the description it carries
343
+ with it, which means that it was damaged on the way.
344
+ """
345
+ return ()
346
+
347
+
149
348
  class Connection:
150
349
  @abstractmethod
151
350
  def read_from_mailbox(self, name: str) -> bytes: ...
File without changes
File without changes
File without changes
File without changes
File without changes