Fix handler type of register_api_command
authorMarvin Schenkel <marvinschenkel@gmail.com>
Tue, 25 Nov 2025 08:10:18 +0000 (09:10 +0100)
committerMarvin Schenkel <marvinschenkel@gmail.com>
Tue, 25 Nov 2025 08:10:18 +0000 (09:10 +0100)
music_assistant/helpers/api.py
music_assistant/mass.py

index 1cc336ef1a246066cdec1c9c6325254f23e84459..53403986dd72465277244e2a106a76d89b53fdb9 100644 (file)
@@ -4,7 +4,7 @@ from __future__ import annotations
 
 import inspect
 import logging
-from collections.abc import Callable, Coroutine
+from collections.abc import AsyncGenerator, Callable, Coroutine
 from dataclasses import MISSING, dataclass
 from datetime import datetime
 from enum import Enum
@@ -27,11 +27,11 @@ class APICommandHandler:
     command: str
     signature: inspect.Signature
     type_hints: dict[str, Any]
-    target: Callable[..., Coroutine[Any, Any, Any]]
+    target: Callable[..., Coroutine[Any, Any, Any] | AsyncGenerator[Any, Any]]
 
     @classmethod
     def parse(
-        cls, command: str, func: Callable[..., Coroutine[Any, Any, Any]]
+        cls, command: str, func: Callable[..., Coroutine[Any, Any, Any] | AsyncGenerator[Any, Any]]
     ) -> APICommandHandler:
         """Parse APICommandHandler by providing a function."""
         type_hints = get_type_hints(func)
index 3cec14240b8f7153eca71cfc1cb0692ca4fcd377..3dad39f43a2108d7a477a2e2fc5e75e284e022e4 100644 (file)
@@ -7,7 +7,7 @@ import logging
 import os
 import pathlib
 import threading
-from collections.abc import Awaitable, Callable, Coroutine
+from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine
 from typing import TYPE_CHECKING, Any, Self, TypeGuard, TypeVar, cast
 from uuid import uuid4
 
@@ -482,7 +482,7 @@ class MusicAssistant:
     def register_api_command(
         self,
         command: str,
-        handler: Callable[..., Coroutine[Any, Any, Any]],
+        handler: Callable[..., Coroutine[Any, Any, Any] | AsyncGenerator[Any, Any]],
     ) -> Callable[[], None]:
         """
         Dynamically register a command on the API.