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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"websockets >= 16.1",
"pydantic-settings[toml] >= 2.11",
"typing-extensions >= 4.14.0",
"exceptiongroup >= 1.3.1",
"exceptiongroup >= 1.3.1; python_version < '3.11'",
]

[project.urls]
Expand Down
7 changes: 2 additions & 5 deletions streamdeck/command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ async def set_settings(self, context: ActionInstanceIdStr, payload: PluginDefine
)

async def get_settings(self, context: ActionInstanceUUIDStr) -> None:
await self._send_event(
event="getSettings",
context=context,
)
await self._send_event("getSettings", context=context)

async def set_global_settings(self, payload: PluginDefinedData) -> None:
await self._send_event(
Expand All @@ -63,7 +60,7 @@ async def set_global_settings(self, payload: PluginDefinedData) -> None:

async def get_global_settings(self) -> None:
await self._send_event(
event="getGlobalSettings",
"getGlobalSettings",
context=self._plugin_registration_uuid,
)

Expand Down
2 changes: 1 addition & 1 deletion streamdeck/event_handlers/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""Handler-specific trailing signature; it may include parameters the SDK cannot inject."""

EventHandlerResult: TypeAlias = Awaitable[None] | None
"""Result of calling a handler: ``None`` for sync handlers or an awaitable for async handlers."""
"""Result of calling a handler: `None` for sync handlers or an awaitable for async handlers."""

# The ParamSpec preserves a handler's declared trailing signature at
# registration. Its default ellipsis gives catalogs and dispatch a common type
Expand Down
6 changes: 3 additions & 3 deletions streamdeck/event_handlers/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def iter_event_handler_bindings(
"""Yield registered event names with their handlers, optionally filtered.

Args:
event_name: The event name to retrieve, or ``ALL_EVENTS`` to enumerate every
event_name: The event name to retrieve, or `ALL_EVENTS` to enumerate every
registered event.
event_action_uuid: The action UUID to filter action-specific catalogs by. If None,
include handlers from all catalogs.
Expand All @@ -72,12 +72,12 @@ def get_event_handlers(
) -> Iterator[EventHandlerFunc]:
"""Yield handlers matching an event name or enumerate all registrations.

Passing ``ALL_EVENTS`` enumerates handlers registered under every event
Passing `ALL_EVENTS` enumerates handlers registered under every event
name. It does not register a handler to receive every event.

Args:
event_name (EventNameStr | ALL_EVENTS): The event name to retrieve,
or ``ALL_EVENTS`` to enumerate every registered event.
or `ALL_EVENTS` to enumerate every registered event.
event_action_uuid (str | None): The action UUID to get handlers for.
If None (i.e., the event is not action-specific), get all handlers for the event.

Expand Down
7 changes: 6 additions & 1 deletion streamdeck/event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
from __future__ import annotations

import asyncio
import sys
from abc import ABC, abstractmethod
from dataclasses import dataclass
from logging import getLogger
from typing import TYPE_CHECKING

from exceptiongroup import ExceptionGroup
from typing_extensions import sentinel


if sys.version_info < (3, 11):
# ExceptionGroup is built in starting with Python 3.11.
from exceptiongroup import ExceptionGroup


if TYPE_CHECKING:
from collections.abc import AsyncIterator, Awaitable
from typing import ClassVar
Expand Down
2 changes: 1 addition & 1 deletion streamdeck/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def listen(self) -> AsyncIterator[str | bytes]:
elif isinstance(exc, ConnectionClosed):
logger.exception("Connection was already closed.")
else:
logger.exception("Connection is closed due to an unexpected WebSocket error.")
logger.exception("Connection closed due to an unexpected WebSocket error.")

raise StopStreaming from None
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_toml_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def test_cli_listener_modules_replace_toml_before_import(tmp_path, flag):


def test_repeated_listener_aliases_combine_in_one_override(tmp_path):
from tests.data.dummy_event_listener import DummyEventListener
from streamdeck.websocket import WebSocketClient
from tests.data.dummy_event_listener import DummyEventListener

write_config(
tmp_path,
Expand Down
4 changes: 2 additions & 2 deletions tests/plugin_manager/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def patch_websocket_client(monkeypatch: pytest.MonkeyPatch) -> Mock:
mock_websocket_client.__aenter__.return_value = mock_websocket_client
mock_websocket_client.__aexit__.return_value = False

monkeypatch.setattr("streamdeck.manager.WebSocketClient", (lambda *args, **kwargs: mock_websocket_client))
monkeypatch.setattr("streamdeck.manager.WebSocketClient", lambda *args, **kwargs: mock_websocket_client)

return mock_websocket_client

Expand Down Expand Up @@ -116,7 +116,7 @@ def mock_event_listener_manager_with_fake_events(patch_event_listener_manager: M
Returns:
tuple: Mocked instance of EventListenerManager, and a list of fake event messages.
"""
# Create a list of fake event messages, and convert them to json strings to be passed back by the client.listen() method.
# Convert the fake event messages to JSON strings for the listener manager to yield.
fake_event_messages: list[events.EventBase] = [
KeyDownEventFactory.build(action="my-fake-action-uuid"),
]
Expand Down
5 changes: 3 additions & 2 deletions tests/test_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ def test_command_sender_methods(

method = getattr(command_sender, method_name)
if context is not None:
asyncio.run(method(context, **extra_args))
result = asyncio.run(method(context, **extra_args))
else:
asyncio.run(method(**extra_args))
result = asyncio.run(method(**extra_args))
assert result is None

# Build the expected data structure to send through the WebSocket
expected_data = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async def scenario() -> None:
(ConnectionClosedOK(None, None), logging.DEBUG, "Connection was closed normally, stopping the client."),
(ConnectionClosedError(None, None), logging.ERROR, "Connection was terminated with an error."),
(ConnectionClosed(None, None), logging.ERROR, "Connection was already closed."),
(WebSocketException("broken"), logging.ERROR, "Connection is closed due to an unexpected WebSocket error."),
(WebSocketException("broken"), logging.ERROR, "Connection closed due to an unexpected WebSocket error."),
],
)
def test_listen_logs_websocket_exception_type(
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading