forked from platypush/platypush
Handle EntityUpdateEvents on the UI
This commit is contained in:
parent
be4d1e8e01
commit
72617b4b75
2 changed files with 21 additions and 6 deletions
|
@ -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()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue