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): def getStatusSummary(self, selected_id = None):
status = { status = {
'uptime': time.time() - self.start_time, 'uptime': "-" if not self.start_time else (time.time() - self.start_time),
'languages': self.config['languages'], 'languages': self.config['languages'],
'hugvey_ids': self.hugvey_ids, 'hugvey_ids': self.hugvey_ids,
'hugveys': [], 'hugveys': [],
@ -205,6 +205,34 @@ class CentralCommand(object):
# (re)configure exisitng hugveys # (re)configure exisitng hugveys
h.config(msg['host'], msg['ip']) 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): async def eventListener(self):
s = self.ctx.socket(zmq.SUB) s = self.ctx.socket(zmq.SUB)
s.bind(self.config['events']['listen_address']) s.bind(self.config['events']['listen_address'])
@ -301,6 +329,7 @@ class HugveyState(object):
STATE_PAUSE = "paused" STATE_PAUSE = "paused"
STATE_GONE = "gone" STATE_GONE = "gone"
STATE_RUNNING = "running" STATE_RUNNING = "running"
STATE_FINISHED = "finished"
def __init__(self, id: int, command: CentralCommand): def __init__(self, id: int, command: CentralCommand):
self.id = id self.id = id
@ -322,7 +351,7 @@ class HugveyState(object):
def getStatus(self): def getStatus(self):
if self.story.isFinished(): if self.story.isFinished():
return "finished" return self.STATE_FINISHED
return self.status return self.status
def config(self, hostname, ip): def config(self, hostname, ip):
@ -362,7 +391,7 @@ class HugveyState(object):
async def catchException(self, awaitable): async def catchException(self, awaitable):
try: try:
print(awaitable) # print(awaitable)
await awaitable await awaitable
except Exception as e: except Exception as e:
self.logger.exception(e) self.logger.exception(e)
@ -403,6 +432,8 @@ class HugveyState(object):
self.pause() self.pause()
if event['event'] == 'restart': if event['event'] == 'restart':
self.restart() self.restart()
if event['event'] == 'finish':
self.finish()
if event['event'] == 'resume': if event['event'] == 'resume':
self.resume() self.resume()
@ -475,6 +506,15 @@ class HugveyState(object):
self.resume() self.resume()
self.isRunning.set() 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): def gone(self):
'''Status to 'gone' as in, shutdown/crashed/whatever '''Status to 'gone' as in, shutdown/crashed/whatever
''' '''

View file

@ -313,16 +313,16 @@ class CommandHandler(object):
self.playPopen = None self.playPopen = None
else: else:
logger.info("Speak: {}".format(text)) logger.info("Speak: {}".format(text))
playCmd = ['espeak', '-p', '{0}'.format(pitch), text]
self.playPopen = subprocess.Popen( self.playPopen = subprocess.Popen(
['espeak', '-p', '{0}'.format(pitch), text], stdout=subprocess.PIPE) playCmd, stdout=subprocess.PIPE)
returnCode = self.playPopen.wait() returnCode = self.playPopen.wait()
self.playPopen = None self.playPopen = None
if returnCode: if returnCode:
logger.critical("Had returncode on play: {}".format(returnCode)) logger.critical("Had returncode {} on play: {}".format(returnCode, playCmd))
else: else:
logger.debug( logger.debug("Finished playback.")
"Finished playback. Return code: {}".format(returnCode))
self.playingMsgId = None self.playingMsgId = None
self.muteMic = False self.muteMic = False

View file

@ -58,6 +58,8 @@ def getWebSocketHandler(central_command):
self.msgPause(msg['hugvey']) self.msgPause(msg['hugvey'])
elif msg['action'] == 'restart': elif msg['action'] == 'restart':
self.msgRestart(msg['hugvey']) self.msgRestart(msg['hugvey'])
elif msg['action'] == 'finish':
self.msgFinish(msg['hugvey'])
elif msg['action'] == 'change_language': elif msg['action'] == 'change_language':
self.msgChangeLanguage(msg['hugvey'], msg['lang_code']) self.msgChangeLanguage(msg['hugvey'], msg['lang_code'])
elif msg['action'] == 'play_msg': elif msg['action'] == 'play_msg':
@ -102,6 +104,9 @@ def getWebSocketHandler(central_command):
def msgRestart(self, hv_id): def msgRestart(self, hv_id):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'restart'}) 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): def msgChangeLanguage(self, hv_id, lang_code):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_language', 'lang_code': 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.hugvey.pause()
self.finish_time = time.time() self.finish_time = time.time()
self.timer.pause() 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 == '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 == '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 == 'finished'" @click.stop="restart(hv)">Restart</div>
<div class='btn' v-if="hv.status == 'running'" @click.stop="finish(hv)">Finish</div>
</div> </div>
</div> </div>
</div> </div>

View file

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