Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): allow to toggle persistent/discovery fields from HA discovery table #3569

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 43 additions & 12 deletions src/components/nodes-table/HomeAssistant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,23 @@
{{ item.object_id }}
</template>
<template v-slot:[`item.persistent`]="{ item }">
{{ item.persistent ? 'Yes' : 'No' }}
<v-checkbox
v-model="item.persistent"
@click.stop
@change="updateDevice(item)"
hide-details
dense
></v-checkbox>
</template>
<template v-slot:[`item.ignoreDiscovery`]="{ item }">
{{ item.ignoreDiscovery ? 'Disabled' : 'Enabled' }}
<v-btn
@click.stop="toggleField(item, 'ignoreDiscovery')"
:color="item.ignoreDiscovery ? 'error' : 'success'"
rounded
x-small
>
{{ item.ignoreDiscovery ? 'Disabled' : 'Enabled' }}
</v-btn>
</template>
</v-data-table>
</v-col>
Expand All @@ -115,7 +128,7 @@
color="blue darken-1"
:disabled="errorDevice"
text
@click="addDevice"
@click="addDevice()"
>Add</v-btn
>
</template>
Expand All @@ -129,7 +142,7 @@
color="blue darken-1"
:disabled="errorDevice"
text
@click="updateDevice"
@click="updateDeviceJSON()"
>Update</v-btn
>
</template>
Expand Down Expand Up @@ -373,23 +386,41 @@ export default {
)
}
},
async updateDevice() {
async updateDeviceJSON() {
if (!this.errorDevice) {
const updated = JSON.parse(this.deviceJSON)
this.$set(
this.node.hassDevices,
this.selectedDevice.id,
updated,
)
const response = await this.sendAction({
apiName: 'update',
device: updated,
nodeId: this.node.id,
})
await this.updateDevice(updated)
}
},
async toggleField(device, field) {
device[field] = !device[field]
await this.updateDevice(device)
},
async updateDevice(device) {
const response = await this.sendAction({
apiName: 'update',
device,
nodeId: this.node.id,
})

if (response.success) {
this.showSnackbar(`Device ${updated.id} updated`, 'success')
if (response.success) {
this.node.hassDevices = {
...this.node.hassDevices,
[device.id]: device,
}

if (
this.selectedDevice &&
this.selectedDevice.id === device.id
) {
this.deviceJSON = JSON.stringify(device, null, 2)
}
this.showSnackbar(`Device ${device.id} updated`, 'success')
}
},
validJSONdevice() {
Expand Down
Loading