From 897338399f5a2f2c83b573f27d10e8d9ece39e25 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 23 May 2019 19:34:42 +0200 Subject: [PATCH] Synchronize all lights toggles when scenes are selected --- .../http/static/js/plugins/light.hue/index.js | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/platypush/backend/http/static/js/plugins/light.hue/index.js b/platypush/backend/http/static/js/plugins/light.hue/index.js index 242a9b1072..047d295211 100644 --- a/platypush/backend/http/static/js/plugins/light.hue/index.js +++ b/platypush/backend/http/static/js/plugins/light.hue/index.js @@ -121,8 +121,33 @@ Vue.component('light-hue', { ); this.selectedScene = event.id; - for (const light of Object.values(this.scenes[this.selectedScene].lights)) { - this.lights[light].state.on = true; + groups = {} + + for (const lightId of Object.values(this.scenes[this.selectedScene].lights)) { + this.lights[lightId].state.on = true; + + for (const [groupId, group] of Object.entries(this.lights[lightId].groups)) { + if (!(group.id in groups)) { + groups[groupId] = { + any_on: true, + all_on: group.state.all_on, + lights: [], + } + } + + groups[groupId].lights.push(lightId) + if (groups[groupId].lights.length == Object.values(group.lights).length) { + groups[groupId].all_on = true; + } + } + } + + for (const [id, group] of Object.entries(groups)) { + this.groups[id].state = { + ...group.state, + any_on: group.any_on, + any_off: group.any_off, + } } },