Story now loops if configured to do so. Also light controls to Panopticon

This commit is contained in:
Ruben van de Ven 2019-06-08 17:20:47 +02:00
parent 39dbf0502a
commit 8ca727b015
9 changed files with 52 additions and 13 deletions

View file

@ -118,7 +118,9 @@ class CentralCommand(object):
# status['status'] = 'off'
# return status
#: :type hv: HugveyState
status['status'] = hv.getStatus()
status['light_on'] = bool(hv.lightStatus)
status['language'] = hv.language_code
status['light_id'] = hv.lightId
status['msg'] = hv.story.currentMessage.id if hv.story and hv.story.currentMessage else None
@ -280,6 +282,7 @@ class CentralCommand(object):
if not r:
# stop if False, ie. when stream has gone
return
logger.critical(f'Hugvey stopped (crashed?). Reinstantiate after 5 sec')
time.sleep(5)
@ -438,8 +441,9 @@ class HugveyState(object):
self.recorder = None
self.notShuttingDown = True # TODO: allow shutdown of object
self.startMsgId = None
self.lightStatus = 0
self.eventLogger = eventLogger.getChild(f"{self.id}")
self.setStatus(self.STATE_GONE)
self.requireRestartAfterStop = None
@ -452,8 +456,12 @@ class HugveyState(object):
def setStatus(self, status):
self.status = status
lightOn = status in [self.STATE_AVAILABLE, self.STATE_PAUSE]
self.setLightStatus(lightOn)
# if the story is looping, light should not go off when the story starts
if status != self.STATE_RUNNING or self.command.config['story']['loop'] is False:
lightOn = status in [self.STATE_AVAILABLE, self.STATE_PAUSE]
self.setLightStatus(lightOn)
self.eventLogger.info(f"status: {self.status}")
def config(self, hostname, ip):
@ -466,7 +474,7 @@ class HugveyState(object):
else:
self.logger.info(
f"Hugvey {self.id} at {self.ip}, host: {self.hostname}")
if self.status == self.STATE_GONE:
# turn on :-)
self.setStatus(self.STATE_BLOCKED)
@ -503,6 +511,7 @@ class HugveyState(object):
# restart
# TODO: test proper functioning
self.shutdown()
def queueEvent(self, msg):
if 'time' not in msg:
@ -572,6 +581,8 @@ class HugveyState(object):
self.setLanguage(event['lang_code'])
if event['event'] == 'change_light':
self.setLightId(event['light_id'])
if event['event'] == 'change_light_status':
self.setLightStatus(event['status'])
if event['event'] == 'play_msg':
self.logger.info(f"Play given message {event['msg_id']}")
if not self.story:
@ -654,10 +665,10 @@ class HugveyState(object):
self.setStatus(self.STATE_AVAILABLE)
def setLightStatus(self, on):
status = 1 if on else 0
self.logger.log(LOG_BS, f"Send /hugvey {status}")
self.lightStatus = 1 if on else 0
self.logger.log(LOG_BS, f"Send /hugvey {self.lightStatus}")
self.command.commandLight('/hugvey', [self.lightId, status])
self.command.commandLight('/hugvey', [self.lightId, self.lightStatus])
def setLightId(self, id):
"""
@ -740,6 +751,10 @@ class HugveyState(object):
self.setLightStatus(False)
await self.story.run(startMsgId, resuming)
if self.command.config['story']['loop']:
self.logger.info("Loop story")
self.restart()
# self.story = None
def getStreamer(self):

View file

@ -71,6 +71,8 @@ def getWebSocketHandler(central_command):
self.msgChangeLanguage(msg['hugvey'], msg['lang_code'])
elif msg['action'] == 'change_light':
self.msgChangeLightId(msg['hugvey'], int(msg['light_id']))
elif msg['action'] == 'change_light_status':
self.msgChangeLightStatus(msg['hugvey'], bool(msg['light_status']))
elif msg['action'] == 'play_msg':
self.msgPlayMsg(msg['hugvey'], msg['msg_id'], msg['reloadStory'])
else:
@ -135,6 +137,9 @@ def getWebSocketHandler(central_command):
def msgChangeLightId(self, hv_id, lightId):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_light', 'light_id': lightId})
def msgChangeLightStatus(self, hv_id, status):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_light_status', 'status': status})
def msgPlayMsg(self, hv_id, msg_id, reloadStory):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'play_msg', 'msg_id': msg_id, 'reloadStory':bool(reloadStory)})

View file

@ -32,3 +32,5 @@ web:
light:
ip: "192.168.178.15"
port: 7400
story:
loop: true

View file

@ -96,7 +96,7 @@ img.icon {
left: 5px;
top: 5px; }
#status .hugvey .status {
font-sytle: italic;
font-style: italic;
color: gray;
position: absolute;
top: 10px;

View file

@ -30,7 +30,7 @@
</div>
<div class='hugvey' v-for="hv in hugveys"
:class="[{'hugvey--on': hv.status != 'off'},'hugvey--' + hv.status]"
:class="[{'hugvey--on': hv.status != 'off'},'hugvey--' + hv.status, 'hugvey--light-' + hv.light_on]"
@click="showHugvey(hv)"
>
<h1>

2
www/js/crel.min.js vendored
View file

@ -9,7 +9,7 @@ crel.attrMap['options'] = function(element, values) {
if(element.tagName != "SELECT") {
return;
}
console.log(values);
console.log(values, element.value);
if(Array.isArray(values)) {
for (let option of values) {
element.appendChild(crel('option', option));

View file

@ -67,6 +67,11 @@ class Panopticon {
console.log(hv_id, light_id, this);
return panopticon.change_light_id(hv_id, light_id);
},
change_light_status: function(e) {
let hv_id = parseInt(e.target.dataset.hvid);
let checked = e.target.checked;
panopticon.send( { action: 'change_light_status', hugvey: hv_id, light_status: checked } );
},
showHugvey: function(hv) {
panopticon.selectHugvey(hv.language ? hv.id : null);
panopticon.hugveys.logbook = [];

View file

@ -23,7 +23,7 @@
</div>
<div class='hugvey' v-for="hv in hugveys"
:class="[{'hugvey--on': hv.status != 'off'},'hugvey--' + hv.status]"
:class="[{'hugvey--on': hv.status != 'off'},'hugvey--' + hv.status, 'hugvey--light-' + hv.light_on]"
@click="showHugvey(hv)"
>
<h1>
@ -69,7 +69,11 @@
<!-- <div class='light'>
{{ hv.light }}
</div> -->
<div class='light'>Light: <input type="number" step="1" :value="hv.light_id" @change="change_light" :data-hvid="hv.id" v-on:click.stop></div>
<div class='light'>
Light:
<input type="number" step="1" :value="hv.light_id" @change="change_light" :data-hvid="hv.id" v-on:click.stop>
<input type="checkbox" v-model="hv.light_on" @change="change_light_status" :data-hvid="hv.id" v-on:click.stop>
</div>
</div>
</div>
</div>

View file

@ -136,7 +136,7 @@ img.icon{
}
.status{
font-sytle: italic;
font-style: italic;
color: gray;
position: absolute;
top: 10px;
@ -208,6 +208,14 @@ img.icon{
background-image: linear-gradient(to top, #587457, #e2f04a);
}
// TODO
// &.hugvey--light-false{
// background-image: linear-gradient(to top, #ccc, rgba(255,255,255,0));
// }
// &.hugvey--light-true{
// background-image: linear-gradient(to top, , rgba(255,255,255,0));
// }
}
}