Skip to content

Commit 733f799

Browse files
committed
Move actions and HandlersRegistry under event_handlers/ directory
1 parent b96c90f commit 733f799

File tree

11 files changed

+62
-45
lines changed

11 files changed

+62
-45
lines changed

streamdeck/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from . import (
2-
actions,
32
command_sender,
43
manager,
54
models,
65
utils,
76
websocket,
87
)
8+
from .event_handlers import actions
99

1010

1111
__all__ = [
Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -102,39 +102,3 @@ def name(self) -> str:
102102
return self.uuid.split(".")[-1]
103103

104104

105-
class HandlersRegistry:
106-
"""Manages the registration and retrieval of actions and their event handlers."""
107-
_plugin_actions: list[SupportsEventHandlers]
108-
"""List of registered actions."""
109-
110-
def __init__(self) -> None:
111-
"""Initialize an HandlersRegistry instance."""
112-
self._plugin_actions = []
113-
114-
def register(self, action: SupportsEventHandlers) -> None:
115-
"""Register an action with the registry.
116-
117-
Args:
118-
action (Action): The action to register.
119-
"""
120-
self._plugin_actions.append(action)
121-
122-
def get_event_handlers(self, event_name: EventNameStr, event_action_uuid: ActionUUIDStr | None = None) -> Generator[EventHandlerFunc, None, None]:
123-
"""Get all event handlers for a specific event from all registered actions.
124-
125-
Args:
126-
event_name (EventName): The name of the event to retrieve handlers for.
127-
event_action_uuid (str | None): The action UUID to get handlers for.
128-
If None (i.e., the event is not action-specific), get all handlers for the event.
129-
130-
Yields:
131-
EventHandlerFunc: The event handler functions for the specified event.
132-
"""
133-
for action in self._plugin_actions:
134-
# If the event is action-specific (i.e is not a GlobalAction and has a UUID attribute),
135-
# only get handlers for that action, as we don't want to trigger
136-
# and pass this event to handlers for other actions.
137-
if event_action_uuid is not None and (isinstance(action, Action) and action.uuid != event_action_uuid):
138-
continue
139-
140-
yield from action.get_event_handlers(event_name)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
from streamdeck.event_handlers.actions import Action
6+
7+
8+
if TYPE_CHECKING:
9+
from collections.abc import Generator
10+
11+
from streamdeck.event_handlers.protocol import EventHandlerFunc, SupportsEventHandlers
12+
from streamdeck.types import ActionUUIDStr, EventNameStr
13+
14+
15+
class HandlersRegistry:
16+
"""Manages the registration and retrieval of actions and their event handlers."""
17+
_plugin_actions: list[SupportsEventHandlers]
18+
"""List of registered actions."""
19+
20+
def __init__(self) -> None:
21+
"""Initialize an HandlersRegistry instance."""
22+
self._plugin_actions = []
23+
24+
def register(self, action: SupportsEventHandlers) -> None:
25+
"""Register an action with the registry.
26+
27+
Args:
28+
action (Action): The action to register.
29+
"""
30+
self._plugin_actions.append(action)
31+
32+
def get_event_handlers(self, event_name: EventNameStr, event_action_uuid: ActionUUIDStr | None = None) -> Generator[EventHandlerFunc, None, None]:
33+
"""Get all event handlers for a specific event from all registered actions.
34+
35+
Args:
36+
event_name (EventName): The name of the event to retrieve handlers for.
37+
event_action_uuid (str | None): The action UUID to get handlers for.
38+
If None (i.e., the event is not action-specific), get all handlers for the event.
39+
40+
Yields:
41+
EventHandlerFunc: The event handler functions for the specified event.
42+
"""
43+
for action in self._plugin_actions:
44+
# If the event is action-specific (i.e is not a GlobalAction and has a UUID attribute),
45+
# only get handlers for that action, as we don't want to trigger
46+
# and pass this event to handlers for other actions.
47+
if event_action_uuid is not None and (isinstance(action, Action) and action.uuid != event_action_uuid):
48+
continue
49+
50+
yield from action.get_event_handlers(event_name)

streamdeck/manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
from pydantic import ValidationError
88

9-
from streamdeck.actions import Action, ActionBase, HandlersRegistry
109
from streamdeck.command_sender import StreamDeckCommandSender
10+
from streamdeck.event_handlers.actions import Action, ActionBase
1111
from streamdeck.event_handlers.protocol import (
1212
SupportsEventHandlers,
1313
is_bindable_handler,
1414
is_not_bindable_handler,
1515
)
16+
from streamdeck.event_handlers.registry import HandlersRegistry
1617
from streamdeck.event_listener import EventListener, EventListenerManager
1718
from streamdeck.models.events.adapter import EventAdapter
1819
from streamdeck.models.events.common import ContextualEventMixin

tests/actions/test_action_event_handler_filtering.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from unittest.mock import create_autospec
55

66
import pytest
7-
from streamdeck.actions import Action, GlobalAction, HandlersRegistry
7+
from streamdeck.event_handlers.actions import Action, GlobalAction
8+
from streamdeck.event_handlers.registry import HandlersRegistry
89
from streamdeck.models.events.common import ContextualEventMixin
910

1011
from tests.test_utils.fake_event_factories import (

tests/actions/test_action_registry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from typing import TYPE_CHECKING
44

55
import pytest
6-
from streamdeck.actions import Action, HandlersRegistry
6+
from streamdeck.event_handlers.actions import Action
7+
from streamdeck.event_handlers.registry import HandlersRegistry
78

89
from tests.test_utils.fake_event_factories import (
910
DialDownEventFactory,

tests/actions/test_actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import TYPE_CHECKING, Any, cast
44

55
import pytest
6-
from streamdeck.actions import Action, ActionBase, GlobalAction
6+
from streamdeck.event_handlers.actions import Action, ActionBase, GlobalAction
77
from streamdeck.models.events import DEFAULT_EVENT_NAMES
88

99

tests/data/test_action1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from streamdeck.actions import Action
21
from streamdeck.command_sender import StreamDeckCommandSender
2+
from streamdeck.event_handlers.actions import Action
33
from streamdeck.models.events import KeyDown, WillAppear
44

55

tests/data/test_action2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from streamdeck.actions import Action, GlobalAction
1+
from streamdeck.event_handlers.actions import Action, GlobalAction
22
from streamdeck.models.events import ApplicationDidLaunch
33

44

tests/plugin_manager/test_command_sender_binding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from unittest.mock import Mock, create_autospec
66

77
import pytest
8-
from streamdeck.actions import Action
8+
from streamdeck.event_handlers.actions import Action
99

1010

1111
if TYPE_CHECKING:

0 commit comments

Comments
 (0)