Skip to content

Commit 3dd0955

Browse files
committed
Minor changes for handling new GlobalAction class
1 parent 1c966fa commit 3dd0955

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

streamdeck/__main__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import tomli as toml
1212

13-
from streamdeck.actions import Action
13+
from streamdeck.actions import ActionBase
1414
from streamdeck.cli.errors import (
1515
DirectoryNotFoundError,
1616
NotAFileError,
@@ -146,7 +146,7 @@ def read_streamdeck_config_from_pyproject(plugin_dir: Path) -> StreamDeckConfigD
146146

147147
class ActionLoader:
148148
@classmethod
149-
def load_actions(cls: type[Self], plugin_dir: Path, files: list[str]) -> Generator[Action, None, None]:
149+
def load_actions(cls: type[Self], plugin_dir: Path, files: list[str]) -> Generator[ActionBase, None, None]:
150150
# Ensure the parent directory of the plugin modules is in `sys.path`,
151151
# so that import statements in the plugin module will work as expected.
152152
if str(plugin_dir) not in sys.path:
@@ -191,12 +191,12 @@ def _load_module_from_file(filepath: Path) -> ModuleType:
191191
return module
192192

193193
@staticmethod
194-
def _get_actions_from_loaded_module(module: ModuleType) -> Generator[Action, None, None]:
194+
def _get_actions_from_loaded_module(module: ModuleType) -> Generator[ActionBase, None, None]:
195195
# Iterate over all attributes in the module to find Action subclasses
196196
for attribute_name in dir(module):
197197
attribute = getattr(module, attribute_name)
198-
# Check if the attribute is an instance of the Action class
199-
if isinstance(attribute, Action):
198+
# Check if the attribute is an instance of the Action class or GlobalAction class.
199+
if issubclass(type(attribute), ActionBase):
200200
yield attribute
201201

202202

streamdeck/actions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from abc import ABC
34
from collections import defaultdict
45
from functools import cached_property
56
from logging import getLogger
@@ -39,7 +40,7 @@
3940
}
4041

4142

42-
class ActionBase:
43+
class ActionBase(ABC):
4344
"""Base class for all actions."""
4445

4546
def __init__(self):
@@ -89,6 +90,9 @@ def get_event_handlers(self, event_name: EventNameStr, /) -> Generator[EventHand
8990
msg = f"Provided event name for pulling handlers from action does not exist: {event_name}"
9091
raise KeyError(msg)
9192

93+
if event_name not in self._events:
94+
return
95+
9296
yield from self._events[event_name]
9397

9498

streamdeck/manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def register_action(self, action: Action) -> None:
6161
Args:
6262
action (Action): The action to register.
6363
"""
64-
# First, configure a logger for the action, giving it the last part of its uuid as name.
65-
action_component_name = action.uuid.split(".")[-1]
64+
# First, configure a logger for the action, giving it the last part of its uuid as name (if it has one).
65+
action_component_name = action.uuid.split(".")[-1] if hasattr(action, "uuid") else "global"
6666
configure_streamdeck_logger(name=action_component_name, plugin_uuid=self.uuid)
6767

6868
self._registry.register(action)

0 commit comments

Comments
 (0)