Add 'finish' button, and attempt on #29

This commit is contained in:
Ruben van de Ven 2019-04-16 12:38:12 +02:00
parent 080cd1bcee
commit 16a186dc89
6 changed files with 63 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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})

View file

@ -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()

View file

@ -63,6 +63,7 @@
<div class='btn' v-if="hv.status == 'running'" @click.stop="pause(hv)">Pause</div>
<div class='btn' v-if="hv.status == 'paused'" @click.stop="resume(hv)">Resume</div>
<div class='btn' v-if="hv.status == 'finished'" @click.stop="restart(hv)">Restart</div>
<div class='btn' v-if="hv.status == 'running'" @click.stop="finish(hv)">Finish</div>
</div>
</div>
</div>

View file

@ -36,6 +36,10 @@ class Panopticon {
hv.status = "loading";
return panopticon.restart(hv.id);
},
finish: function(hv) {
hv.status = "loading";
return panopticon.finish(hv.id);
},
change_lang: function(hv, lang_code) {
hv.status = "loading";
return panopticon.change_language(hv.id, lang_code);
@ -279,6 +283,9 @@ class Panopticon {
restart( hv_id ) {
this.send( { action: 'restart', hugvey: hv_id } );
}
finish( hv_id ) {
this.send( { action: 'finish', hugvey: hv_id } );
}
change_language( hv_id, lang_code ) {
this.send( { action: 'change_language', hugvey: hv_id, lang_code: lang_code } );
}