Fix queing of restart

This commit is contained in:
Ruben van de Ven 2019-01-25 13:11:00 +01:00
parent 46299d2dac
commit 2a712fb7e1

View file

@ -320,6 +320,11 @@ class HugveyState(object):
self.logger.critical("No event queue to put {}".format(msg)) self.logger.critical("No event queue to put {}".format(msg))
else: else:
# Allow for both the Hugvey Command, or the Story handle the event. # Allow for both the Hugvey Command, or the Story handle the event.
self.loop.call_soon_threadsafe(self._queueEvent, msg)
def _queueEvent(self, msg):
self.logger.debug(f"Queue event in hugvey loop: {msg}")
self.eventQueue.put_nowait(msg) self.eventQueue.put_nowait(msg)
self.story.events.append(msg) self.story.events.append(msg)
@ -329,6 +334,9 @@ class HugveyState(object):
event = await self.eventQueue.get() event = await self.eventQueue.get()
self.logger.info("Received: {}".format(event)) self.logger.info("Received: {}".format(event))
if event['event'] == 'connection' and not self.isRunning.is_set():
self.restart()
if event['event'] == 'language': if event['event'] == 'language':
self.setLanguage(event['code']) self.setLanguage(event['code'])
@ -434,7 +442,7 @@ class HugveyState(object):
self.logger.info("Start audio stream") self.logger.info("Start audio stream")
while self.notShuttingDown: while self.notShuttingDown:
# self.isRunning.wait() await self.isRunning.wait()
self.logger.info("Start audio stream") self.logger.info("Start audio stream")
await self.getStreamer().run() await self.getStreamer().run()