From fc698359b60b0f049dda54a1148ed212beadeecf Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 18 Oct 2021 21:41:22 -0700 Subject: [PATCH] Remove set state from state tool --- .../state/developer-tools-state.js | 340 ++++-------------- src/translations/en.json | 8 - 2 files changed, 76 insertions(+), 272 deletions(-) diff --git a/src/panels/developer-tools/state/developer-tools-state.js b/src/panels/developer-tools/state/developer-tools-state.js index 4d4102227e..507955a5b5 100644 --- a/src/panels/developer-tools/state/developer-tools-state.js +++ b/src/panels/developer-tools/state/developer-tools-state.js @@ -1,29 +1,21 @@ -import "@material/mwc-button"; import { mdiClipboardTextMultipleOutline, mdiInformationOutline, mdiRefresh, } from "@mdi/js"; import "@polymer/paper-checkbox/paper-checkbox"; -import "@polymer/paper-input/paper-input"; import { html } from "@polymer/polymer/lib/utils/html-tag"; /* eslint-plugin-disable lit */ import { PolymerElement } from "@polymer/polymer/polymer-element"; -import { dump, load } from "js-yaml"; -import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time"; +import { dump } from "js-yaml"; import { computeRTL } from "../../../common/util/compute_rtl"; import { escapeRegExp } from "../../../common/string/escape_regexp"; 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-svg-icon"; -import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box"; import { EventsMixin } from "../../../mixins/events-mixin"; import LocalizeMixin from "../../../mixins/localize-mixin"; import "../../../styles/polymer-ha-style"; -const ERROR_SENTINEL = {}; /* * @appliesMixin EventsMixin * @appliesMixin LocalizeMixin @@ -37,16 +29,7 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) { -webkit-user-select: initial; -moz-user-select: initial; display: block; - padding: 16px; - } - - .inputs { - width: 100%; - max-width: 400px; - } - - .info { - padding: 0 16px; + padding: 4px; } .button-row { @@ -55,9 +38,8 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) { align-items: center; } - .table-wrapper { + table { width: 100%; - overflow: auto; } .entities th { @@ -89,10 +71,9 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) { min-width: 200px; word-break: break-word; } - .entities ha-svg-icon { + .entities ha-icon-button { --mdc-icon-size: 20px; - padding: 4px; - cursor: pointer; + --mdc-icon-button-size: 28px; flex-shrink: 0; margin-right: 8px; } @@ -109,10 +90,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) { color: var(--primary-color); } - .entities .id-name-container { - display: flex; - flex-direction: column; - } .entities .id-name-row { display: flex; align-items: center; @@ -127,151 +104,80 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) { } -

- [[localize('ui.panel.developer-tools.tabs.states.description1')]]
- [[localize('ui.panel.developer-tools.tabs.states.description2')]] -

-
-
- - -

- [[localize('ui.panel.developer-tools.tabs.states.state_attributes')]] -

- -
- [[localize('ui.panel.developer-tools.tabs.states.set_state')]] - -
-
-
- -
-
- -

- [[localize('ui.panel.developer-tools.tabs.states.current_entities')]] -

-
- +
+ + + + + + + + + + + + + + +
[[localize('ui.panel.developer-tools.tabs.states.entity')]][[localize('ui.panel.developer-tools.tabs.states.state')]] + [[localize('ui.panel.developer-tools.tabs.states.attributes')]] + +
+ + + + + +
+ [[localize('ui.panel.developer-tools.tabs.states.no_entities')]] +
`; } @@ -281,16 +187,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) { type: Object, }, - parsedJSON: { - type: Object, - computed: "_computeParsedStateAttributes(_stateAttributes)", - }, - - validJSON: { - type: Boolean, - computed: "_computeValidJSON(parsedJSON)", - }, - _entityId: { type: String, value: "", @@ -311,20 +207,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) { value: "", }, - _entity: { - type: Object, - }, - - _state: { - type: String, - value: "", - }, - - _stateAttributes: { - type: String, - value: "", - }, - _showAttributes: { type: Boolean, value: JSON.parse( @@ -355,51 +237,11 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) { 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) { ev.preventDefault(); 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() { return mdiInformationOutline; } @@ -520,20 +362,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) { 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) { if ( (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) { return computeRTL(hass); } diff --git a/src/translations/en.json b/src/translations/en.json index 70335e9823..187bb42737 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -3835,22 +3835,14 @@ }, "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", "state": "State", "attributes": "Attributes", - "state_attributes": "State attributes (YAML, optional)", - "set_state": "Set State", - "current_entities": "Current entities", "filter_entities": "Filter entities", "filter_states": "Filter states", "filter_attributes": "Filter attributes", "no_entities": "No entities", "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" }, "templates": {