7
7
if TYPE_CHECKING :
8
8
from typing import Any , Literal
9
9
10
+ from streamdeck .types import (
11
+ ActionInstanceUUIDStr ,
12
+ ActionUUIDStr ,
13
+ DeviceUUIDStr ,
14
+ EventNameStr ,
15
+ PluginDefinedData ,
16
+ )
10
17
from streamdeck .websocket import WebSocketClient
11
18
12
19
16
23
17
24
class StreamDeckCommandSender :
18
25
"""Class for sending command event messages to the Stream Deck software through a WebSocket client."""
26
+
19
27
def __init__ (self , client : WebSocketClient , plugin_registration_uuid : str ):
20
28
self ._client = client
21
29
self ._plugin_registration_uuid = plugin_registration_uuid
22
30
23
- def _send_event (self , event : str , ** kwargs : Any ) -> None :
31
+ def _send_event (self , event : EventNameStr , ** kwargs : Any ) -> None :
24
32
self ._client .send_event ({
25
33
"event" : event ,
26
34
** kwargs ,
27
35
})
28
36
29
- def set_settings (self , context : str , payload : dict [ str , Any ] ) -> None :
37
+ def set_settings (self , context : ActionInstanceUUIDStr , payload : PluginDefinedData ) -> None :
30
38
self ._send_event (
31
39
event = "setSettings" ,
32
40
context = context ,
33
41
payload = payload ,
34
42
)
35
43
36
- def get_settings (self , context : str ) -> None :
44
+ def get_settings (self , context : ActionInstanceUUIDStr ) -> None :
37
45
self ._send_event (
38
46
event = "getSettings" ,
39
47
context = context ,
40
48
)
41
49
42
- def set_global_settings (self , payload : dict [ str , Any ] ) -> None :
50
+ def set_global_settings (self , payload : PluginDefinedData ) -> None :
43
51
self ._send_event (
44
52
event = "setGlobalSettings" ,
45
53
context = self ._plugin_registration_uuid ,
@@ -52,14 +60,14 @@ def get_global_settings(self) -> None:
52
60
context = self ._plugin_registration_uuid ,
53
61
)
54
62
55
- def open_url (self , context : str , url : str ) -> None :
63
+ def open_url (self , context : ActionInstanceUUIDStr , url : str ) -> None :
56
64
self ._send_event (
57
65
event = "openUrl" ,
58
66
context = context ,
59
67
payload = {"url" : url },
60
68
)
61
69
62
- def log_message (self , context : str , message : str ) -> None :
70
+ def log_message (self , context : ActionInstanceUUIDStr , message : str ) -> None :
63
71
self ._send_event (
64
72
event = "logMessage" ,
65
73
context = context ,
@@ -68,10 +76,10 @@ def log_message(self, context: str, message: str) -> None:
68
76
69
77
def set_title (
70
78
self ,
71
- context : str ,
79
+ context : ActionInstanceUUIDStr ,
72
80
state : int | None = None ,
73
- target : str | None = None ,
74
- title : str | None = None
81
+ target : Literal [ "hardware" , "software" , "both" ] | None = None ,
82
+ title : str | None = None ,
75
83
) -> None :
76
84
payload = {}
77
85
@@ -90,10 +98,10 @@ def set_title(
90
98
91
99
def set_image (
92
100
self ,
93
- context : str ,
94
- image : str , # base64 encoded image,
95
- target : Literal ["hardware" , "software" , "both" ], # software, hardware, or both,
96
- state : int , # 0-based integer
101
+ context : ActionInstanceUUIDStr ,
102
+ image : str , # base64 encoded image,
103
+ target : Literal ["hardware" , "software" , "both" ],
104
+ state : int ,
97
105
) -> None :
98
106
"""...
99
107
@@ -117,14 +125,26 @@ def set_image(
117
125
},
118
126
)
119
127
120
- def set_feedback (self , context : str , payload : dict [str , Any ]) -> None :
128
+ def set_feedback (self , context : ActionInstanceUUIDStr , payload : PluginDefinedData ) -> None :
129
+ """Set's the feedback of an existing layout associated with an action instance.
130
+
131
+ Args:
132
+ context (str): Defines the context of the command, e.g. which action instance the command is intended for.
133
+ payload (PluginDefinedData): Additional information supplied as part of the command.
134
+ """
121
135
self ._send_event (
122
136
event = "setFeedback" ,
123
137
context = context ,
124
138
payload = payload ,
125
139
)
126
140
127
- def set_feedback_layout (self , context : str , layout : str ) -> None :
141
+ def set_feedback_layout (self , context : ActionInstanceUUIDStr , layout : str ) -> None :
142
+ """Sets the layout associated with an action instance.
143
+
144
+ Args:
145
+ context (str): Defines the context of the command, e.g. which action instance the command is intended for.
146
+ layout (str): Name of a pre-defined layout, or relative path to a custom one.
147
+ """
128
148
self ._send_event (
129
149
event = "setFeedbackLayout" ,
130
150
context = context ,
@@ -133,7 +153,7 @@ def set_feedback_layout(self, context: str, layout: str) -> None:
133
153
134
154
def set_trigger_description (
135
155
self ,
136
- context : str ,
156
+ context : ActionInstanceUUIDStr ,
137
157
rotate : str | None = None ,
138
158
push : str | None = None ,
139
159
touch : str | None = None ,
@@ -170,21 +190,21 @@ def set_trigger_description(
170
190
},
171
191
)
172
192
173
- def show_alert (self , context : str ) -> None :
193
+ def show_alert (self , context : ActionInstanceUUIDStr ) -> None :
174
194
"""Temporarily show an alert icon on the image displayed by an instance of an action."""
175
195
self ._send_event (
176
196
event = "showAlert" ,
177
197
context = context ,
178
198
)
179
199
180
- def show_ok (self , context : str ) -> None :
200
+ def show_ok (self , context : ActionInstanceUUIDStr ) -> None :
181
201
"""Temporarily show an OK checkmark icon on the image displayed by an instance of an action."""
182
202
self ._send_event (
183
203
event = "showOk" ,
184
204
context = context ,
185
205
)
186
206
187
- def set_state (self , context : str , state : int ) -> None :
207
+ def set_state (self , context : ActionInstanceUUIDStr , state : int ) -> None :
188
208
self ._send_event (
189
209
event = "setState" ,
190
210
context = context ,
@@ -193,8 +213,8 @@ def set_state(self, context: str, state: int) -> None:
193
213
194
214
def switch_to_profile (
195
215
self ,
196
- context : str ,
197
- device : str ,
216
+ context : ActionInstanceUUIDStr ,
217
+ device : DeviceUUIDStr ,
198
218
profile : str | None = None ,
199
219
page : int = 0 ,
200
220
) -> None :
@@ -211,7 +231,7 @@ def switch_to_profile(
211
231
page (int): Page to show when switching to the profile; indexed from 0.
212
232
"""
213
233
# TODO: Should validation happen that ensures the specified profile is declared in manifest.yaml?
214
- payload = {}
234
+ payload : dict [ str , str | int | None ] = {}
215
235
216
236
if profile is not None :
217
237
payload = {
@@ -226,18 +246,17 @@ def switch_to_profile(
226
246
payload = payload ,
227
247
)
228
248
229
- def send_to_property_inspector (self , context : str , payload : dict [str , Any ]) -> None :
249
+ def send_to_property_inspector (
250
+ self , context : ActionInstanceUUIDStr , payload : PluginDefinedData
251
+ ) -> None :
230
252
self ._send_event (
231
253
event = "sendToPropertyInspector" ,
232
254
context = context ,
233
255
payload = payload ,
234
256
)
235
257
236
258
def send_to_plugin (
237
- self ,
238
- context : str ,
239
- action : str ,
240
- payload : dict [str , Any ]
259
+ self , context : ActionInstanceUUIDStr , action : ActionUUIDStr , payload : PluginDefinedData
241
260
) -> None :
242
261
"""Send a payload to another plugin.
243
262
0 commit comments