Allow to change the id of the light per hugvey Fix #41

This commit is contained in:
Ruben van de Ven 2019-05-10 16:59:14 +02:00
parent 627e0ffbe9
commit 735a63683d
4 changed files with 34 additions and 4 deletions

View file

@ -119,6 +119,7 @@ class CentralCommand(object):
status['status'] = hv.getStatus() status['status'] = hv.getStatus()
status['language'] = hv.language_code 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['msg'] = hv.story.currentMessage.id if hv.story and hv.story.currentMessage else None
# status['finished'] = hv.story.isFinished() # status['finished'] = hv.story.isFinished()
status['history'] = {} if isSelected is False or not hv.story else hv.story.getLogSummary() 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): def __init__(self, id: int, command: CentralCommand):
self.id = id self.id = id
self.lightId = id
self.command = command self.command = command
self.logger = mainLogger.getChild(f"{self.id}").getChild("command") self.logger = mainLogger.getChild(f"{self.id}").getChild("command")
self.loop = asyncio.new_event_loop() self.loop = asyncio.new_event_loop()
@ -544,6 +546,8 @@ class HugveyState(object):
if event['event'] == 'change_language': if event['event'] == 'change_language':
self.setLanguage(event['lang_code']) self.setLanguage(event['lang_code'])
if event['event'] == 'change_light':
self.setLightId(event['light_id'])
if event['event'] == 'play_msg': if event['event'] == 'play_msg':
self.logger.info(f"Play given message {event['msg_id']}") self.logger.info(f"Play given message {event['msg_id']}")
if not self.story: if not self.story:
@ -621,7 +625,13 @@ class HugveyState(object):
status = 1 if on else 0 status = 1 if on else 0
self.logger.log(LOG_BS, f"Send /hugvey {status}") 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): def gone(self):
'''Status to 'gone' as in, shutdown/crashed/whatever '''Status to 'gone' as in, shutdown/crashed/whatever

View file

@ -66,6 +66,8 @@ def getWebSocketHandler(central_command):
self.msgFinish(msg['hugvey']) 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'] == 'change_light':
self.msgChangeLightId(msg['hugvey'], int(msg['light_id']))
elif msg['action'] == 'play_msg': elif msg['action'] == 'play_msg':
self.msgPlayMsg(msg['hugvey'], msg['msg_id']) self.msgPlayMsg(msg['hugvey'], msg['msg_id'])
else: else:
@ -120,6 +122,9 @@ def getWebSocketHandler(central_command):
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})
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): def msgPlayMsg(self, hv_id, msg_id):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'play_msg', 'msg_id': msg_id}) central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'play_msg', 'msg_id': msg_id})

View file

@ -14,6 +14,7 @@ class Panopticon {
hugveys: [], hugveys: [],
selectedId: null, selectedId: null,
logbook: "", logbook: "",
logbookId: null,
}, },
methods: { methods: {
time_passed: function( hugvey, property ) { time_passed: function( hugvey, property ) {
@ -60,6 +61,12 @@ class Panopticon {
hv.status = "loading"; hv.status = "loading";
return panopticon.change_language(hv.id, lang_code); 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) { showHugvey: function(hv) {
panopticon.hugveys.selectedId = hv.language ? hv.id : null; panopticon.hugveys.selectedId = hv.language ? hv.id : null;
panopticon.hugveys.logbook = []; panopticon.hugveys.logbook = [];
@ -222,6 +229,10 @@ class Panopticon {
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 } );
} }
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) { playFromSelected(msg_id) {
if(!this.hugveys.selectedId) { if(!this.hugveys.selectedId) {

View file

@ -39,6 +39,9 @@
</option> </option>
</select> </select>
{{ hv.language }} {{ hv.language }}
<!-- <div v-if="hv.awaiting != false"><img class='icon' :src="'/images/icon-finished.svg'" title="Finished"> {{timer(hv, <!-- <div v-if="hv.awaiting != false"><img class='icon' :src="'/images/icon-finished.svg'" title="Finished"> {{timer(hv,
'finished')}}</div> --> 'finished')}}</div> -->
<div class='stats'> <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="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 == '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='light'> <!-- <div class='light'>
{{ hv.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> </div>
</div> </div>
@ -72,7 +76,7 @@
<h1>Log of {{logbookId}}</h1> <h1>Log of {{logbookId}}</h1>
<div v-for="log in logbook" class='log'> <div v-for="log in logbook" class='log'>
<div class='time'>{{formatted(log.time)}}</div> <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='origin'>{{log.origin}}</span>
<span class='msg'>{{log.msg}}</span> <span class='msg'>{{log.msg}}</span>
<span v-if="log.extra" class='extra'>( {{log.extra}} )</span> <span v-if="log.extra" class='extra'>( {{log.extra}} )</span>