mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 21:17:47 +00:00
Remove set state from state tool
This commit is contained in:
parent
2770d1f36b
commit
fc698359b6
@ -1,29 +1,21 @@
|
|||||||
import "@material/mwc-button";
|
|
||||||
import {
|
import {
|
||||||
mdiClipboardTextMultipleOutline,
|
mdiClipboardTextMultipleOutline,
|
||||||
mdiInformationOutline,
|
mdiInformationOutline,
|
||||||
mdiRefresh,
|
mdiRefresh,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import "@polymer/paper-checkbox/paper-checkbox";
|
import "@polymer/paper-checkbox/paper-checkbox";
|
||||||
import "@polymer/paper-input/paper-input";
|
|
||||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||||
/* eslint-plugin-disable lit */
|
/* eslint-plugin-disable lit */
|
||||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||||
import { dump, load } from "js-yaml";
|
import { dump } from "js-yaml";
|
||||||
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
|
|
||||||
import { computeRTL } from "../../../common/util/compute_rtl";
|
import { computeRTL } from "../../../common/util/compute_rtl";
|
||||||
import { escapeRegExp } from "../../../common/string/escape_regexp";
|
import { escapeRegExp } from "../../../common/string/escape_regexp";
|
||||||
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||||
import "../../../components/entity/ha-entity-picker";
|
|
||||||
import "../../../components/ha-code-editor";
|
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
import "../../../components/ha-svg-icon";
|
|
||||||
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
|
|
||||||
import { EventsMixin } from "../../../mixins/events-mixin";
|
import { EventsMixin } from "../../../mixins/events-mixin";
|
||||||
import LocalizeMixin from "../../../mixins/localize-mixin";
|
import LocalizeMixin from "../../../mixins/localize-mixin";
|
||||||
import "../../../styles/polymer-ha-style";
|
import "../../../styles/polymer-ha-style";
|
||||||
|
|
||||||
const ERROR_SENTINEL = {};
|
|
||||||
/*
|
/*
|
||||||
* @appliesMixin EventsMixin
|
* @appliesMixin EventsMixin
|
||||||
* @appliesMixin LocalizeMixin
|
* @appliesMixin LocalizeMixin
|
||||||
@ -37,16 +29,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
-webkit-user-select: initial;
|
-webkit-user-select: initial;
|
||||||
-moz-user-select: initial;
|
-moz-user-select: initial;
|
||||||
display: block;
|
display: block;
|
||||||
padding: 16px;
|
padding: 4px;
|
||||||
}
|
|
||||||
|
|
||||||
.inputs {
|
|
||||||
width: 100%;
|
|
||||||
max-width: 400px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.info {
|
|
||||||
padding: 0 16px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.button-row {
|
.button-row {
|
||||||
@ -55,9 +38,8 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.table-wrapper {
|
table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: auto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.entities th {
|
.entities th {
|
||||||
@ -89,10 +71,9 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
.entities ha-svg-icon {
|
.entities ha-icon-button {
|
||||||
--mdc-icon-size: 20px;
|
--mdc-icon-size: 20px;
|
||||||
padding: 4px;
|
--mdc-icon-button-size: 28px;
|
||||||
cursor: pointer;
|
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
@ -109,10 +90,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
color: var(--primary-color);
|
color: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.entities .id-name-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
.entities .id-name-row {
|
.entities .id-name-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@ -127,151 +104,80 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<p>
|
<table class="entities">
|
||||||
[[localize('ui.panel.developer-tools.tabs.states.description1')]]<br />
|
<tr>
|
||||||
[[localize('ui.panel.developer-tools.tabs.states.description2')]]
|
<th>[[localize('ui.panel.developer-tools.tabs.states.entity')]]</th>
|
||||||
</p>
|
<th>[[localize('ui.panel.developer-tools.tabs.states.state')]]</th>
|
||||||
<div class="state-wrapper flex layout horizontal">
|
<th hidden$="[[narrow]]">
|
||||||
<div class="inputs">
|
[[localize('ui.panel.developer-tools.tabs.states.attributes')]]
|
||||||
<ha-entity-picker
|
<paper-checkbox
|
||||||
autofocus
|
checked="{{_showAttributes}}"
|
||||||
hass="[[hass]]"
|
on-change="saveAttributeCheckboxState"
|
||||||
value="{{_entityId}}"
|
></paper-checkbox>
|
||||||
on-change="entityIdChanged"
|
</th>
|
||||||
allow-custom-entity
|
</tr>
|
||||||
></ha-entity-picker>
|
<tr>
|
||||||
<paper-input
|
<th>
|
||||||
label="[[localize('ui.panel.developer-tools.tabs.states.state')]]"
|
<paper-input
|
||||||
required
|
label="[[localize('ui.panel.developer-tools.tabs.states.filter_entities')]]"
|
||||||
autocapitalize="none"
|
type="search"
|
||||||
autocomplete="off"
|
value="{{_entityFilter}}"
|
||||||
autocorrect="off"
|
></paper-input>
|
||||||
spellcheck="false"
|
</th>
|
||||||
value="{{_state}}"
|
<th>
|
||||||
class="state-input"
|
<paper-input
|
||||||
></paper-input>
|
label="[[localize('ui.panel.developer-tools.tabs.states.filter_states')]]"
|
||||||
<p>
|
type="search"
|
||||||
[[localize('ui.panel.developer-tools.tabs.states.state_attributes')]]
|
value="{{_stateFilter}}"
|
||||||
</p>
|
></paper-input>
|
||||||
<ha-code-editor
|
</th>
|
||||||
mode="yaml"
|
<th hidden$="[[!computeShowAttributes(narrow, _showAttributes)]]">
|
||||||
value="[[_stateAttributes]]"
|
<paper-input
|
||||||
error="[[!validJSON]]"
|
label="[[localize('ui.panel.developer-tools.tabs.states.filter_attributes')]]"
|
||||||
on-value-changed="_yamlChanged"
|
type="search"
|
||||||
></ha-code-editor>
|
value="{{_attributeFilter}}"
|
||||||
<div class="button-row">
|
></paper-input>
|
||||||
<mwc-button
|
</th>
|
||||||
on-click="handleSetState"
|
</tr>
|
||||||
disabled="[[!validJSON]]"
|
<tr hidden$="[[!computeShowEntitiesPlaceholder(_entities)]]">
|
||||||
raised
|
<td colspan="3">
|
||||||
>[[localize('ui.panel.developer-tools.tabs.states.set_state')]]</mwc-button
|
[[localize('ui.panel.developer-tools.tabs.states.no_entities')]]
|
||||||
>
|
</td>
|
||||||
<ha-icon-button
|
</tr>
|
||||||
on-click="entityIdChanged"
|
<template is="dom-repeat" items="[[_entities]]" as="entity">
|
||||||
label="[[localize('ui.common.refresh')]]"
|
|
||||||
path="[[refreshIcon()]]"
|
|
||||||
></ha-icon-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="info">
|
|
||||||
<template is="dom-if" if="[[_entity]]">
|
|
||||||
<p>
|
|
||||||
<b
|
|
||||||
>[[localize('ui.panel.developer-tools.tabs.states.last_changed')]]:</b
|
|
||||||
><br />[[lastChangedString(_entity)]]
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<b
|
|
||||||
>[[localize('ui.panel.developer-tools.tabs.states.last_updated')]]:</b
|
|
||||||
><br />[[lastUpdatedString(_entity)]]
|
|
||||||
</p>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h1>
|
|
||||||
[[localize('ui.panel.developer-tools.tabs.states.current_entities')]]
|
|
||||||
</h1>
|
|
||||||
<div class="table-wrapper">
|
|
||||||
<table class="entities">
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>[[localize('ui.panel.developer-tools.tabs.states.entity')]]</th>
|
<td>
|
||||||
<th>[[localize('ui.panel.developer-tools.tabs.states.state')]]</th>
|
<div class="id-name-row">
|
||||||
<th hidden$="[[narrow]]">
|
<ha-icon-button
|
||||||
[[localize('ui.panel.developer-tools.tabs.states.attributes')]]
|
on-click="copyEntity"
|
||||||
<paper-checkbox
|
alt="[[localize('ui.panel.developer-tools.tabs.states.copy_id')]]"
|
||||||
checked="{{_showAttributes}}"
|
title="[[localize('ui.panel.developer-tools.tabs.states.copy_id')]]"
|
||||||
on-change="saveAttributeCheckboxState"
|
path="[[clipboardOutlineIcon()]]"
|
||||||
></paper-checkbox>
|
></ha-icon-button>
|
||||||
</th>
|
[[entity.entity_id]]
|
||||||
</tr>
|
</div>
|
||||||
<tr>
|
<div class="id-name-row">
|
||||||
<th>
|
<ha-icon-button
|
||||||
<paper-input
|
on-click="entityMoreInfo"
|
||||||
label="[[localize('ui.panel.developer-tools.tabs.states.filter_entities')]]"
|
alt="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]"
|
||||||
type="search"
|
title="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]"
|
||||||
value="{{_entityFilter}}"
|
path="[[informationOutlineIcon()]]"
|
||||||
></paper-input>
|
></ha-icon-button>
|
||||||
</th>
|
<span class="secondary">
|
||||||
<th>
|
[[entity.attributes.friendly_name]]
|
||||||
<paper-input
|
</span>
|
||||||
label="[[localize('ui.panel.developer-tools.tabs.states.filter_states')]]"
|
</div>
|
||||||
type="search"
|
|
||||||
value="{{_stateFilter}}"
|
|
||||||
></paper-input>
|
|
||||||
</th>
|
|
||||||
<th hidden$="[[!computeShowAttributes(narrow, _showAttributes)]]">
|
|
||||||
<paper-input
|
|
||||||
label="[[localize('ui.panel.developer-tools.tabs.states.filter_attributes')]]"
|
|
||||||
type="search"
|
|
||||||
value="{{_attributeFilter}}"
|
|
||||||
></paper-input>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
<tr hidden$="[[!computeShowEntitiesPlaceholder(_entities)]]">
|
|
||||||
<td colspan="3">
|
|
||||||
[[localize('ui.panel.developer-tools.tabs.states.no_entities')]]
|
|
||||||
</td>
|
</td>
|
||||||
|
<td>[[entity.state]]</td>
|
||||||
|
<template
|
||||||
|
is="dom-if"
|
||||||
|
if="[[computeShowAttributes(narrow, _showAttributes)]]"
|
||||||
|
>
|
||||||
|
<td>[[attributeString(entity)]]</td>
|
||||||
|
</template>
|
||||||
</tr>
|
</tr>
|
||||||
<template is="dom-repeat" items="[[_entities]]" as="entity">
|
</template>
|
||||||
<tr>
|
</table>
|
||||||
<td>
|
|
||||||
<div class="id-name-container">
|
|
||||||
<div class="id-name-row">
|
|
||||||
<ha-svg-icon
|
|
||||||
on-click="copyEntity"
|
|
||||||
alt="[[localize('ui.panel.developer-tools.tabs.states.copy_id')]]"
|
|
||||||
title="[[localize('ui.panel.developer-tools.tabs.states.copy_id')]]"
|
|
||||||
path="[[clipboardOutlineIcon()]]"
|
|
||||||
></ha-svg-icon>
|
|
||||||
<a href="#" on-click="entitySelected"
|
|
||||||
>[[entity.entity_id]]</a
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
<div class="id-name-row">
|
|
||||||
<ha-svg-icon
|
|
||||||
on-click="entityMoreInfo"
|
|
||||||
alt="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]"
|
|
||||||
title="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]"
|
|
||||||
path="[[informationOutlineIcon()]]"
|
|
||||||
></ha-svg-icon>
|
|
||||||
<span class="secondary">
|
|
||||||
[[entity.attributes.friendly_name]]
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td>[[entity.state]]</td>
|
|
||||||
<template
|
|
||||||
is="dom-if"
|
|
||||||
if="[[computeShowAttributes(narrow, _showAttributes)]]"
|
|
||||||
>
|
|
||||||
<td>[[attributeString(entity)]]</td>
|
|
||||||
</template>
|
|
||||||
</tr>
|
|
||||||
</template>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,16 +187,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
type: Object,
|
type: Object,
|
||||||
},
|
},
|
||||||
|
|
||||||
parsedJSON: {
|
|
||||||
type: Object,
|
|
||||||
computed: "_computeParsedStateAttributes(_stateAttributes)",
|
|
||||||
},
|
|
||||||
|
|
||||||
validJSON: {
|
|
||||||
type: Boolean,
|
|
||||||
computed: "_computeValidJSON(parsedJSON)",
|
|
||||||
},
|
|
||||||
|
|
||||||
_entityId: {
|
_entityId: {
|
||||||
type: String,
|
type: String,
|
||||||
value: "",
|
value: "",
|
||||||
@ -311,20 +207,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
value: "",
|
value: "",
|
||||||
},
|
},
|
||||||
|
|
||||||
_entity: {
|
|
||||||
type: Object,
|
|
||||||
},
|
|
||||||
|
|
||||||
_state: {
|
|
||||||
type: String,
|
|
||||||
value: "",
|
|
||||||
},
|
|
||||||
|
|
||||||
_stateAttributes: {
|
|
||||||
type: String,
|
|
||||||
value: "",
|
|
||||||
},
|
|
||||||
|
|
||||||
_showAttributes: {
|
_showAttributes: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: JSON.parse(
|
value: JSON.parse(
|
||||||
@ -355,51 +237,11 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
copyToClipboard(ev.model.entity.entity_id);
|
copyToClipboard(ev.model.entity.entity_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
entitySelected(ev) {
|
|
||||||
const state = ev.model.entity;
|
|
||||||
this._entityId = state.entity_id;
|
|
||||||
this._entity = state;
|
|
||||||
this._state = state.state;
|
|
||||||
this._stateAttributes = dump(state.attributes);
|
|
||||||
ev.preventDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
entityIdChanged() {
|
|
||||||
if (this._entityId === "") {
|
|
||||||
this._entity = undefined;
|
|
||||||
this._state = "";
|
|
||||||
this._stateAttributes = "";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const state = this.hass.states[this._entityId];
|
|
||||||
if (!state) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._entity = state;
|
|
||||||
this._state = state.state;
|
|
||||||
this._stateAttributes = dump(state.attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
entityMoreInfo(ev) {
|
entityMoreInfo(ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
this.fire("hass-more-info", { entityId: ev.model.entity.entity_id });
|
this.fire("hass-more-info", { entityId: ev.model.entity.entity_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSetState() {
|
|
||||||
if (!this._entityId) {
|
|
||||||
showAlertDialog(this, {
|
|
||||||
text: this.hass.localize(
|
|
||||||
"ui.panel.developer-tools.tabs.states.alert_entity_field"
|
|
||||||
),
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.hass.callApi("POST", "states/" + this._entityId, {
|
|
||||||
state: this._state,
|
|
||||||
attributes: this.parsedJSON,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
informationOutlineIcon() {
|
informationOutlineIcon() {
|
||||||
return mdiInformationOutline;
|
return mdiInformationOutline;
|
||||||
}
|
}
|
||||||
@ -520,20 +362,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastChangedString(entity) {
|
|
||||||
return formatDateTimeWithSeconds(
|
|
||||||
new Date(entity.last_changed),
|
|
||||||
this.hass.locale
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
lastUpdatedString(entity) {
|
|
||||||
return formatDateTimeWithSeconds(
|
|
||||||
new Date(entity.last_updated),
|
|
||||||
this.hass.locale
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
formatAttributeValue(value) {
|
formatAttributeValue(value) {
|
||||||
if (
|
if (
|
||||||
(Array.isArray(value) && value.some((val) => val instanceof Object)) ||
|
(Array.isArray(value) && value.some((val) => val instanceof Object)) ||
|
||||||
@ -552,22 +380,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_computeParsedStateAttributes(stateAttributes) {
|
|
||||||
try {
|
|
||||||
return stateAttributes.trim() ? load(stateAttributes) : {};
|
|
||||||
} catch (err) {
|
|
||||||
return ERROR_SENTINEL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_computeValidJSON(parsedJSON) {
|
|
||||||
return parsedJSON !== ERROR_SENTINEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
_yamlChanged(ev) {
|
|
||||||
this._stateAttributes = ev.detail.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
_computeRTL(hass) {
|
_computeRTL(hass) {
|
||||||
return computeRTL(hass);
|
return computeRTL(hass);
|
||||||
}
|
}
|
||||||
|
@ -3835,22 +3835,14 @@
|
|||||||
},
|
},
|
||||||
"states": {
|
"states": {
|
||||||
"title": "States",
|
"title": "States",
|
||||||
"description1": "Set the current state representation of an entity within Home Assistant.",
|
|
||||||
"description2": "If the entity belongs to a device, there will be no actual communication with that device.",
|
|
||||||
"entity": "Entity",
|
"entity": "Entity",
|
||||||
"state": "State",
|
"state": "State",
|
||||||
"attributes": "Attributes",
|
"attributes": "Attributes",
|
||||||
"state_attributes": "State attributes (YAML, optional)",
|
|
||||||
"set_state": "Set State",
|
|
||||||
"current_entities": "Current entities",
|
|
||||||
"filter_entities": "Filter entities",
|
"filter_entities": "Filter entities",
|
||||||
"filter_states": "Filter states",
|
"filter_states": "Filter states",
|
||||||
"filter_attributes": "Filter attributes",
|
"filter_attributes": "Filter attributes",
|
||||||
"no_entities": "No entities",
|
"no_entities": "No entities",
|
||||||
"more_info": "More Info",
|
"more_info": "More Info",
|
||||||
"alert_entity_field": "Entity is a mandatory field",
|
|
||||||
"last_updated": "[%key:ui::dialogs::more_info_control::last_updated%]",
|
|
||||||
"last_changed": "[%key:ui::dialogs::more_info_control::last_changed%]",
|
|
||||||
"copy_id": "Copy ID to clipboard"
|
"copy_id": "Copy ID to clipboard"
|
||||||
},
|
},
|
||||||
"templates": {
|
"templates": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user