mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Only update dev tools yaml editor on entity change or submit (#18575)
Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com>
This commit is contained in:
parent
00a311bd63
commit
18b5215ce6
@ -1,38 +1,39 @@
|
|||||||
import { addHours } from "date-fns/esm";
|
|
||||||
import "@material/mwc-button";
|
|
||||||
import {
|
import {
|
||||||
mdiClipboardTextMultipleOutline,
|
mdiClipboardTextMultipleOutline,
|
||||||
mdiInformationOutline,
|
mdiInformationOutline,
|
||||||
mdiRefresh,
|
mdiRefresh,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
|
import { addHours } from "date-fns/esm";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
|
||||||
import {
|
import {
|
||||||
HassEntities,
|
HassEntities,
|
||||||
HassEntity,
|
HassEntity,
|
||||||
HassEntityAttributeBase,
|
HassEntityAttributeBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import { dump } from "js-yaml";
|
import { dump } from "js-yaml";
|
||||||
|
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
|
||||||
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
|
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
|
||||||
import { computeRTL } from "../../../common/util/compute_rtl";
|
import { storage } from "../../../common/decorators/storage";
|
||||||
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
|
import { toggleAttribute } from "../../../common/dom/toggle_attribute";
|
||||||
import { escapeRegExp } from "../../../common/string/escape_regexp";
|
import { escapeRegExp } from "../../../common/string/escape_regexp";
|
||||||
|
import { computeRTL } from "../../../common/util/compute_rtl";
|
||||||
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||||
import "../../../components/entity/ha-entity-picker";
|
import "../../../components/entity/ha-entity-picker";
|
||||||
import "../../../components/ha-yaml-editor";
|
import "../../../components/ha-alert";
|
||||||
|
import "../../../components/ha-button";
|
||||||
|
import "../../../components/ha-checkbox";
|
||||||
|
import "../../../components/ha-expansion-panel";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import "../../../components/ha-checkbox";
|
|
||||||
import "../../../components/ha-tip";
|
import "../../../components/ha-tip";
|
||||||
import "../../../components/ha-alert";
|
import "../../../components/ha-yaml-editor";
|
||||||
|
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
||||||
import "../../../components/search-input";
|
import "../../../components/search-input";
|
||||||
import "../../../components/ha-expansion-panel";
|
|
||||||
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
|
||||||
import { toggleAttribute } from "../../../common/dom/toggle_attribute";
|
|
||||||
import { storage } from "../../../common/decorators/storage";
|
|
||||||
|
|
||||||
@customElement("developer-tools-state")
|
@customElement("developer-tools-state")
|
||||||
class HaPanelDevState extends LitElement {
|
class HaPanelDevState extends LitElement {
|
||||||
@ -70,6 +71,8 @@ class HaPanelDevState extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public rtl = false;
|
@property({ type: Boolean, reflect: true }) public rtl = false;
|
||||||
|
|
||||||
|
@query("ha-yaml-editor") private _yamlEditor?: HaYamlEditor;
|
||||||
|
|
||||||
private _filteredEntities = memoizeOne(
|
private _filteredEntities = memoizeOne(
|
||||||
(
|
(
|
||||||
entityFilter: string,
|
entityFilter: string,
|
||||||
@ -151,20 +154,19 @@ class HaPanelDevState extends LitElement {
|
|||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
<ha-yaml-editor
|
<ha-yaml-editor
|
||||||
autoUpdate
|
|
||||||
.value=${this._stateAttributes}
|
.value=${this._stateAttributes}
|
||||||
.error=${!this._validJSON}
|
.error=${!this._validJSON}
|
||||||
@value-changed=${this._yamlChanged}
|
@value-changed=${this._yamlChanged}
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
></ha-yaml-editor>
|
></ha-yaml-editor>
|
||||||
<div class="button-row">
|
<div class="button-row">
|
||||||
<mwc-button
|
<ha-button
|
||||||
@click=${this._handleSetState}
|
@click=${this._handleSetState}
|
||||||
.disabled=${!this._validJSON}
|
.disabled=${!this._validJSON}
|
||||||
raised
|
raised
|
||||||
>${this.hass.localize(
|
>${this.hass.localize(
|
||||||
"ui.panel.developer-tools.tabs.states.set_state"
|
"ui.panel.developer-tools.tabs.states.set_state"
|
||||||
)}</mwc-button
|
)}</ha-button
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
@click=${this._updateEntity}
|
@click=${this._updateEntity}
|
||||||
@ -343,10 +345,15 @@ class HaPanelDevState extends LitElement {
|
|||||||
this._entity = entityState;
|
this._entity = entityState;
|
||||||
this._state = entityState.state;
|
this._state = entityState.state;
|
||||||
this._stateAttributes = entityState.attributes;
|
this._stateAttributes = entityState.attributes;
|
||||||
|
this._updateEditor();
|
||||||
this._expanded = true;
|
this._expanded = true;
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _updateEditor() {
|
||||||
|
this._yamlEditor?.setValue(this._stateAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
private _entityIdChanged(ev: CustomEvent) {
|
private _entityIdChanged(ev: CustomEvent) {
|
||||||
this._entityId = ev.detail.value;
|
this._entityId = ev.detail.value;
|
||||||
this._updateEntity();
|
this._updateEntity();
|
||||||
@ -357,6 +364,7 @@ class HaPanelDevState extends LitElement {
|
|||||||
this._entity = undefined;
|
this._entity = undefined;
|
||||||
this._state = "";
|
this._state = "";
|
||||||
this._stateAttributes = {};
|
this._stateAttributes = {};
|
||||||
|
this._updateEditor();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const entityState = this.hass.states[this._entityId];
|
const entityState = this.hass.states[this._entityId];
|
||||||
@ -366,6 +374,7 @@ class HaPanelDevState extends LitElement {
|
|||||||
this._entity = entityState;
|
this._entity = entityState;
|
||||||
this._state = entityState.state;
|
this._state = entityState.state;
|
||||||
this._stateAttributes = entityState.attributes;
|
this._stateAttributes = entityState.attributes;
|
||||||
|
this._updateEditor();
|
||||||
this._expanded = true;
|
this._expanded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,6 +428,7 @@ class HaPanelDevState extends LitElement {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this._updateEditor();
|
||||||
try {
|
try {
|
||||||
await this.hass.callApi("POST", "states/" + this._entityId, {
|
await this.hass.callApi("POST", "states/" + this._entityId, {
|
||||||
state: this._state,
|
state: this._state,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user