Show error when set state fails (#17850)

This commit is contained in:
Bram Kragten 2023-09-11 18:13:36 +02:00 committed by GitHub
parent 2352d05573
commit 24d401061c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ import "../../../components/ha-icon-button";
import "../../../components/ha-svg-icon"; import "../../../components/ha-svg-icon";
import "../../../components/ha-checkbox"; import "../../../components/ha-checkbox";
import "../../../components/ha-tip"; import "../../../components/ha-tip";
import "../../../components/ha-alert";
import "../../../components/search-input"; import "../../../components/search-input";
import "../../../components/ha-expansion-panel"; import "../../../components/ha-expansion-panel";
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box"; import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
@ -185,6 +186,9 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
[[localize('ui.panel.developer-tools.tabs.states.description1')]]<br /> [[localize('ui.panel.developer-tools.tabs.states.description1')]]<br />
[[localize('ui.panel.developer-tools.tabs.states.description2')]] [[localize('ui.panel.developer-tools.tabs.states.description2')]]
</p> </p>
<template is="dom-if" if="[[_error]]">
<ha-alert alert-type="error">[[_error]]</ha-alert>
</template>
<div class="state-wrapper flex layout horizontal"> <div class="state-wrapper flex layout horizontal">
<div class="inputs"> <div class="inputs">
<ha-entity-picker <ha-entity-picker
@ -355,6 +359,11 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
computed: "_computeValidJSON(parsedJSON)", computed: "_computeValidJSON(parsedJSON)",
}, },
_error: {
type: String,
value: "",
},
_entityId: { _entityId: {
type: String, type: String,
value: "", value: "",
@ -490,7 +499,8 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
this.fire("hass-more-info", { entityId: ev.model.entity.entity_id }); this.fire("hass-more-info", { entityId: ev.model.entity.entity_id });
} }
handleSetState() { async handleSetState() {
this._error = "";
if (!this._entityId) { if (!this._entityId) {
showAlertDialog(this, { showAlertDialog(this, {
text: this.hass.localize( text: this.hass.localize(
@ -499,10 +509,14 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
}); });
return; return;
} }
this.hass.callApi("POST", "states/" + this._entityId, { try {
state: this._state, await this.hass.callApi("POST", "states/" + this._entityId, {
attributes: this.parsedJSON, state: this._state,
}); attributes: this.parsedJSON,
});
} catch (e) {
this._error = e.body?.message || "Unknown error";
}
} }
informationOutlineIcon() { informationOutlineIcon() {