Runtime¶
runtime ¶
Runtime package for deux device sessions and events.
AsyncHandler
module-attribute
¶
Type alias for an async callback that accepts any arguments and returns None.
DeckEvent
module-attribute
¶
Union type of all events that can be received from a Stream Deck device.
AsyncEvent ¶
A multicast async event that can have multiple subscribers.
Subscribers are async callables registered via :meth:subscribe
or by using the event itself as a decorator. :meth:emit invokes
every registered subscriber sequentially, awaiting each one in
registration order.
The handler list is snapshotted at the start of every :meth:emit,
so subscribers may safely register or unregister during dispatch
without affecting the in-flight emission.
The signature of an event is part of its documented contract, not its static type — events here are intentionally non-generic so they can carry arbitrary positional/keyword payloads.
Examples:
::
on_volume_changed = AsyncEvent()
@on_volume_changed
async def _log(value: int) -> None:
print(f"volume = {value}")
await on_volume_changed.emit(75)
Source code in src/deux/runtime/async_event.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
has_value
property
¶
Whether :meth:emit has been called at least once.
Returns:
| Type | Description |
|---|---|
bool
|
|
last_args
property
¶
Positional arguments from the most recent :meth:emit.
Returns:
| Type | Description |
|---|---|
tuple
|
The positional args from the last emission. |
Raises:
| Type | Description |
|---|---|
LookupError
|
If :meth: |
last_kwargs
property
¶
Keyword arguments from the most recent :meth:emit.
Returns:
| Type | Description |
|---|---|
dict
|
The keyword args from the last emission. |
Raises:
| Type | Description |
|---|---|
LookupError
|
If :meth: |
subscribe ¶
Register handler as a subscriber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
_H
|
Async callable to invoke on every :meth: |
required |
Returns:
| Type | Description |
|---|---|
handler
|
The original handler, unchanged, so this can be used as a decorator. |
Source code in src/deux/runtime/async_event.py
unsubscribe ¶
Remove handler from the subscriber list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
AsyncHandler
|
A previously-registered subscriber. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If handler is not currently subscribed. |
Source code in src/deux/runtime/async_event.py
__call__ ¶
Decorator alias for :meth:subscribe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
_H
|
Async callable to register. |
required |
Returns:
| Type | Description |
|---|---|
handler
|
The original handler. |
Source code in src/deux/runtime/async_event.py
emit
async
¶
Invoke every subscriber sequentially, awaiting each in turn.
A snapshot of the handler list is taken first, so handlers may subscribe or unsubscribe during dispatch without affecting the current emission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to every handler. |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to every handler. |
{}
|
Source code in src/deux/runtime/async_event.py
DeviceCapabilities
dataclass
¶
Immutable snapshot of a Stream Deck device's hardware capabilities.
Constructed from a connected device via :meth:from_device, this
dataclass captures every property needed to drive layout, rendering,
and event routing without hardcoded constants.
Source code in src/deux/runtime/capabilities.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
has_info_screen
property
¶
Whether the device has a non-touch info screen (e.g. Neo).
from_device
classmethod
¶
Build capabilities from a connected (opened) HID device.
Reads hardware information from the device's Get Unit Information
feature report and derives all capabilities from the product ID and
self-reported geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
HidDevice
|
An open :class: |
required |
Returns:
| Type | Description |
|---|---|
DeviceCapabilities
|
A frozen :class: |
Source code in src/deux/runtime/capabilities.py
Deck ¶
Per-device handle for an Elgato Stream Deck.
Instances are created and managed by :class:DeckManager. Do not
instantiate Deck directly — use DeckManager.on_connect to
receive connected Deck instances.
The Deck object provides the per-device API for screens, keys,
encoders, touchscreen cards, brightness, and rendering.
Attributes:
| Name | Type | Description |
|---|---|---|
on_brightness_changed |
AsyncEvent
|
Fires after :meth: |
on_screen_changed |
AsyncEvent
|
Fires after :meth: |
Source code in src/deux/runtime/deck.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
is_connected
property
¶
Whether the device is currently connected and operational.
capabilities
property
¶
The device capabilities for the connected device.
Raises:
| Type | Description |
|---|---|
DeckError
|
If the device is not opened. |
metrics
property
¶
Rendering metrics for the connected device.
Raises:
| Type | Description |
|---|---|
DeckError
|
If the device is not opened. |
theme
property
writable
¶
Per-deck theme override, or None to inherit the system theme.
When set, this theme is used for all screens on this deck
unless a screen has its own :attr:~deux.Screen.theme
override. Set to None to fall back to the system-wide
theme.
active_screen
property
¶
The currently displayed screen, or None if no screen is set.
__init__ ¶
Construct a deck handle for the given serial number.
Instances are normally created by :class:DeckManager in
response to a device-connect event; application code receives
them via on_connect handlers. For unit tests that need a
deck without HID I/O, use :meth:Deck.for_testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serial_number
|
str
|
Serial number of the target device. Used during
:meth: |
required |
brightness
|
int
|
Initial brightness percentage in |
80
|
Notes
Construction performs no I/O. The HID device is opened and the
event loop started by :meth:start. The
:attr:on_brightness_changed and :attr:on_screen_changed
events are wired up here and ready for subscription before
:meth:start is called.
Source code in src/deux/runtime/deck.py
for_testing
classmethod
¶
for_testing(capabilities: DeviceCapabilities, *, serial_number: str = 'TEST', brightness: int = 80) -> Deck
Construct a :class:Deck pre-seeded with capabilities for tests.
Real construction goes through :meth:start, which discovers a
physical device and derives :attr:capabilities and
:attr:metrics from it. Tests that exercise behaviour above
the device layer need those two attributes populated without
any HID I/O.
This helper provides the supported way to do so, so that tests
do not have to assign to the private _caps / _metrics
attributes directly. No device is opened and no transport is
started — :attr:is_connected remains False until the
normal :meth:start path is invoked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capabilities
|
DeviceCapabilities
|
The capabilities to seed onto the deck. Drives the
derived :class: |
required |
serial_number
|
str
|
Serial number recorded on the instance. Does not need to correspond to a real device. |
"TEST"
|
brightness
|
int
|
Initial brightness (0-100). |
80
|
Returns:
| Type | Description |
|---|---|
Deck
|
A deck instance with :attr: |
Notes
This constructor is intended for unit tests. Production code
should use the normal :class:Deck constructor and
:meth:start.
Source code in src/deux/runtime/deck.py
start
async
¶
Discover the device by serial, open it, and start the event loop.
Source code in src/deux/runtime/deck.py
stop
async
¶
Stop the event loop and close the device.
Source code in src/deux/runtime/deck.py
wait_closed
async
¶
set_theme
async
¶
Apply a new deck-level theme and re-render the active screen.
Sets the deck theme, applies the CSS cascade to all renderers, marks every control dirty, and performs a complete re-render (icon prefetch, render all, push all) so the display updates atomically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme
|
Theme or None
|
The theme to apply, or |
required |
Source code in src/deux/runtime/deck.py
preload_icons
async
¶
Prefetch Iconify icons for all registered screens.
Collects every icon identifier across all screens and fetches them concurrently, warming the in-memory and disk caches. Call this after all screens have been set up (keys and cards installed) to avoid network latency on first render.
Source code in src/deux/runtime/deck.py
resolve_stylesheet ¶
Resolve the effective CSS stylesheet for the active screen.
The cascade is: screen theme > deck theme > system theme.
Returns:
| Type | Description |
|---|---|
str
|
CSS stylesheet string from the most specific theme. |
Source code in src/deux/runtime/deck.py
set_brightness
async
¶
Set screen brightness.
Pushes the value to the hardware (if connected) and emits
:attr:on_brightness_changed with the clamped result. If the
clamped value equals the current brightness, no event fires —
observers see only confirmed transitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percent
|
int
|
Brightness level (0-100). Values outside the range are clamped. |
required |
Source code in src/deux/runtime/deck.py
show_full_screen_image
async
¶
show_full_screen_image(image: Image | str | Path | bytes, *, fit: FitMode = 'cover', background: tuple[int, int, int] = (0, 0, 0), jpeg_quality: int = 90, min_display_ms: int = 0) -> None
Upload an image covering the entire LCD (HID command 0x08).
The image is loaded (PIL image, file path, raw image bytes, or
SVG), resized to the device's logical LCD size using fit,
rotated into the device's transmit orientation, JPEG-encoded,
and pushed via
:meth:HidDevice.set_full_screen_image.
Important behavioural contract. This is a one-shot,
whole-LCD blit. Any subsequent per-key (set_key_image),
per-window (set_partial_window_image), or per-screen render
will paint over the image. In particular, calling
:meth:set_screen after :meth:show_full_screen_image will
immediately clobber the image as the renderer pushes the new
screen.
Intended use cases are startup splashes, loading screens, and
lock screens. For persistent backgrounds, use the per-screen
background layer in :class:Screen instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image.Image, str, Path, or bytes
|
Source image. |
required |
fit
|
('cover', 'contain', 'stretch')
|
Resize strategy. |
"cover"
|
background
|
tuple[int, int, int]
|
RGB background colour used to letterbox under
|
(0, 0, 0)
|
jpeg_quality
|
int
|
JPEG encoding quality (1-95). |
90
|
min_display_ms
|
int
|
Minimum time, in milliseconds, that this image must remain
visible on the LCD before the push phase of the next
batched render ( |
0
|
Raises:
| Type | Description |
|---|---|
DeckError
|
If the device is not opened, or its PID has no known logical LCD size. |
SplashError
|
If image preparation fails. |
Examples:
Hold a splash for at least 500 ms so the user can perceive it
even when the first set_screen is very fast::
await deck.show_splash("boot.png", min_display_ms=500)
await deck.set_screen("home") # push delayed until 500ms elapsed
Source code in src/deux/runtime/deck.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
show_splash
async
¶
show_splash(image: Image | str | Path | bytes, *, fit: FitMode = 'cover', background: tuple[int, int, int] = (0, 0, 0), jpeg_quality: int = 90, min_display_ms: int = 0) -> None
Alias for :meth:show_full_screen_image, intended for startup.
Provides a semantically clearer entry point for the common case of displaying a boot/splash image before the first screen is rendered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image.Image, str, Path, or bytes
|
See :meth: |
required |
fit
|
('cover', 'contain', 'stretch')
|
See :meth: |
"cover"
|
background
|
tuple[int, int, int]
|
See :meth: |
(0, 0, 0)
|
jpeg_quality
|
int
|
See :meth: |
90
|
min_display_ms
|
int
|
See :meth: |
0
|
See Also
show_full_screen_image clear_full_screen_image
Source code in src/deux/runtime/deck.py
clear_full_screen_image
async
¶
Clear the LCD by uploading a solid-colour full-screen image.
Uses the same HID command 0x08 path as
:meth:show_full_screen_image, ensuring a deterministic
clear across all supported deck families. Behaviour-wise this
is equivalent to show_full_screen_image with a solid-colour
source; like that method, any subsequent per-key or per-window
write will paint over the cleared LCD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
tuple[int, int, int]
|
RGB fill colour. |
(0, 0, 0)
|
jpeg_quality
|
int
|
JPEG encoding quality (1-95). |
90
|
Raises:
| Type | Description |
|---|---|
DeckError
|
If the device is not opened, or its PID has no known logical LCD size. |
Source code in src/deux/runtime/deck.py
screen ¶
Get or create a screen by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Screen name. |
required |
Returns:
| Type | Description |
|---|---|
Screen
|
The Screen instance. |
Raises:
| Type | Description |
|---|---|
DeckError
|
If the device is not opened — capabilities are required to
size the screen, and they are only known after :meth: |
Source code in src/deux/runtime/deck.py
set_screen
async
¶
Switch to a named screen, rendering all keys and cards.
Wires up refresh callbacks on every key and card so that any
handler or background task can call request_refresh() to
trigger a re-render without needing a direct reference to the
deck. After the new screen has finished rendering, fires
:attr:on_screen_changed with the new name. No event fires
if the requested screen is already active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Screen name (must already exist via |
required |
Raises:
| Type | Description |
|---|---|
DeckError
|
If name does not match a previously-created screen. |
Source code in src/deux/runtime/deck.py
refresh
async
¶
Re-render and push all dirty controls on the active screen.
Call this after changing card values if you need immediate
updates outside of set_screen(). Also drains any pending
callbacks queued by programmatic set_value() calls on
range controls.
While the deck is inside a batched render (initial screen load, screen switch, or theme change), this call is recorded as pending and a single drain refresh fires once the batched operation completes. This prevents partial per-key writes from landing on the LCD between the old frame and the new one.
Source code in src/deux/runtime/deck.py
schedule_timeout_check ¶
Signal that a card timeout needs checking.
Call this method when a card registers a selection timeout so
the deck can fire _check_timeouts without polling. This is
a no-op when the timeout loop is already scheduled to wake.
Source code in src/deux/runtime/deck.py
DeckError ¶
DeviceInfo
dataclass
¶
Information about a connected Stream Deck device.
Attributes:
| Name | Type | Description |
|---|---|---|
deck_type |
str
|
Human-readable device model name (e.g. |
serial |
str
|
Unique serial number reported by the hardware. |
firmware |
str
|
Firmware version string. |
key_count |
int
|
Total number of physical keys on the device. |
key_layout |
tuple[int, int]
|
Key grid dimensions as |
encoder_count |
int
|
Number of rotary encoders (dials) on the device. |
key_pixel_size |
tuple[int, int]
|
Pixel dimensions of a single key image as |
touchscreen_size |
tuple[int, int]
|
Pixel dimensions of the touchscreen as |
key_image_format |
str
|
Image format expected by the device (e.g. |
Source code in src/deux/runtime/device_info.py
EncoderPressEvent
dataclass
¶
EncoderTurnEvent
dataclass
¶
EventType ¶
KeyEvent
dataclass
¶
TouchEvent
dataclass
¶
A touchscreen interaction event.
Source code in src/deux/runtime/events.py
compute_zone ¶
Compute which touch-strip zone this touch falls in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
RenderMetrics
|
The render metrics for the connected device. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Zone index (0 to panel_count-1). |
Source code in src/deux/runtime/events.py
DeckManager ¶
The main entry point for the deux library.
Manages one or more Stream Deck devices with automatic discovery,
hot-plug detection, and reconnection. Register on_connect and
on_disconnect handlers, then start the manager.
Examples:
::
manager = DeckManager()
@manager.on_connect(deck_type="Stream Deck +")
async def handle(deck: Deck):
screen = deck.screen("main")
@screen.key(0).on_press
async def on_home():
print("Home pressed!")
await deck.set_screen("main")
@manager.on_disconnect
async def lost(info: DeviceInfo):
print(f"Lost: {info.serial}")
async with manager:
await manager.wait_closed()
Source code in src/deux/runtime/manager.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
on_disconnect
property
¶
Register a callback for when a device disconnects.
Multiple handlers may be registered; all are called in registration order when a device disconnects.
Examples:
::
@manager.on_disconnect
async def handle(info: DeviceInfo):
...
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the handler. |
Notes
Unlike :meth:on_connect, this is a property returning the
decorator directly. Use it bare (@manager.on_disconnect);
calling it with parentheses raises :class:TypeError.
__init__ ¶
Construct a deck manager.
Construction is side-effect free; no devices are scanned until
:meth:start is called (directly or via async with).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poll_interval
|
float
|
Seconds between HID device scans. Lower values detect hot-plug events faster at the cost of more frequent enumeration. |
2.0
|
brightness
|
int
|
Default brightness percentage in |
80
|
auto_reconnect
|
bool
|
When |
True
|
Notes
The scan loop, executor lifecycle, and event subscriptions are
created lazily by :meth:start; constructing a manager is
cheap and does no I/O.
Source code in src/deux/runtime/manager.py
__aenter__
async
¶
__aexit__
async
¶
start
async
¶
Start the device scanning loop.
Source code in src/deux/runtime/manager.py
stop
async
¶
Stop scanning and close all managed decks.
Source code in src/deux/runtime/manager.py
wait_closed
async
¶
on_connect ¶
on_connect(*, serial: str | None = None, deck_type: str | None = None) -> Callable[[AsyncHandler], AsyncHandler]
Register a callback for when a matching device connects.
The handler is also called on reconnection when
auto_reconnect is enabled.
Examples:
::
@manager.on_connect(deck_type="Stream Deck +")
async def handle(deck: Deck):
...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serial
|
str | None
|
Only match this serial number. |
None
|
deck_type
|
str | None
|
Only match this device type. |
None
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the handler. |
Notes
Unlike :attr:on_disconnect, this is a decorator factory and
must be invoked with parentheses (@manager.on_connect()) even
when no filter arguments are passed.
Source code in src/deux/runtime/manager.py
AsyncTransport ¶
Poll-based async bridge from HID input reports to deck events.
Reads input reports from the device in a background task and
translates them into :class:DeckEvent objects on an asyncio queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
HidDevice
|
An open HID device. |
required |
caps
|
DeviceCapabilities or None
|
Device capabilities (used to determine which events to process). |
None
|
poll_interval_ms
|
int
|
HID read timeout per poll cycle in milliseconds. |
50
|
Source code in src/deux/runtime/transport.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
start ¶
Start the input polling background task.
Spawns an asyncio task that continuously polls the underlying
HID device for input events and forwards decoded events to
:attr:queue. Calling :meth:start more than once without an
intervening :meth:stop will replace the previous polling task
reference; callers should treat the method as one-shot per
transport lifetime.
Notes
Must be called from within a running asyncio event loop.
Source code in src/deux/runtime/transport.py
stop ¶
Stop polling.
Signals the polling loop to exit and cancels the background
task if it is still running. Safe to call multiple times and
safe to call when :meth:start was never invoked; in both
cases the method becomes a no-op.
Source code in src/deux/runtime/transport.py
get_executor ¶
Return the shared executor, creating it on first access.
The pool is lazily initialised so that import-time side-effects are avoided. All callers share the same instance.
Returns:
| Type | Description |
|---|---|
ThreadPoolExecutor
|
The shared executor. |
Source code in src/deux/runtime/_executor.py
shutdown_executor ¶
Shut down the shared executor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wait
|
bool
|
If |
True
|
Source code in src/deux/runtime/_executor.py
list_devices
async
¶
Enumerate all connected Stream Deck devices.
Discovers devices via HID, opens each briefly to read serial and
firmware information, then closes them. Returns a list of
:class:DeviceInfo snapshots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deck_type
|
str | None
|
If set, only return devices matching this type
(e.g. |
None
|
Returns:
| Type | Description |
|---|---|
list[DeviceInfo]
|
A list of :class: |