Skip to content

Commit 475f0b0

Browse files
authored
Merge pull request #2279 from AppDaemon/async-revert
Async revert
2 parents 5509953 + d64c8f1 commit 475f0b0

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

appdaemon/adapi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3642,7 +3642,8 @@ def callback_inner(f: Future):
36423642
self.AD.futures.add_future(self.name, future)
36433643
return future
36443644

3645-
def create_task(
3645+
@utils.sync_decorator
3646+
async def create_task(
36463647
self,
36473648
coro: Coroutine[Any, Any, T],
36483649
callback: Callable | None = None,

appdaemon/adbase.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from typing import TYPE_CHECKING
66

77
from appdaemon import adapi
8+
from appdaemon import utils
89
from appdaemon.models.config.app import AppConfig
9-
from appdaemon.utils import StateAttrs
10+
1011

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

3334
def __get__(self, instance, owner):
34-
stateattrs = StateAttrs(instance.get_state())
35+
stateattrs = utils.StateAttrs(instance.get_state())
3536
return stateattrs
3637

3738

@@ -165,7 +166,8 @@ def name(self) -> str:
165166
def get_ad_api(self) -> adapi.ADAPI:
166167
return adapi.ADAPI(self.AD, self.config_model)
167168

168-
def get_plugin_api(self, plugin_name: str):
169+
@utils.sync_decorator
170+
async def get_plugin_api(self, plugin_name: str):
169171
"""Get the plugin API for a specific plugin."""
170172
if isinstance(cfg := self.app_config.root.get(self.name), AppConfig):
171173
return self.AD.plugins.get_plugin_api(plugin_name, cfg)

appdaemon/plugins/mqtt/mqttapi.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,17 @@ def mqtt_publish(self, topic: str, payload: Any = None, **kwargs: Optional[Any])
229229
result = self.call_service(service, **kwargs)
230230
return result
231231

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

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

239-
if isinstance(topic, str):
240-
kwargs["topic"] = topic
241-
service = f"mqtt/{task}"
242-
self.call_service(service, **kwargs)
239+
kwargs["topic"] = topic
240+
service = f"mqtt/{task}"
241+
return self.call_service(service, **kwargs)
243242

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

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

287-
self._run_service_call("subscribe", topic, **kwargs)
281+
return self._run_service_call("subscribe", topic, **kwargs)
288282

289283
def mqtt_unsubscribe(self, topic: Union[str, list], **kwargs: Optional[Any]) -> None:
290284
"""Unsubscribes from a MQTT topic.
@@ -323,7 +317,7 @@ def mqtt_unsubscribe(self, topic: Union[str, list], **kwargs: Optional[Any]) ->
323317
324318
"""
325319

326-
self._run_service_call("unsubscribe", topic, **kwargs)
320+
return self._run_service_call("unsubscribe", topic, **kwargs)
327321

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

0 commit comments

Comments
 (0)