Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions streamdeck/command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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",
Expand All @@ -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.

Expand Down
8 changes: 3 additions & 5 deletions streamdeck/event_handlers/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
if TYPE_CHECKING:
from collections.abc import Iterable

from streamdeck.types import ActionUUIDStr, EventNameStr
from streamdeck.types import ActionIdStr, EventNameStr



Expand Down Expand Up @@ -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:
Expand All @@ -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]


6 changes: 3 additions & 3 deletions streamdeck/event_handlers/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.

Expand Down Expand Up @@ -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.

Expand Down
21 changes: 14 additions & 7 deletions streamdeck/models/events/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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"]
Expand Down
15 changes: 9 additions & 6 deletions streamdeck/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading