diff --git a/hugvey/central_command.py b/hugvey/central_command.py index 8866b10..e69cec2 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -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): diff --git a/hugvey/panopticon.py b/hugvey/panopticon.py index da1fdb4..d95daed 100644 --- a/hugvey/panopticon.py +++ b/hugvey/panopticon.py @@ -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)}) diff --git a/server_config.yml b/server_config.yml index 2d6f3e7..1523212 100644 --- a/server_config.yml +++ b/server_config.yml @@ -32,3 +32,5 @@ web: light: ip: "192.168.178.15" port: 7400 +story: + loop: true \ No newline at end of file diff --git a/www/css/styles.css b/www/css/styles.css index a8fc216..0b2befa 100644 --- a/www/css/styles.css +++ b/www/css/styles.css @@ -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; diff --git a/www/index.html b/www/index.html index c6ff202..068c001 100644 --- a/www/index.html +++ b/www/index.html @@ -30,7 +30,7 @@

diff --git a/www/js/crel.min.js b/www/js/crel.min.js index 739d68c..f451ebb 100644 --- a/www/js/crel.min.js +++ b/www/js/crel.min.js @@ -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)); diff --git a/www/js/hugvey_console.js b/www/js/hugvey_console.js index 2515536..2695aed 100644 --- a/www/js/hugvey_console.js +++ b/www/js/hugvey_console.js @@ -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 = []; diff --git a/www/panopticon.html b/www/panopticon.html index 3196a97..efc6826 100644 --- a/www/panopticon.html +++ b/www/panopticon.html @@ -23,7 +23,7 @@

@@ -69,7 +69,11 @@ -
Light:
+
+ Light: + + +

diff --git a/www/scss/styles.scss b/www/scss/styles.scss index 10845e0..3965f1d 100644 --- a/www/scss/styles.scss +++ b/www/scss/styles.scss @@ -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)); +// } } }