mirror of
				https://github.com/home-assistant/frontend.git
				synced 2025-11-04 00:19:47 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			20251029.0
			...
			remove-set
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					fc698359b6 | 
@@ -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,72 +104,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
 | 
			
		||||
        }
 | 
			
		||||
      </style>
 | 
			
		||||
 | 
			
		||||
      <p>
 | 
			
		||||
        [[localize('ui.panel.developer-tools.tabs.states.description1')]]<br />
 | 
			
		||||
        [[localize('ui.panel.developer-tools.tabs.states.description2')]]
 | 
			
		||||
      </p>
 | 
			
		||||
      <div class="state-wrapper flex layout horizontal">
 | 
			
		||||
        <div class="inputs">
 | 
			
		||||
          <ha-entity-picker
 | 
			
		||||
            autofocus
 | 
			
		||||
            hass="[[hass]]"
 | 
			
		||||
            value="{{_entityId}}"
 | 
			
		||||
            on-change="entityIdChanged"
 | 
			
		||||
            allow-custom-entity
 | 
			
		||||
          ></ha-entity-picker>
 | 
			
		||||
          <paper-input
 | 
			
		||||
            label="[[localize('ui.panel.developer-tools.tabs.states.state')]]"
 | 
			
		||||
            required
 | 
			
		||||
            autocapitalize="none"
 | 
			
		||||
            autocomplete="off"
 | 
			
		||||
            autocorrect="off"
 | 
			
		||||
            spellcheck="false"
 | 
			
		||||
            value="{{_state}}"
 | 
			
		||||
            class="state-input"
 | 
			
		||||
          ></paper-input>
 | 
			
		||||
          <p>
 | 
			
		||||
            [[localize('ui.panel.developer-tools.tabs.states.state_attributes')]]
 | 
			
		||||
          </p>
 | 
			
		||||
          <ha-code-editor
 | 
			
		||||
            mode="yaml"
 | 
			
		||||
            value="[[_stateAttributes]]"
 | 
			
		||||
            error="[[!validJSON]]"
 | 
			
		||||
            on-value-changed="_yamlChanged"
 | 
			
		||||
          ></ha-code-editor>
 | 
			
		||||
          <div class="button-row">
 | 
			
		||||
            <mwc-button
 | 
			
		||||
              on-click="handleSetState"
 | 
			
		||||
              disabled="[[!validJSON]]"
 | 
			
		||||
              raised
 | 
			
		||||
              >[[localize('ui.panel.developer-tools.tabs.states.set_state')]]</mwc-button
 | 
			
		||||
            >
 | 
			
		||||
            <ha-icon-button
 | 
			
		||||
              on-click="entityIdChanged"
 | 
			
		||||
              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>
 | 
			
		||||
          <th>[[localize('ui.panel.developer-tools.tabs.states.entity')]]</th>
 | 
			
		||||
@@ -236,30 +147,26 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
 | 
			
		||||
        <template is="dom-repeat" items="[[_entities]]" as="entity">
 | 
			
		||||
          <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
                <div class="id-name-container">
 | 
			
		||||
              <div class="id-name-row">
 | 
			
		||||
                    <ha-svg-icon
 | 
			
		||||
                <ha-icon-button
 | 
			
		||||
                  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
 | 
			
		||||
                    >
 | 
			
		||||
                ></ha-icon-button>
 | 
			
		||||
                [[entity.entity_id]]
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="id-name-row">
 | 
			
		||||
                    <ha-svg-icon
 | 
			
		||||
                <ha-icon-button
 | 
			
		||||
                  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>
 | 
			
		||||
                ></ha-icon-button>
 | 
			
		||||
                <span class="secondary">
 | 
			
		||||
                  [[entity.attributes.friendly_name]]
 | 
			
		||||
                </span>
 | 
			
		||||
              </div>
 | 
			
		||||
                </div>
 | 
			
		||||
            </td>
 | 
			
		||||
            <td>[[entity.state]]</td>
 | 
			
		||||
            <template
 | 
			
		||||
@@ -271,7 +178,6 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
 | 
			
		||||
          </tr>
 | 
			
		||||
        </template>
 | 
			
		||||
      </table>
 | 
			
		||||
      </div>
 | 
			
		||||
    `;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -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);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -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": {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user