omnipython-desktop 0.8.1.dev4__tar.gz → 0.8.1.dev5__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 (89) hide show
  1. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/PKG-INFO +2 -2
  2. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/pyproject.toml +2 -2
  3. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/endpointkit/__init__.py +105 -9
  4. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/endpointkit/__init__.pyi +19 -2
  5. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/endpointkit/fake.py +21 -6
  6. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/endpointkit/fake.pyi +3 -0
  7. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/icons/__init__.py +1 -1
  8. omnipython_desktop-0.8.1.dev5/src/icons/_material.py +11 -0
  9. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/__init__.py +149 -19
  10. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/__init__.pyi +7 -0
  11. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/ble.py +146 -33
  12. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/ble.pyi +38 -1
  13. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/endpoints.py +15 -0
  14. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/linux.py +62 -17
  15. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/usb_host.py +28 -0
  16. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/webmidi.py +5 -1
  17. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/omnipython_desktop.egg-info/PKG-INFO +2 -2
  18. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/omnipython_desktop.egg-info/requires.txt +1 -1
  19. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/uwin32.py +5 -5
  20. omnipython_desktop-0.8.1.dev4/src/icons/_material.py +0 -11
  21. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/README.md +0 -0
  22. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/setup.cfg +0 -0
  23. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/_svgio_canvas.py +0 -0
  24. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/_svgio_colour.py +0 -0
  25. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/_svgio_compact.py +0 -0
  26. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/_svgio_resvg.py +0 -0
  27. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/__init__.py +0 -0
  28. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/active_sensing.py +0 -0
  29. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/channel_pressure.py +0 -0
  30. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/control_change.py +0 -0
  31. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/control_change_values.py +0 -0
  32. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/midi_continue.py +0 -0
  33. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/midi_message.py +0 -0
  34. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/midi_reset.py +0 -0
  35. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/mtc_quarter_frame.py +0 -0
  36. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/note_off.py +0 -0
  37. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/note_on.py +0 -0
  38. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/pitch_bend.py +0 -0
  39. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/polyphonic_key_pressure.py +0 -0
  40. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/program_change.py +0 -0
  41. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/start.py +0 -0
  42. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/stop.py +0 -0
  43. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/system_exclusive.py +0 -0
  44. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/adafruit_midi/timing_clock.py +0 -0
  45. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/board_config.py +0 -0
  46. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/board_peripherals.py +0 -0
  47. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/endpointkit/py.typed +0 -0
  48. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/frame_recorder-stubs/__init__.pyi +0 -0
  49. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/frame_recorder.py +0 -0
  50. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/hostnet-stubs/__init__.pyi +0 -0
  51. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/hostnet.py +0 -0
  52. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/icons/__init__.pyi +0 -0
  53. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/icons/_material.pyi +0 -0
  54. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/icons/gfx.py +0 -0
  55. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/icons/gfx.pyi +0 -0
  56. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/icons/lvgl.py +0 -0
  57. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/icons/lvgl.pyi +0 -0
  58. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/icons/py.typed +0 -0
  59. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/jpegio-stubs/__init__.pyi +0 -0
  60. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/jpegio.py +0 -0
  61. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/manifest.py +0 -0
  62. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/mdns-stubs/__init__.pyi +0 -0
  63. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/mdns.py +0 -0
  64. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/micropython.py +0 -0
  65. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/endpoints.pyi +0 -0
  66. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/linux.pyi +0 -0
  67. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/loopback.py +0 -0
  68. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/loopback.pyi +0 -0
  69. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/py.typed +0 -0
  70. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/uart.py +0 -0
  71. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/uart.pyi +0 -0
  72. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/usb_device.py +0 -0
  73. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/usb_device.pyi +0 -0
  74. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/usb_host.pyi +0 -0
  75. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/webmidi.pyi +0 -0
  76. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/windows.py +0 -0
  77. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/midiports/windows.pyi +0 -0
  78. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/omnipython_desktop.egg-info/SOURCES.txt +0 -0
  79. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/omnipython_desktop.egg-info/dependency_links.txt +0 -0
  80. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/omnipython_desktop.egg-info/top_level.txt +0 -0
  81. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/pngio-stubs/__init__.pyi +0 -0
  82. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/pngio.py +0 -0
  83. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/svgio-stubs/__init__.pyi +0 -0
  84. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/svgio.py +0 -0
  85. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/ttfio-stubs/__init__.pyi +0 -0
  86. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/ttfio.py +0 -0
  87. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/usdl2-stubs/__init__.pyi +0 -0
  88. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/usdl2.py +0 -0
  89. {omnipython_desktop-0.8.1.dev4 → omnipython_desktop-0.8.1.dev5}/src/uwin32-stubs/__init__.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: omnipython-desktop
3
- Version: 0.8.1.dev4
3
+ Version: 0.8.1.dev5
4
4
  Summary: Complete OmniPython desktop stack and board configuration
5
5
  Author: Brad Barnett
6
6
  License-Expression: MIT
@@ -8,7 +8,7 @@ Project-URL: Homepage, https://github.com/PyDevices/omnipython
8
8
  Project-URL: Repository, https://github.com/PyDevices/omnipython
9
9
  Requires-Python: >=3.9
10
10
  Description-Content-Type: text/markdown
11
- Requires-Dist: omnipython==0.8.1.dev4
11
+ Requires-Dist: omnipython==0.8.1.dev5
12
12
  Requires-Dist: zeroconf>=0.132
13
13
  Requires-Dist: Pillow>=9
14
14
  Requires-Dist: resvg-py>=0.5
@@ -4,14 +4,14 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "omnipython-desktop"
7
- version = "0.8.1.dev4"
7
+ version = "0.8.1.dev5"
8
8
  description = "Complete OmniPython desktop stack and board configuration"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
11
11
  license = "MIT"
12
12
  authors = [{ name = "Brad Barnett" }]
13
13
  dependencies = [
14
- "omnipython==0.8.1.dev4",
14
+ "omnipython==0.8.1.dev5",
15
15
  "zeroconf>=0.132",
16
16
  "Pillow>=9",
17
17
  "resvg-py>=0.5",
@@ -25,9 +25,11 @@ The five ideas
25
25
  --------------
26
26
  A **kind** names a role: ``audio.out``, ``audio.in``, ``midi.in``,
27
27
  ``midi.out``, ``net``, ``cast.target``, ``camera``, ``gamepad``, ``keys``,
28
- ``pointer``. Each says whether one endpoint is chosen at a time (a camera, a
28
+ ``pointer``, ``assistant``. Each says whether one endpoint is chosen at a time (a camera, a
29
29
  cast target, the default network) or many (MIDI inputs merge, audio can fan
30
- out). `add_kind` adds another without changing anything here.
30
+ out), and what a person calls it, with an icon, for a picker or a status bar
31
+ to show (`title`, `icon`). `add_kind` adds another without changing anything
32
+ here.
31
33
 
32
34
  A **provider** is one transport for one kind: I2S, USB audio or Bluetooth
33
35
  for ``audio.out``. The library that owns the transport registers it, so this
@@ -67,7 +69,7 @@ try:
67
69
  except ImportError:
68
70
  os = None
69
71
 
70
- __version__ = "0.0.1"
72
+ __version__ = "0.0.3"
71
73
 
72
74
  #: One endpoint of the kind is chosen at a time.
73
75
  ONE = 1
@@ -86,13 +88,44 @@ KINDS = {
86
88
  "gamepad": MANY,
87
89
  "keys": MANY,
88
90
  "pointer": MANY,
91
+ "assistant": ONE,
89
92
  }
90
93
 
94
+ #: What a person calls each kind, and its icon: a Material Symbols name, which
95
+ #: the ``icons`` package draws. `add_kind` adds to it.
96
+ NAMES = {
97
+ "audio.out": ("Audio out", "volume_up"),
98
+ "audio.in": ("Audio in", "mic"),
99
+ "midi.in": ("MIDI in", "piano"),
100
+ "midi.out": ("MIDI out", "music_note"),
101
+ "net": ("Network", "wifi"),
102
+ "cast.target": ("Cast to", "cast"),
103
+ "camera": ("Camera", "photo_camera"),
104
+ "gamepad": ("Gamepads", "sports_esports"),
105
+ "keys": ("Keyboards", "keyboard"),
106
+ "pointer": ("Pointers", "mouse"),
107
+ "assistant": ("Assistant", "smart_toy"),
108
+ }
109
+ #: The icon of a kind added with none.
110
+ OTHER_ICON = "cable"
111
+
112
+ # The kinds in the order they became known: a picker lists them this way.
113
+ # Written out, because a MicroPython dict keeps no order.
114
+ _ORDER = [
115
+ "audio.out", "audio.in", "midi.in", "midi.out", "net", "cast.target",
116
+ "camera", "gamepad", "keys", "pointer", "assistant",
117
+ ]
118
+
91
119
  AVAILABLE = "available"
92
120
  CONNECTED = "connected"
93
121
  NEEDS_PAIRING = "needs pairing"
94
122
  UNAVAILABLE = "unavailable"
95
123
 
124
+ #: What pairing or joining an endpoint asks a person for (`Endpoint.asks`):
125
+ #: a password (a Wi-Fi network) or a PIN (an older Bluetooth device).
126
+ PASSWORD = "password"
127
+ PIN = "pin"
128
+
96
129
  #: Subscription events: the list of a kind's endpoints changed.
97
130
  ENDPOINTS = "endpoints"
98
131
  #: An endpoint's state changed.
@@ -103,10 +136,13 @@ SELECTION = "selection"
103
136
  ERROR = "error"
104
137
 
105
138
 
106
- def add_kind(name, count=ONE):
139
+ def add_kind(name, count=ONE, title=None, icon=None):
107
140
  """Make a new kind known, choosing `ONE` or `MANY` endpoints at a time.
108
141
 
109
- Adding a kind that exists with the same count does nothing.
142
+ *title* is what a person calls it ("Storage"), and *icon* a Material
143
+ Symbols name ("sd_card"); a picker shows the kind's name and `OTHER_ICON`
144
+ without them. Adding a kind that exists with the same count changes
145
+ nothing but a title or icon given.
110
146
 
111
147
  Raises:
112
148
  ValueError: the kind exists with the other count.
@@ -114,6 +150,25 @@ def add_kind(name, count=ONE):
114
150
  if name in KINDS and KINDS[name] != count:
115
151
  raise ValueError("kind %r already chooses %s" % (name, "one" if KINDS[name] == ONE else "many"))
116
152
  KINDS[name] = count
153
+ if name not in _ORDER:
154
+ _ORDER.append(name)
155
+ old = NAMES.get(name, (name, OTHER_ICON))
156
+ NAMES[name] = (title or old[0], icon or old[1])
157
+
158
+
159
+ def kinds():
160
+ """Every kind known, in the order they became known: the built-in ones first."""
161
+ return list(_ORDER)
162
+
163
+
164
+ def title(kind):
165
+ """What a person calls *kind*: "Audio out" for ``audio.out``, or the kind's own name."""
166
+ return NAMES.get(kind, (kind, OTHER_ICON))[0]
167
+
168
+
169
+ def icon(kind):
170
+ """*kind*'s icon, a Material Symbols name; `OTHER_ICON` when it has none."""
171
+ return NAMES.get(kind, (kind, OTHER_ICON))[1]
117
172
 
118
173
 
119
174
  class Conflict(Exception):
@@ -148,9 +203,11 @@ class Endpoint:
148
203
  resources (tuple): the shared resources it takes when chosen; the
149
204
  provider's own unless the endpoint names others.
150
205
  error (str or None): why the provider last failed to start or stop it.
206
+ asks (str or None): what `Registry.pair` needs typed to pair or
207
+ join it, `PASSWORD` or `PIN`; None when pairing asks nothing.
151
208
  """
152
209
 
153
- def __init__(self, provider, local_id, label, state=AVAILABLE, caps=None, resources=None):
210
+ def __init__(self, provider, local_id, label, state=AVAILABLE, caps=None, resources=None, asks=None):
154
211
  self.provider = provider
155
212
  self.local_id = local_id
156
213
  self.id = "%s:%s" % (provider.name, local_id)
@@ -160,6 +217,7 @@ class Endpoint:
160
217
  self.caps = caps if caps is not None else {}
161
218
  self.resources = tuple(resources) if resources is not None else tuple(provider.resources)
162
219
  self.error = None
220
+ self.asks = asks
163
221
 
164
222
  def __repr__(self):
165
223
  return "<Endpoint %s %r %s>" % (self.id, self.label, self.state)
@@ -171,7 +229,9 @@ class Provider:
171
229
  Set ``kind``, ``name`` (unique on the device, the first part of every
172
230
  endpoint id) and ``resources``, and write `scan`. A transport whose
173
231
  finding is slow writes `poll` too, and one that must do something when
174
- an endpoint is chosen or let go writes `apply`.
232
+ an endpoint is chosen or let go writes `apply`. One whose endpoints
233
+ must be paired or joined first (Bluetooth, a Wi-Fi network) reports
234
+ them as `NEEDS_PAIRING` and writes `pair`.
175
235
  """
176
236
 
177
237
  kind = None
@@ -190,9 +250,9 @@ class Provider:
190
250
  if ":" in self.name:
191
251
  raise ValueError("a provider's name can't hold ':': %r" % self.name)
192
252
 
193
- def endpoint(self, local_id, label, state=AVAILABLE, caps=None, resources=None):
253
+ def endpoint(self, local_id, label, state=AVAILABLE, caps=None, resources=None, asks=None):
194
254
  """An `Endpoint` of this provider, for `scan` and `poll` to return."""
195
- return Endpoint(self, local_id, label, state, caps, resources)
255
+ return Endpoint(self, local_id, label, state, caps, resources, asks)
196
256
 
197
257
  def scan(self):
198
258
  """The endpoints known now, as a list. It must return quickly; start
@@ -210,6 +270,16 @@ class Provider:
210
270
  Raise to refuse; the registry records the message on the endpoint.
211
271
  """
212
272
 
273
+ def pair(self, endpoint, secret=None):
274
+ """Pair with or join *endpoint*, with the *secret* its ``asks`` named.
275
+
276
+ Keep the secret yourself if it's needed again; the registry never
277
+ stores it. Raise to refuse (a wrong password); the message is what
278
+ a person sees. Pairing that takes a while may start here and report
279
+ the endpoint's new state from `poll`.
280
+ """
281
+ raise ValueError("%s can't pair" % self.name)
282
+
213
283
  def stop(self):
214
284
  """Release whatever the provider holds; called by `Registry.unregister`."""
215
285
 
@@ -319,6 +389,30 @@ class Registry:
319
389
  return ep
320
390
  return None
321
391
 
392
+ def pair(self, endpoint_id, secret=None):
393
+ """Pair with or join the endpoint *endpoint_id* through its provider,
394
+ then scan that provider again; returns the endpoint.
395
+
396
+ *secret* is what the endpoint's ``asks`` names, typed by a person.
397
+ It goes to the provider and nowhere else. Pairing doesn't choose
398
+ the endpoint: `select` it after.
399
+
400
+ Raises:
401
+ ValueError: no such endpoint is found, or the provider refused
402
+ (a wrong password); the message says why.
403
+ """
404
+ ep = self.find(endpoint_id)
405
+ if ep is None:
406
+ raise ValueError("%s isn't found" % endpoint_id)
407
+ ep.provider.pair(ep, secret)
408
+ try:
409
+ found = ep.provider.scan()
410
+ except Exception as exc: # noqa: BLE001
411
+ _report("scan", ep.provider.name, exc)
412
+ else:
413
+ self._update(ep.provider, found)
414
+ return self.find(endpoint_id) or ep
415
+
322
416
  # -- choices ---------------------------------------------------------------
323
417
 
324
418
  def chosen(self, kind):
@@ -564,6 +658,7 @@ class Registry:
564
658
  prev.label = ep.label
565
659
  prev.caps = ep.caps
566
660
  prev.resources = ep.resources
661
+ prev.asks = ep.asks
567
662
  new.append(prev)
568
663
  if not list_changed:
569
664
  list_changed = [e.id for e in new] != [e.id for e in old]
@@ -648,6 +743,7 @@ unregister = registry.unregister
648
743
  providers = registry.providers
649
744
  poll = registry.poll
650
745
  refresh = registry.refresh
746
+ pair = registry.pair
651
747
  endpoints = registry.endpoints
652
748
  find = registry.find
653
749
  chosen = registry.chosen
@@ -10,10 +10,14 @@ __version__: str
10
10
  ONE: int
11
11
  MANY: int
12
12
  KINDS: dict[str, int]
13
+ NAMES: dict[str, tuple[str, str]]
14
+ OTHER_ICON: str
13
15
  AVAILABLE: str
14
16
  CONNECTED: str
15
17
  NEEDS_PAIRING: str
16
18
  UNAVAILABLE: str
19
+ PASSWORD: str
20
+ PIN: str
17
21
  ENDPOINTS: str
18
22
  STATE: str
19
23
  SELECTION: str
@@ -22,8 +26,14 @@ ERROR: str
22
26
  _Ids = str | Iterable[str] | None
23
27
  _Callback = Callable[[str, str], object]
24
28
 
25
- def add_kind(name: str, count: int = ...) -> None:
26
- """Make a new kind known, choosing `ONE` or `MANY` endpoints at a time."""
29
+ def add_kind(name: str, count: int = ..., title: str | None = None, icon: str | None = None) -> None:
30
+ """Make a new kind known, choosing `ONE` or `MANY` endpoints at a time, with what it's called and its icon."""
31
+ def kinds() -> list[str]:
32
+ """Every kind known, in the order they became known."""
33
+ def title(kind: str) -> str:
34
+ """What a person calls `kind`, or the kind's own name."""
35
+ def icon(kind: str) -> str:
36
+ """`kind`'s icon, a Material Symbols name; `OTHER_ICON` when it has none."""
27
37
 
28
38
  class Conflict(Exception):
29
39
  """A choice would stop endpoints that are using the same resources."""
@@ -45,6 +55,7 @@ class Endpoint:
45
55
  caps: dict[str, Any]
46
56
  resources: tuple[str, ...]
47
57
  error: str | None
58
+ asks: str | None
48
59
  def __init__(
49
60
  self,
50
61
  provider: Provider,
@@ -53,6 +64,7 @@ class Endpoint:
53
64
  state: str = ...,
54
65
  caps: dict[str, Any] | None = None,
55
66
  resources: Iterable[str] | None = None,
67
+ asks: str | None = None,
56
68
  ) -> None: ...
57
69
 
58
70
  class Provider:
@@ -69,6 +81,7 @@ class Provider:
69
81
  state: str = ...,
70
82
  caps: dict[str, Any] | None = None,
71
83
  resources: Iterable[str] | None = None,
84
+ asks: str | None = None,
72
85
  ) -> Endpoint:
73
86
  """An `Endpoint` of this provider, for `scan` and `poll` to return."""
74
87
  def scan(self) -> list[Endpoint]:
@@ -77,6 +90,8 @@ class Provider:
77
90
  """A new list of endpoints when something changed, or None."""
78
91
  def apply(self, endpoint: Endpoint, chosen: bool) -> None:
79
92
  """Start using *endpoint* when *chosen* is True, stop when False."""
93
+ def pair(self, endpoint: Endpoint, secret: str | None = None) -> None:
94
+ """Pair with or join *endpoint*; raise to refuse."""
80
95
  def stop(self) -> None:
81
96
  """Release whatever the provider holds."""
82
97
 
@@ -89,6 +104,7 @@ class Registry:
89
104
  def providers(self, kind: str | None = None) -> list[Provider]: ...
90
105
  def poll(self) -> bool: ...
91
106
  def refresh(self, kind: str | None = None) -> None: ...
107
+ def pair(self, endpoint_id: str, secret: str | None = None) -> Endpoint: ...
92
108
  def endpoints(self, kind: str) -> list[Endpoint]: ...
93
109
  def find(self, endpoint_id: str) -> Endpoint | None: ...
94
110
  def chosen(self, kind: str) -> list[str]: ...
@@ -110,6 +126,7 @@ def unregister(provider: Provider) -> None: ...
110
126
  def providers(kind: str | None = None) -> list[Provider]: ...
111
127
  def poll() -> bool: ...
112
128
  def refresh(kind: str | None = None) -> None: ...
129
+ def pair(endpoint_id: str, secret: str | None = None) -> Endpoint: ...
113
130
  def endpoints(kind: str) -> list[Endpoint]: ...
114
131
  def find(endpoint_id: str) -> Endpoint | None: ...
115
132
  def chosen(kind: str) -> list[str]: ...
@@ -37,18 +37,22 @@ class FakeProvider(endpointkit.Provider):
37
37
  delay (int): how many polls pass before the endpoints are found, to
38
38
  stand in for a slow scan. 0 finds them at once.
39
39
  fail (tuple): local ids whose start raises, to try error paths.
40
+ secrets (dict): ``{local_id: (asks, secret)}`` for endpoints that
41
+ ask for a password or a PIN to pair; `pair` refuses any other.
42
+ An endpoint that needs pairing and isn't here pairs with nothing typed.
40
43
 
41
44
  Attributes:
42
45
  started (list): local ids started and not stopped, in order.
43
- log (list): ``("start" or "stop", local_id)`` for every call.
46
+ log (list): ``("start", "stop" or "pair", local_id)`` for every call.
44
47
  """
45
48
 
46
- def __init__(self, kind, name, found=(), resources=(), delay=0, fail=()):
49
+ def __init__(self, kind, name, found=(), resources=(), delay=0, fail=(), secrets=None):
47
50
  endpointkit.Provider.__init__(self, kind, name, resources)
48
51
  self._want = [self._entry(e) for e in found]
49
52
  self._delay = delay
50
53
  self._dirty = False
51
54
  self.fail = list(fail)
55
+ self.secrets = dict(secrets or {})
52
56
  self.started = []
53
57
  self.log = []
54
58
 
@@ -58,7 +62,10 @@ class FakeProvider(endpointkit.Provider):
58
62
  return [e[0], e[1], e[2] if len(e) > 2 else endpointkit.AVAILABLE]
59
63
 
60
64
  def _list(self):
61
- return [self.endpoint(i, label, state) for i, label, state in self._want]
65
+ return [
66
+ self.endpoint(i, label, state, asks=self.secrets[i][0] if i in self.secrets else None)
67
+ for i, label, state in self._want
68
+ ]
62
69
 
63
70
  def scan(self):
64
71
  return [] if self._delay else self._list()
@@ -84,6 +91,13 @@ class FakeProvider(endpointkit.Provider):
84
91
  elif local in self.started:
85
92
  self.started.remove(local)
86
93
 
94
+ def pair(self, endpoint, secret=None):
95
+ local = endpoint.local_id
96
+ self.log.append(("pair", local))
97
+ if local in self.secrets and secret != self.secrets[local][1]:
98
+ raise ValueError("Wrong %s for %s" % (self.secrets[local][0], endpoint.label))
99
+ self.set_state(local, endpointkit.AVAILABLE)
100
+
87
101
  # -- changing what's found, reported on the next poll ------------------------
88
102
 
89
103
  def add(self, local_id, label, state=endpointkit.AVAILABLE):
@@ -113,8 +127,8 @@ def bench(registry=None, delay=2):
113
127
  polls to find their endpoints.
114
128
  """
115
129
  registry = registry or endpointkit.registry
116
- endpointkit.add_kind("espnow.peer", endpointkit.MANY)
117
- endpointkit.add_kind("thread.net", endpointkit.ONE)
130
+ endpointkit.add_kind("espnow.peer", endpointkit.MANY, "ESP-NOW peers", "hub")
131
+ endpointkit.add_kind("thread.net", endpointkit.ONE, "Thread", "lan")
118
132
  na, cn = endpointkit.NEEDS_PAIRING, endpointkit.CONNECTED
119
133
  fakes = [
120
134
  FakeProvider("audio.out", "i2s", [("0", "Headphone jack")], ("i2s.0",)),
@@ -123,7 +137,8 @@ def bench(registry=None, delay=2):
123
137
  FakeProvider("midi.in", "blemidi", [("pad", "BLE pad controller")], (), delay),
124
138
  FakeProvider("midi.in", "uart", [("1", "MIDI DIN in")], ("uart.1",)),
125
139
  FakeProvider("midi.out", "uartout", [("1", "MIDI DIN out")], ("uart.1",)),
126
- FakeProvider("net", "wlan", [("home", "Wi-Fi: home", cn)], ("radio.wifi",)),
140
+ FakeProvider("net", "wlan", [("home", "Wi-Fi: home", cn), ("cafe", "Wi-Fi: cafe", na)], ("radio.wifi",),
141
+ secrets={"cafe": (endpointkit.PASSWORD, "espresso")}),
127
142
  FakeProvider("net", "eth", [("0", "Ethernet")], ("eth.0",)),
128
143
  FakeProvider("net", "usbnet", [("phone", "Phone tethering")], ("usb.host",)),
129
144
  FakeProvider("net", "btpan", [("phone", "Phone over Bluetooth", na)], ("radio.bt",), delay),
@@ -11,6 +11,7 @@ class FakeProvider(endpointkit.Provider):
11
11
  """A provider that finds what it's told to."""
12
12
 
13
13
  fail: list[str]
14
+ secrets: dict[str, tuple[str, str]]
14
15
  started: list[str]
15
16
  log: list[tuple[str, str]]
16
17
  def __init__(
@@ -21,10 +22,12 @@ class FakeProvider(endpointkit.Provider):
21
22
  resources: Iterable[str] = (),
22
23
  delay: int = 0,
23
24
  fail: Iterable[str] = (),
25
+ secrets: dict[str, tuple[str, str]] | None = None,
24
26
  ) -> None: ...
25
27
  def scan(self) -> list[endpointkit.Endpoint]: ...
26
28
  def poll(self) -> list[endpointkit.Endpoint] | None: ...
27
29
  def apply(self, endpoint: endpointkit.Endpoint, chosen: bool) -> None: ...
30
+ def pair(self, endpoint: endpointkit.Endpoint, secret: str | None = None) -> None: ...
28
31
  def add(self, local_id: str, label: str, state: str = ...) -> None:
29
32
  """Find another endpoint."""
30
33
  def remove(self, local_id: str) -> None:
@@ -5,7 +5,7 @@
5
5
 
6
6
  ``mask("home", 20)`` gives the antialiased shape of an icon as 8-bit alpha,
7
7
  ``size * size`` bytes, drawn by `ttfio` from a cut-down Material Symbols font
8
- of 500 icons. Frozen into firmware, the font is read in place, so the icons
8
+ of 520 icons. Frozen into firmware, the font is read in place, so the icons
9
9
  cost flash, not RAM; each mask you ask for is drawn once and kept in a small
10
10
  cache. Draw a mask with `icons.gfx` in pygraphics or `icons.lvgl` in LVGL.
11
11
  This module imports neither.