feat(gui): a ble_address schema field, so any BLE device can offer Scan - #136
Merged
Conversation
A device rendered through the generic schema form got a plain text box for its address. Only the built-ins had a Scan button, because the hardware panel special-cases them by name -- which a plugin device cannot be. Pasting a MAC by hand is the difference between a device a researcher can add and one they have to be walked through. schema_form gains a "ble_address" field type. It also gains the widget itself, moved out of hardware_panel: the hand-built dialog rows and the schema-rendered form are now the same widget rather than two that drift. That is the third duplicated-implementation bug this week, so building a second copy here would have been a poor joke. Scanning is asynchronous and the form has no loop of its own, so the caller passes a runner. Without one the field still renders and stays editable and only the button is dropped -- an address can always be typed, and a form that refused to render because it could not scan would be worse than one that cannot scan. Reading the field back handles all three ways an address arrives: picked from a scan, where the address is the item data behind an advertised-name label; typed by hand; or pasted as a whole scan label, where the trailing " (name)" is stripped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second of three for making Maimu installable as a plugin. Follows #135 (node extension points); the Maimu move itself is next.
The gap
A device rendered through the generic schema form got a plain text box for its address. Only the built-ins have a Scan button, because
hardware_panelspecial-cases them by name — which a plugin device by definition cannot be.Pasting a BLE MAC by hand is the difference between a device a researcher can add and one they have to be walked through. Moving Maimu to a plugin without this would have been a straight downgrade.
What this adds
A
"ble_address"field type inschema_form, usable from any device'sSETTINGS_SCHEMA:{"key": "address", "label": "Address / UUID", "type": "ble_address"}It also moves the widget itself out of
hardware_panel. The hand-built dialog rows and the schema-rendered form a plugin gets are now the same widget rather than two that drift apart. That is the third duplicated-implementation bug this week (#129 two file formats, #133 two hardware-population loops), so writing a second copy here would have been a poor joke.Degradation is deliberate
Scanning is async and the form has no event loop of its own, so the caller passes a runner. Without one the field still renders and stays editable — only the button is dropped. An address can always be typed, and a form that refused to render because it could not scan would be worse than one that simply cannot scan.
Reading it back
All three ways an address arrives are handled: picked from a scan, where the address is item data behind an advertised-name label; typed by hand; or pasted as a whole scan label, where a trailing
" (name)"is stripped.Tests — 8 new
Scan offered when a runner is supplied; degrades to a typeable field without one; clicking Scan actually runs the coroutine; a typed address reads back; a scanned entry reads back its address, not its label; a pasted label is stripped; a saved address is shown; an empty field reads back empty.
Verification
PYTHONPATH=src QT_QPA_PLATFORM=offscreen pytest tests/— 3680 passed, 4 skipped, ruff and black clean.