Save light status (not properly restored yet) and clearer status in timeline when running in a loop

This commit is contained in:
Ruben van de Ven 2019-06-14 20:47:59 +02:00
parent 5af386212e
commit 5ca3cffdd9
4 changed files with 12 additions and 3 deletions

View File

@ -123,6 +123,7 @@ class CentralCommand(object):
status['light_on'] = bool(hv.lightStatus) status['light_on'] = bool(hv.lightStatus)
status['language'] = hv.language_code status['language'] = hv.language_code
status['light_id'] = hv.lightId status['light_id'] = hv.lightId
status['available'] = hv.isAvailable()
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()

View File

@ -1782,6 +1782,7 @@ class Story(object):
fn = self.getStateFilename(self.hugvey.lightId) fn = self.getStateFilename(self.hugvey.lightId)
tmpfn = fn + '.tmp' tmpfn = fn + '.tmp'
self.stateSave = time.time() self.stateSave = time.time()
self.lightStateSave = self.hugvey.lightStatus
with open(tmpfn, 'wb') as fp: with open(tmpfn, 'wb') as fp:
pickle.dump(self, fp) pickle.dump(self, fp)
# write atomic to disk: flush, close, rename # write atomic to disk: flush, close, rename
@ -1805,9 +1806,11 @@ class Story(object):
story = pickle.load(fp) story = pickle.load(fp)
story.hugvey = hugvey_state story.hugvey = hugvey_state
#: :type story: Story
story.logger = mainLogger.getChild(f"{story.hugvey.id}").getChild("story") story.logger = mainLogger.getChild(f"{story.hugvey.id}").getChild("story")
# TODO: this is not really working because it is overridden by the set-status later.
story.hugvey.setLightStatus(story.lightStateSave)
return story return story
# TODO: take running state etc.
@classmethod @classmethod
def clearSavedState(cls, hv_id): def clearSavedState(cls, hv_id):

View File

@ -95,8 +95,9 @@ checkbox.addEventListener('change', (event) => {
if(msg['action'] == 'status') { if(msg['action'] == 'status') {
for(let hv of msg['hugveys']){ for(let hv of msg['hugveys']){
console.log(hv['language'], hv['status']); console.log(hv['language'], hv['status']);
let evenOdd = parseInt(hv['id'])%2 ? 'odd': 'even' let evenOdd = parseInt(hv['id'])%2 ? 'odd': 'even';
this.dataGroups.update({id: parseInt(hv['id']), content: 'Hugvey #'+hv['id'], className: `status-${hv['status']} lang-${hv['language']} ${evenOdd}`}) let availableClass = hv['available'] ? 'is-available' : 'is-not-available'
this.dataGroups.update({id: parseInt(hv['id']), content: 'Hugvey #'+hv['id'], className: `status-${hv['status']} ${availableClass} lang-${hv['language']} ${evenOdd}`})
} }
} }

View File

@ -98,6 +98,10 @@ font-size: 20pt;
.status-available{ .status-available{
background-color: #660; background-color: #660;
} }
.status-running.is-available{
/* When running in a loop, Hugvey is listening while available */
background-color: #246f6f !important;
}
.status-running.lang-en-GB{ .status-running.lang-en-GB{
background-color: #02547e; background-color: #02547e;