Fixed modified property Vue warning

This commit is contained in:
Fabio Manganiello 2020-12-15 21:32:39 +01:00
parent 5d4f4b0378
commit 049a48e156
2 changed files with 19 additions and 9 deletions

View File

@ -31,7 +31,7 @@ export default {
components: {Group, Groups}, components: {Group, Groups},
mixins: [Utils, Panel], mixins: [Utils, Panel],
emits: ['group-toggle', 'light-toggle', 'set-light', 'set-group', 'select-scene', 'start-animation', 'stop-animation', emits: ['group-toggle', 'light-toggle', 'set-light', 'set-group', 'select-scene', 'start-animation', 'stop-animation',
'refresh'], 'refresh', 'light-changed'],
props: { props: {
lights: { lights: {
@ -182,13 +182,16 @@ export default {
return return
} }
delete event.plugin_name const state = {...event}
delete event.type const lightId = state.light_id
delete state.light_id
delete state.type
delete state.plugin_name
this.lights[event.light_id].state = { this.$emit('light-changed', {
...(this.lights[event.light_id]?.state || {}), id: lightId,
...event, state: state,
} })
}, },
onAnimationChange(event) { onAnimationChange(event) {
@ -209,7 +212,7 @@ export default {
this.initSelectedGroup() this.initSelectedGroup()
}, },
destroyed() { unmounted() {
this.unsubscribe('on-light-change') this.unsubscribe('on-light-change')
this.unsubscribe('on-animation-change') this.unsubscribe('on-animation-change')
}, },

View File

@ -2,7 +2,7 @@
<Loading v-if="loading" /> <Loading v-if="loading" />
<LightPlugin plugin-name="light.hue" :config="config" :lights="lights" :groups="groups" :scenes="scenes" <LightPlugin plugin-name="light.hue" :config="config" :lights="lights" :groups="groups" :scenes="scenes"
:animations="animations" :initial-group="initialGroup" :loading-groups="loadingGroups" :animations="animations" :initial-group="initialGroup" :loading-groups="loadingGroups"
:color-converter="colorConverter" @group-toggle="toggleGroup" :color-converter="colorConverter" @group-toggle="toggleGroup" @light-changed="onLightChanged"
@light-toggle="toggleLight" @set-light="setLight" @set-group="setGroup" @select-scene="setScene" @light-toggle="toggleLight" @set-light="setLight" @set-group="setGroup" @select-scene="setScene"
@start-animation="startAnimation" @stop-animation="stopAnimation" @refresh="refresh(true)"/> @start-animation="startAnimation" @stop-animation="stopAnimation" @refresh="refresh(true)"/>
</template> </template>
@ -217,6 +217,13 @@ export default {
await this.request('light.hue.stop_animation') await this.request('light.hue.stop_animation')
await this.refresh(true) await this.refresh(true)
}, },
onLightChanged(event) {
this.lights[event.id].state = {
...this.lights[event.id].state,
...event.state,
}
},
}, },
mounted() { mounted() {