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
}
},
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() {
this.subscribe(
this.onEntityUpdate,
'on-entity-update',
'platypush.message.event.entities.EntityUpdateEvent'
)
this.refresh()
},
}

View File

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