Skip to content

Commit e9ca09d

Browse files
authored
feat: check if callback is async or sync then call it properly (#392)
* feat: check if callback is async or sync then call it properly * formatting * linting
1 parent 3b17141 commit e9ca09d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

openevsehttp/__main__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,21 @@ async def _update_status(self, msgtype, data, error):
280280
self._status.update(data)
281281

282282
if self.callback is not None:
283-
self.callback() # pylint: disable=not-callable
283+
if self.is_coroutine_function(self.callback):
284+
await self.callback() # pylint: disable=not-callable
285+
else:
286+
self.callback() # pylint: disable=not-callable
284287

285288
async def ws_disconnect(self) -> None:
286289
"""Disconnect the websocket listener."""
287290
assert self.websocket
288291
await self.websocket.close()
289292
self._ws_listening = False
290293

294+
def is_coroutine_function(self, callback):
295+
"""Check if a callback is a coroutine function."""
296+
return asyncio.iscoroutinefunction(callback)
297+
291298
@property
292299
def ws_state(self) -> Any:
293300
"""Return the status of the websocket listener."""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
PROJECT_DIR = Path(__file__).parent.resolve()
88
README_FILE = PROJECT_DIR / "README.md"
9-
VERSION = "0.1.64"
9+
VERSION = "0.1.65"
1010

1111
setup(
1212
name="python-openevse-http",

0 commit comments

Comments
 (0)