diff --git a/hugvey/central_command.py b/hugvey/central_command.py index 8e03730..c6985b3 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -126,7 +126,7 @@ class CentralCommand(object): def getStatusSummary(self, selected_id = None): status = { - 'uptime': time.time() - self.start_time, + 'uptime': "-" if not self.start_time else (time.time() - self.start_time), 'languages': self.config['languages'], 'hugvey_ids': self.hugvey_ids, 'hugveys': [], @@ -204,7 +204,35 @@ class CentralCommand(object): logger.info(f'Reconfigure hugvey #{hugvey_id}') # (re)configure exisitng hugveys h.config(msg['host'], msg['ip']) - + + async def timerEmitter(self): + """ + This is fixed: a one hour loop with a collective moment 10-15 minutes, + 30-35 minutes and 50-55 minutes + """ + loop_duration = 60 * 60 # one hour loop + intervals = [ + { + 'start_time': 10*60, + 'duration': 5 * 60, + }, + { + 'start_time': 30*60, + 'duration': 5 * 60, + }, + { + 'start_time': 50*60, + 'duration': 5 * 60, + } + ] + self.start_time = time.time() + + # TODO: emit start event + + while self.isRunning.is_set(): + + pass + async def eventListener(self): s = self.ctx.socket(zmq.SUB) s.bind(self.config['events']['listen_address']) @@ -301,6 +329,7 @@ class HugveyState(object): STATE_PAUSE = "paused" STATE_GONE = "gone" STATE_RUNNING = "running" + STATE_FINISHED = "finished" def __init__(self, id: int, command: CentralCommand): self.id = id @@ -322,7 +351,7 @@ class HugveyState(object): def getStatus(self): if self.story.isFinished(): - return "finished" + return self.STATE_FINISHED return self.status def config(self, hostname, ip): @@ -362,7 +391,7 @@ class HugveyState(object): async def catchException(self, awaitable): try: - print(awaitable) +# print(awaitable) await awaitable except Exception as e: self.logger.exception(e) @@ -403,6 +432,8 @@ class HugveyState(object): self.pause() if event['event'] == 'restart': self.restart() + if event['event'] == 'finish': + self.finish() if event['event'] == 'resume': self.resume() @@ -474,6 +505,15 @@ class HugveyState(object): self.story.stop() self.resume() self.isRunning.set() + + def finish(self): + """Finish playback""" + self.logger.info('Restart') + self.pause() + if self.story: + self.story.finish() + self.status = self.STATE_FINISHED + def gone(self): '''Status to 'gone' as in, shutdown/crashed/whatever diff --git a/hugvey/client.py b/hugvey/client.py index 87811fe..d3c015b 100644 --- a/hugvey/client.py +++ b/hugvey/client.py @@ -313,16 +313,16 @@ class CommandHandler(object): self.playPopen = None else: logger.info("Speak: {}".format(text)) + playCmd = ['espeak', '-p', '{0}'.format(pitch), text] self.playPopen = subprocess.Popen( - ['espeak', '-p', '{0}'.format(pitch), text], stdout=subprocess.PIPE) + playCmd, stdout=subprocess.PIPE) returnCode = self.playPopen.wait() self.playPopen = None if returnCode: - logger.critical("Had returncode on play: {}".format(returnCode)) + logger.critical("Had returncode {} on play: {}".format(returnCode, playCmd)) else: - logger.debug( - "Finished playback. Return code: {}".format(returnCode)) + logger.debug("Finished playback.") self.playingMsgId = None self.muteMic = False diff --git a/hugvey/panopticon.py b/hugvey/panopticon.py index 1ced204..1edf343 100644 --- a/hugvey/panopticon.py +++ b/hugvey/panopticon.py @@ -58,6 +58,8 @@ def getWebSocketHandler(central_command): self.msgPause(msg['hugvey']) elif msg['action'] == 'restart': self.msgRestart(msg['hugvey']) + elif msg['action'] == 'finish': + self.msgFinish(msg['hugvey']) elif msg['action'] == 'change_language': self.msgChangeLanguage(msg['hugvey'], msg['lang_code']) elif msg['action'] == 'play_msg': @@ -102,6 +104,9 @@ def getWebSocketHandler(central_command): def msgRestart(self, hv_id): central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'restart'}) + def msgFinish(self, hv_id): + central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'finish'}) + def msgChangeLanguage(self, hv_id, lang_code): central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_language', 'lang_code': lang_code}) diff --git a/hugvey/story.py b/hugvey/story.py index 96f7ae3..22e82d7 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -977,4 +977,6 @@ class Story(object): self.hugvey.pause() self.finish_time = time.time() self.timer.pause() + #stop google etc: + self.hugvey.isRunning.clear() diff --git a/www/index.html b/www/index.html index 4ee440e..0e49f71 100644 --- a/www/index.html +++ b/www/index.html @@ -63,6 +63,7 @@