Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/panels/developer-tools/state/developer-tools-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import "../../../components/entity/ha-entity-picker";
import "../../../components/ha-code-editor";
import "../../../resources/ha-style";
import { EventsMixin } from "../../../mixins/events-mixin";
import LocalizeMixin from "../../../mixins/localize-mixin";

const ERROR_SENTINEL = {};
/*
* @appliesMixin EventsMixin
* @appliesMixin LocalizeMixin
*/
class HaPanelDevState extends EventsMixin(PolymerElement) {
class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
static get template() {
return html`
<style include="ha-style">
Expand Down Expand Up @@ -70,8 +72,8 @@ class HaPanelDevState extends EventsMixin(PolymerElement) {

<div class="inputs">
<p>
Set the representation of a device within Home Assistant.<br />
This will not communicate with the actual device.
[[localize('ui.panel.developer-tools.tabs.states.description1')]]<br />
[[localize('ui.panel.developer-tools.tabs.states.description2')]]
</p>

<ha-entity-picker
Expand All @@ -82,7 +84,7 @@ class HaPanelDevState extends EventsMixin(PolymerElement) {
allow-custom-entity
></ha-entity-picker>
<paper-input
label="State"
label="[[localize('ui.panel.developer-tools.tabs.states.state')]]"
required
autocapitalize="none"
autocomplete="off"
Expand All @@ -91,62 +93,68 @@ class HaPanelDevState extends EventsMixin(PolymerElement) {
value="{{_state}}"
class="state-input"
></paper-input>
<p>State attributes (YAML, optional)</p>
<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>
<mwc-button on-click="handleSetState" disabled="[[!validJSON]]" raised
>Set State</mwc-button
>[[localize('ui.panel.developer-tools.tabs.states.set_state')]]</mwc-button
>
</div>

<h1>Current entities</h1>
<h1>
[[localize('ui.panel.developer-tools.tabs.states.current_entities')]]
</h1>
<table class="entities">
<tr>
<th>Entity</th>
<th>State</th>
<th>[[localize('ui.panel.developer-tools.tabs.states.entity')]]</th>
<th>[[localize('ui.panel.developer-tools.tabs.states.state')]]</th>
<th hidden$="[[narrow]]">
Attributes
[[localize('ui.panel.developer-tools.tabs.states.attributes')]]
<paper-checkbox checked="{{_showAttributes}}"></paper-checkbox>
</th>
</tr>
<tr>
<th>
<paper-input
label="Filter entities"
label="[[localize('ui.panel.developer-tools.tabs.states.filter_entities')]]"
type="search"
value="{{_entityFilter}}"
></paper-input>
</th>
<th>
<paper-input
label="Filter states"
label="[[localize('ui.panel.developer-tools.tabs.states.filter_states')]]"
type="search"
value="{{_stateFilter}}"
></paper-input>
</th>
<th hidden$="[[!computeShowAttributes(narrow, _showAttributes)]]">
<paper-input
label="Filter attributes"
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">No entities</td>
<td colspan="3">
[[localize('ui.panel.developer-tools.tabs.states.no_entities')]]
</td>
</tr>
<template is="dom-repeat" items="[[_entities]]" as="entity">
<tr>
<td>
<paper-icon-button
on-click="entityMoreInfo"
icon="hass:information-outline"
alt="More Info"
title="More Info"
alt="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]"
title="[[localize('ui.panel.developer-tools.tabs.states.more_info')]]"
>
</paper-icon-button>
<a href="#" on-click="entitySelected">[[entity.entity_id]]</a>
Expand Down Expand Up @@ -244,7 +252,11 @@ class HaPanelDevState extends EventsMixin(PolymerElement) {

handleSetState() {
if (!this._entityId) {
alert("Entity is a mandatory field");
alert(
this.hass.localize(
"ui.panel.developer-tools.tabs.states.alert_entity_field"
)
);
return;
}
this.hass.callApi("POST", "states/" + this._entityId, {
Expand Down
16 changes: 15 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,21 @@
"title": "Services"
},
"states": {
"title": "States"
"title": "States",
"description1": "Set the representation of a device within Home Assistant.",
"description2": "This will not communicate with the actual 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"
},
"templates": {
"title": "Template"
Expand Down