From 03e7e685460e0a10027f698e8e58801affca4413 Mon Sep 17 00:00:00 2001 From: strohganoff Date: Thu, 3 Dec 2026 21:38:05 -0700 Subject: [PATCH] Clarify identifier string types --- streamdeck/command_sender.py | 29 +++++++++++++-------------- streamdeck/event_handlers/actions.py | 8 +++----- streamdeck/event_handlers/registry.py | 6 +++--- streamdeck/models/events/common.py | 21 ++++++++++++------- streamdeck/types.py | 15 ++++++++------ 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/streamdeck/command_sender.py b/streamdeck/command_sender.py index 070bb61..5ff84a4 100644 --- a/streamdeck/command_sender.py +++ b/streamdeck/command_sender.py @@ -11,15 +11,14 @@ from pydantic import JsonValue from streamdeck.types import ( - ActionInstanceUUIDStr, - ActionUUIDStr, - DeviceUUIDStr, + ActionIdStr, + ActionInstanceIdStr, + DeviceIdStr, EventNameStr, PluginDefinedData, ) - logger = getLogger("streamdeck.command_sender") @@ -42,7 +41,7 @@ async def _send_event(self, event: EventNameStr, **kwargs: Any) -> None: **kwargs, }) - async def set_settings(self, context: ActionInstanceUUIDStr, payload: PluginDefinedData) -> None: + async def set_settings(self, context: ActionInstanceIdStr, payload: PluginDefinedData) -> None: await self._send_event( event="setSettings", context=context, @@ -133,7 +132,7 @@ async def set_image( }, ) - async def set_feedback(self, context: ActionInstanceUUIDStr, payload: PluginDefinedData) -> None: + async def set_feedback(self, context: ActionInstanceIdStr, payload: PluginDefinedData) -> None: """Set's the feedback of an existing layout associated with an action instance. Args: @@ -146,7 +145,7 @@ async def set_feedback(self, context: ActionInstanceUUIDStr, payload: PluginDefi payload=payload, ) - async def set_feedback_layout(self, context: ActionInstanceUUIDStr, layout: str) -> None: + async def set_feedback_layout(self, context: ActionInstanceIdStr, layout: str) -> None: """Sets the layout associated with an action instance. Args: @@ -161,7 +160,7 @@ async def set_feedback_layout(self, context: ActionInstanceUUIDStr, layout: str) async def set_trigger_description( self, - context: ActionInstanceUUIDStr, + context: ActionInstanceIdStr, rotate: str | None = None, push: str | None = None, touch: str | None = None, @@ -198,21 +197,21 @@ async def set_trigger_description( }, ) - async def show_alert(self, context: ActionInstanceUUIDStr) -> None: + async def show_alert(self, context: ActionInstanceIdStr) -> None: """Temporarily show an alert icon on the image displayed by an instance of an action.""" await self._send_event( event="showAlert", context=context, ) - async def show_ok(self, context: ActionInstanceUUIDStr) -> None: + async def show_ok(self, context: ActionInstanceIdStr) -> None: """Temporarily show an OK checkmark icon on the image displayed by an instance of an action.""" await self._send_event( event="showOk", context=context, ) - async def set_state(self, context: ActionInstanceUUIDStr, state: int) -> None: + async def set_state(self, context: ActionInstanceIdStr, state: int) -> None: await self._send_event( event="setState", context=context, @@ -221,8 +220,8 @@ async def set_state(self, context: ActionInstanceUUIDStr, state: int) -> None: async def switch_to_profile( self, - context: ActionInstanceUUIDStr, - device: DeviceUUIDStr, + context: ActionInstanceIdStr, + device: DeviceIdStr, profile: str | None = None, page: int = 0, ) -> None: @@ -255,7 +254,7 @@ async def switch_to_profile( ) async def send_to_property_inspector( - self, context: ActionInstanceUUIDStr, payload: PluginDefinedData + self, context: ActionInstanceIdStr, payload: PluginDefinedData ) -> None: await self._send_event( event="sendToPropertyInspector", @@ -264,7 +263,7 @@ async def send_to_property_inspector( ) async def send_to_plugin( - self, context: ActionInstanceUUIDStr, action: ActionUUIDStr, payload: PluginDefinedData + self, context: ActionInstanceIdStr, action: ActionIdStr, payload: PluginDefinedData ) -> None: """Send a payload to another plugin. diff --git a/streamdeck/event_handlers/actions.py b/streamdeck/event_handlers/actions.py index a6a5cea..6c1c0ad 100644 --- a/streamdeck/event_handlers/actions.py +++ b/streamdeck/event_handlers/actions.py @@ -20,7 +20,7 @@ if TYPE_CHECKING: from collections.abc import Iterable - from streamdeck.types import ActionUUIDStr, EventNameStr + from streamdeck.types import ActionIdStr, EventNameStr @@ -92,10 +92,10 @@ class GlobalAction(ActionBase): class Action(ActionBase): """Represents an action that can be performed for a specific action, with event handlers for specific event types.""" - uuid: ActionUUIDStr + uuid: ActionIdStr """The unique identifier for the action.""" - def __init__(self, uuid: ActionUUIDStr) -> None: + def __init__(self, uuid: ActionIdStr) -> None: """Initialize an Action instance. Args: @@ -108,5 +108,3 @@ def __init__(self, uuid: ActionUUIDStr) -> None: def name(self) -> str: """The name of the action, derived from the last part of the UUID.""" return self.uuid.split(".")[-1] - - diff --git a/streamdeck/event_handlers/registry.py b/streamdeck/event_handlers/registry.py index 46de290..b59de19 100644 --- a/streamdeck/event_handlers/registry.py +++ b/streamdeck/event_handlers/registry.py @@ -13,7 +13,7 @@ from collections.abc import Iterator from streamdeck.event_handlers.protocol import EventHandlerFunc, SupportsEventHandlers - from streamdeck.types import ActionUUIDStr, EventNameStr + from streamdeck.types import ActionIdStr, EventNameStr ALL_EVENTS = sentinel("ALL_EVENTS") @@ -40,7 +40,7 @@ def register(self, catalog: SupportsEventHandlers) -> None: def iter_event_handler_bindings( self, event_name: EventNameStr | ALL_EVENTS = ALL_EVENTS, - event_action_uuid: ActionUUIDStr | None = None, + event_action_uuid: ActionIdStr | None = None, ) -> Iterator[tuple[EventNameStr, EventHandlerFunc]]: """Yield registered event names with their handlers, optionally filtered. @@ -68,7 +68,7 @@ def iter_event_handler_bindings( def get_event_handlers( self, event_name: EventNameStr | ALL_EVENTS, - event_action_uuid: ActionUUIDStr | None = None, + event_action_uuid: ActionIdStr | None = None, ) -> Iterator[EventHandlerFunc]: """Yield handlers matching an event name or enumerate all registrations. diff --git a/streamdeck/models/events/common.py b/streamdeck/models/events/common.py index c1739db..f6ab7c2 100644 --- a/streamdeck/models/events/common.py +++ b/streamdeck/models/events/common.py @@ -2,14 +2,14 @@ from typing import Annotated, Generic, Literal, NamedTuple, TypeAlias, Union -from pydantic import Field +from pydantic import UUID4, Field from typing_extensions import TypedDict, TypeVar from streamdeck.models.events.base import ConfiguredBaseModel from streamdeck.types import ( # noqa: TC001 - ActionInstanceUUIDStr, - DeviceUUIDStr, - EventNameStr, + ActionIdStr, + ActionInstanceIdStr, + DeviceIdStr, PluginDefinedData, ) @@ -18,18 +18,25 @@ class ActionInstanceEventMixin: """Mixin for events that identify an action and one of its instances.""" - action: EventNameStr + action: ActionIdStr """Unique identifier of the action""" - context: ActionInstanceUUIDStr + context: ActionInstanceIdStr """Identifies the instance of an action that caused the event, i.e. the specific key or dial.""" class DeviceSpecificEventMixin: """Mixin class for event models that have a device field.""" - device: DeviceUUIDStr + device: DeviceIdStr """Unique identifier of the Stream Deck device that this event is associated with.""" +class RequestCorrelationMixin: + """Mixin for response events that may include the originating request ID.""" + + id: UUID4 | None = None + """UUIDv4 request identifier, absent for unsolicited updates.""" + + ## Payload models and metadata used by multiple event models. EncoderControllerType = Literal["Encoder"] diff --git a/streamdeck/types.py b/streamdeck/types.py index f533baf..54f6ea8 100644 --- a/streamdeck/types.py +++ b/streamdeck/types.py @@ -15,14 +15,17 @@ We don't define literal string values here, as the list of available event names can be added to dynamically. """ -DeviceUUIDStr: TypeAlias = str -"""Unique identifier string of a Stream Deck device that an event is associated with.""" +ReverseDNSIdStr: TypeAlias = str +"""Reverse-DNS identifier used for plugin and action manifest IDs.""" -ActionUUIDStr: TypeAlias = str -"""Unique identifier string of a Stream Deck action that an event is associated with.""" +DeviceIdStr: TypeAlias = str +"""Unique identifier string of a Stream Deck device.""" -ActionInstanceUUIDStr: TypeAlias = str -"""Unique identifier string of a specific instance of an action that an event is associated with (e.g. a specific key or dial that the action is assigned to).""" +ActionIdStr: TypeAlias = ReverseDNSIdStr +"""Action identifier from the manifest, in reverse-DNS format.""" + +ActionInstanceIdStr: TypeAlias = str +"""Unique identifier string of a specific action instance (e.g. a key or dial).""" PluginDefinedData: TypeAlias = dict[str, JsonValue] """Key-value pair data of arbitrary structure that is defined in and relevant to the plugin.