Handle EntityUpdateEvents on the UI

This commit is contained in:
Fabio Manganiello 2022-04-11 23:16:29 +02:00
parent be4d1e8e01
commit 72617b4b75
Signed by: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 21 additions and 6 deletions

View file

@ -136,9 +136,29 @@ export default {
this.loading = false this.loading = false
} }
}, },
onEntityUpdate(event) {
const entityId = event.entity.id
if (entityId == null)
return
this.entities[entityId] = {
...event.entity,
meta: {
...(this.entities[entityId]?.meta || {}),
...(event.entity?.meta || {}),
},
}
},
}, },
mounted() { mounted() {
this.subscribe(
this.onEntityUpdate,
'on-entity-update',
'platypush.message.event.entities.EntityUpdateEvent'
)
this.refresh() this.refresh()
}, },
} }

View file

@ -34,15 +34,10 @@ export default {
methods: { methods: {
async toggle() { async toggle() {
const response = await this.request('entities.execute', { await this.request('entities.execute', {
id: this.value.id, id: this.value.id,
action: 'toggle', action: 'toggle',
}) })
this.$emit('input', {
...this.value,
state: response.on,
})
}, },
}, },
} }