Skip to content
Merged
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
3 changes: 2 additions & 1 deletion appdaemon/adapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3642,7 +3642,8 @@ def callback_inner(f: Future):
self.AD.futures.add_future(self.name, future)
return future

def create_task(
@utils.sync_decorator
async def create_task(
self,
coro: Coroutine[Any, Any, T],
callback: Callable | None = None,
Expand Down
8 changes: 5 additions & 3 deletions appdaemon/adbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from typing import TYPE_CHECKING

from appdaemon import adapi
from appdaemon import utils
from appdaemon.models.config.app import AppConfig
from appdaemon.utils import StateAttrs


# Check if the module is being imported using the legacy method
if __name__ == Path(__file__).name:
Expand All @@ -31,7 +32,7 @@ def __init__(self):
pass

def __get__(self, instance, owner):
stateattrs = StateAttrs(instance.get_state())
stateattrs = utils.StateAttrs(instance.get_state())
return stateattrs


Expand Down Expand Up @@ -165,7 +166,8 @@ def name(self) -> str:
def get_ad_api(self) -> adapi.ADAPI:
return adapi.ADAPI(self.AD, self.config_model)

def get_plugin_api(self, plugin_name: str):
@utils.sync_decorator
async def get_plugin_api(self, plugin_name: str):
"""Get the plugin API for a specific plugin."""
if isinstance(cfg := self.app_config.root.get(self.name), AppConfig):
return self.AD.plugins.get_plugin_api(plugin_name, cfg)
Expand Down
18 changes: 6 additions & 12 deletions appdaemon/plugins/mqtt/mqttapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,17 @@ def mqtt_publish(self, topic: str, payload: Any = None, **kwargs: Optional[Any])
result = self.call_service(service, **kwargs)
return result

def _run_service_call(self, task: str, topic: Union[str, list], **kwargs: Optional[Any]) -> None:
def _run_service_call(self, task: str, topic: str | list[str], **kwargs: Optional[Any]) -> None:
"""Used to process the subscribe/unsubscribe service calls"""

# first we validate the topic
if not isinstance(topic, (str, list)):
raise ValueError(f"The given topic {topic} is not supported. Please only strs and lists are supported")

if isinstance(topic, str):
kwargs["topic"] = topic
service = f"mqtt/{task}"
self.call_service(service, **kwargs)
kwargs["topic"] = topic
service = f"mqtt/{task}"
return self.call_service(service, **kwargs)

else: # its a list
for t in topic:
kwargs["topic"] = t
service = f"mqtt/{task}"
self.call_service(service, **kwargs)

def mqtt_subscribe(self, topic: Union[str, list], **kwargs: Optional[Any]) -> None:
"""Subscribes to a MQTT topic.
Expand Down Expand Up @@ -284,7 +278,7 @@ def mqtt_subscribe(self, topic: Union[str, list], **kwargs: Optional[Any]) -> No

"""

self._run_service_call("subscribe", topic, **kwargs)
return self._run_service_call("subscribe", topic, **kwargs)

def mqtt_unsubscribe(self, topic: Union[str, list], **kwargs: Optional[Any]) -> None:
"""Unsubscribes from a MQTT topic.
Expand Down Expand Up @@ -323,7 +317,7 @@ def mqtt_unsubscribe(self, topic: Union[str, list], **kwargs: Optional[Any]) ->

"""

self._run_service_call("unsubscribe", topic, **kwargs)
return self._run_service_call("unsubscribe", topic, **kwargs)

@utils.sync_decorator
async def is_client_connected(self, **kwargs: Optional[Any]) -> bool:
Expand Down
Loading