Allow to change the id of the light per hugvey Fix #41
This commit is contained in:
parent
627e0ffbe9
commit
735a63683d
4 changed files with 34 additions and 4 deletions
|
@ -119,6 +119,7 @@ class CentralCommand(object):
|
|||
|
||||
status['status'] = hv.getStatus()
|
||||
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
|
||||
# status['finished'] = hv.story.isFinished()
|
||||
status['history'] = {} if isSelected is False or not hv.story else hv.story.getLogSummary()
|
||||
|
@ -396,6 +397,7 @@ class HugveyState(object):
|
|||
|
||||
def __init__(self, id: int, command: CentralCommand):
|
||||
self.id = id
|
||||
self.lightId = id
|
||||
self.command = command
|
||||
self.logger = mainLogger.getChild(f"{self.id}").getChild("command")
|
||||
self.loop = asyncio.new_event_loop()
|
||||
|
@ -544,6 +546,8 @@ class HugveyState(object):
|
|||
|
||||
if event['event'] == 'change_language':
|
||||
self.setLanguage(event['lang_code'])
|
||||
if event['event'] == 'change_light':
|
||||
self.setLightId(event['light_id'])
|
||||
if event['event'] == 'play_msg':
|
||||
self.logger.info(f"Play given message {event['msg_id']}")
|
||||
if not self.story:
|
||||
|
@ -621,7 +625,13 @@ class HugveyState(object):
|
|||
status = 1 if on else 0
|
||||
self.logger.log(LOG_BS, f"Send /hugvey {status}")
|
||||
|
||||
self.command.commandLight('/hugvey', [self.id, status])
|
||||
self.command.commandLight('/hugvey', [self.lightId, status])
|
||||
|
||||
def setLightId(self, id):
|
||||
"""
|
||||
Connect hugvey to another light
|
||||
"""
|
||||
self.lightId = id
|
||||
|
||||
def gone(self):
|
||||
'''Status to 'gone' as in, shutdown/crashed/whatever
|
||||
|
|
|
@ -66,6 +66,8 @@ def getWebSocketHandler(central_command):
|
|||
self.msgFinish(msg['hugvey'])
|
||||
elif msg['action'] == 'change_language':
|
||||
self.msgChangeLanguage(msg['hugvey'], msg['lang_code'])
|
||||
elif msg['action'] == 'change_light':
|
||||
self.msgChangeLightId(msg['hugvey'], int(msg['light_id']))
|
||||
elif msg['action'] == 'play_msg':
|
||||
self.msgPlayMsg(msg['hugvey'], msg['msg_id'])
|
||||
else:
|
||||
|
@ -119,6 +121,9 @@ def getWebSocketHandler(central_command):
|
|||
|
||||
def msgChangeLanguage(self, hv_id, lang_code):
|
||||
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_language', 'lang_code': lang_code})
|
||||
|
||||
def msgChangeLightId(self, hv_id, lightId):
|
||||
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_light', 'light_id': lightId})
|
||||
|
||||
def msgPlayMsg(self, hv_id, msg_id):
|
||||
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'play_msg', 'msg_id': msg_id})
|
||||
|
|
|
@ -14,6 +14,7 @@ class Panopticon {
|
|||
hugveys: [],
|
||||
selectedId: null,
|
||||
logbook: "",
|
||||
logbookId: null,
|
||||
},
|
||||
methods: {
|
||||
time_passed: function( hugvey, property ) {
|
||||
|
@ -60,6 +61,12 @@ class Panopticon {
|
|||
hv.status = "loading";
|
||||
return panopticon.change_language(hv.id, lang_code);
|
||||
},
|
||||
change_light: function(e) {
|
||||
let hv_id = parseInt(e.target.dataset.hvid);
|
||||
let light_id = parseInt(e.target.value);
|
||||
console.log(hv_id, light_id, this);
|
||||
return panopticon.change_light_id(hv_id, light_id);
|
||||
},
|
||||
showHugvey: function(hv) {
|
||||
panopticon.hugveys.selectedId = hv.language ? hv.id : null;
|
||||
panopticon.hugveys.logbook = [];
|
||||
|
@ -222,6 +229,10 @@ class Panopticon {
|
|||
change_language( hv_id, lang_code ) {
|
||||
this.send( { action: 'change_language', hugvey: hv_id, lang_code: lang_code } );
|
||||
}
|
||||
change_light_id( hv_id, light_id ) {
|
||||
console.log("Light", hv_id, light_id);
|
||||
this.send( { action: 'change_light', hugvey: hv_id, light_id: light_id } );
|
||||
}
|
||||
|
||||
playFromSelected(msg_id) {
|
||||
if(!this.hugveys.selectedId) {
|
||||
|
|
|
@ -39,6 +39,9 @@
|
|||
</option>
|
||||
</select>
|
||||
{{ hv.language }}
|
||||
|
||||
|
||||
|
||||
<!-- <div v-if="hv.awaiting != false"><img class='icon' :src="'/images/icon-finished.svg'" title="Finished"> {{timer(hv,
|
||||
'finished')}}</div> -->
|
||||
<div class='stats'>
|
||||
|
@ -61,9 +64,10 @@
|
|||
<div class='btn' v-if="hv.status == 'running'" @click.stop="finish(hv)">Finish</div> <!-- to available state -->
|
||||
<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='light'>
|
||||
<!-- <div class='light'>
|
||||
{{ hv.light }}
|
||||
</div>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -72,7 +76,7 @@
|
|||
<h1>Log of {{logbookId}}</h1>
|
||||
<div v-for="log in logbook" class='log'>
|
||||
<div class='time'>{{formatted(log.time)}}</div>
|
||||
<div class='content {{log.origin}}'>
|
||||
<div :class="['content', log.origin]">
|
||||
<span class='origin'>{{log.origin}}</span>
|
||||
<span class='msg'>{{log.msg}}</span>
|
||||
<span v-if="log.extra" class='extra'>( {{log.extra}} )</span>
|
||||
|
|
Loading…
Reference in a new issue