From 735a63683d9bc94af5b8af9b2b3fde6dc13aa43b Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 10 May 2019 16:59:14 +0200 Subject: [PATCH] Allow to change the id of the light per hugvey Fix #41 --- hugvey/central_command.py | 12 +++++++++++- hugvey/panopticon.py | 5 +++++ www/js/hugvey_console.js | 11 +++++++++++ www/panopticon.html | 10 +++++++--- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/hugvey/central_command.py b/hugvey/central_command.py index 76b35f8..75fb60a 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -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 diff --git a/hugvey/panopticon.py b/hugvey/panopticon.py index 9eed054..64b6959 100644 --- a/hugvey/panopticon.py +++ b/hugvey/panopticon.py @@ -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}) diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index 7d16bf3..96054fb 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -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) { diff --git a/www/panopticon.html b/www/panopticon.html index 3c6610c..2655d9e 100644 --- a/www/panopticon.html +++ b/www/panopticon.html @@ -39,6 +39,9 @@ {{ hv.language }} + + +
@@ -61,9 +64,10 @@
Finish
Pause
Resume
-
+ +
Light:
@@ -72,7 +76,7 @@

Log of {{logbookId}}

{{formatted(log.time)}}
-
+
{{log.origin}} {{log.msg}} ( {{log.extra}} )