Skip to content

Commit

Permalink
feat(ui): reset one/all configuration buttons
Browse files Browse the repository at this point in the history
Fixes #3076
  • Loading branch information
robertsLando committed May 22, 2023
1 parent 42baeff commit 765794e
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/components/ValueId.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<div>
<v-subheader class="valueid-label">{{ label }} </v-subheader>

<v-btn
@click="resetConfig"
v-if="canResetConfiguration"
x-small
color="error"
>Reset</v-btn
>

<!-- Not writeable value -->
<div v-if="!value.writeable">
<div class="readonly mt-5">
Expand Down Expand Up @@ -375,6 +383,14 @@ export default {
this.value.states?.find((s) => s.value === 0)
)
},
canResetConfiguration() {
if (!this.value || this.disable_send) return false
return (
this.value.commandClass === 112 &&
this.value.commandClassVersion > 3
)
},
items() {
if (this.selectedItem) {
return this.value.states
Expand Down Expand Up @@ -451,6 +467,22 @@ export default {
},
},
methods: {
async resetConfig() {
const app = manager.getInstance(instances.APP)
const response = await app.apiRequest('sendCommand', [
{
nodeId: this.node.id,
commandClass: 112,
},
'reset',
[this.value.property],
])
if (response.success) {
useBaseStore().showSnackbar('Configuration reset', 'success')
}
},
async idleNotification() {
const app = manager.getInstance(instances.APP)
Expand Down
65 changes: 65 additions & 0 deletions src/components/nodes-table/NodeDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@
{{ className }}
</v-col>
<v-col class="text-right pr-5">
<v-btn
v-if="canResetConfig(group[0])"
@click.stop="resetAllConfig()"
color="error"
outlined
x-small
>
Reset
<v-icon x-small right>clear</v-icon>
</v-btn>
<v-btn
v-if="group[0]"
@click.stop="
Expand Down Expand Up @@ -237,6 +247,15 @@
<v-subheader class="valueid-label"
>Custom Configuration
</v-subheader>

<v-btn
@click="resetConfig"
v-if="canResetConfig(group[0])"
x-small
color="error"
>Reset</v-btn
>

<v-row>
<v-col cols="3">
<v-text-field
Expand Down Expand Up @@ -407,6 +426,52 @@ export default {
this.showSnackbar('Powerlevel updated', 'success')
}
},
canResetConfig(value) {
return (
value &&
value.commandClass === 112 &&
value.commandClassVersion > 3
)
},
async resetAllConfig() {
if (
await this.app.confirm(
'Attention',
'Are you sure you want to reset all configurations to default?',
'alert'
)
) {
const response = await this.app.apiRequest('sendCommand', [
{
nodeId: this.node.id,
commandClass: 112,
},
'resetAll',
[],
])
if (response.success) {
this.showSnackbar('All config values resetted', 'success')
}
}
},
async resetConfig() {
const response = await this.app.apiRequest('sendCommand', [
{
nodeId: this.node.id,
commandClass: 112,
},
'reset',
[this.configCC.parameter],
])
if (response.success) {
this.showSnackbar(
`Parameter ${this.configCC.parameter}: resetted`,
'success'
)
}
},
async refreshCCValues(cc) {
const response = await this.app.apiRequest('refreshCCValues', [
this.node.id,
Expand Down

0 comments on commit 765794e

Please sign in to comment.