Skip to content

Commit

Permalink
Prevent multible runs of async stats task
Browse files Browse the repository at this point in the history
  • Loading branch information
rroemhild committed Aug 26, 2019
1 parent c420801 commit 660630a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion homie/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = b"2.0.0-beta.1"
__version__ = b"2.0.0-beta.2"
7 changes: 5 additions & 2 deletions homie/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, settings):
self._state = STATE_INIT
self._extensions = settings.EXTENSIONS

self.async_tasks = []
self.stats_interval = settings.DEVICE_STATS_INTERVAL

self.nodes = []
Expand Down Expand Up @@ -188,8 +189,10 @@ async def legacy_firmware(self):
async def legacy_stats(self):
await self.publish(b"$stats/interval", self.stats_interval)
# Start stats coro
loop = get_event_loop()
loop.create_task(self.publish_stats())
if "stats" not in self.async_tasks:
loop = get_event_loop()
loop.create_task(self.publish_stats())
self.async_tasks.append("stats")

@await_ready_state
async def publish_stats(self):
Expand Down

0 comments on commit 660630a

Please sign in to comment.