ha-frontend/panels/dev-state/ha-panel-dev-state.html

199 lines
5.1 KiB
HTML
Raw Normal View History

2015-07-13 01:57:15 +02:00
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../bower_components/paper-button/paper-button.html">
<link rel="import" href="../../bower_components/paper-input/paper-input.html">
<link rel="import" href="../../bower_components/paper-input/paper-textarea.html">
2016-07-31 07:48:39 +02:00
<link rel="import" href="../../bower_components/paper-checkbox/paper-checkbox.html">
2015-07-13 01:57:15 +02:00
2016-07-31 07:48:39 +02:00
<link rel="import" href="../../bower_components/app-layout/app-header-layout/app-header-layout.html">
<link rel="import" href="../../bower_components/app-layout/app-header/app-header.html">
<link rel="import" href="../../bower_components/app-layout/app-toolbar/app-toolbar.html">
2016-07-19 11:25:26 +02:00
2016-07-31 07:48:39 +02:00
<link rel="import" href="../../src/components/ha-menu-button.html">
2016-08-02 18:06:22 +02:00
<link rel="import" href="../../src/resources/ha-style.html">
2015-07-13 01:57:15 +02:00
2016-07-17 08:19:49 +02:00
<dom-module id="ha-panel-dev-state">
2015-07-13 01:57:15 +02:00
<template>
2016-07-31 07:48:39 +02:00
<style include="ha-style">
:host {
2016-07-18 08:18:48 +02:00
background-color: white;
-ms-user-select: initial;
-webkit-user-select: initial;
-moz-user-select: initial;
}
2016-07-31 07:48:39 +02:00
.content {
padding: 16px;
2016-07-31 07:48:39 +02:00
}
.entities th {
text-align: left;
2016-07-18 08:18:48 +02:00
}
.entities tr {
vertical-align: top;
}
.entities tr:nth-child(even) {
background-color: #eee;
}
2016-07-31 07:48:39 +02:00
.entities td:nth-child(3) {
white-space: pre-wrap;
word-break: break-word;
}
.entities a {
color: var(--primary-color);
2016-07-18 08:18:48 +02:00
}
</style>
2016-07-31 07:48:39 +02:00
<app-header-layout has-scrolling-region>
<app-header fixed>
<app-toolbar>
<ha-menu-button narrow='[[narrow]]' show-menu='[[showMenu]]'></ha-menu-button>
<div main-title>States</div>
</app-toolbar>
</app-header>
2015-07-13 01:57:15 +02:00
2016-07-31 07:48:39 +02:00
<div class='content'>
2016-04-09 06:10:32 +02:00
<div>
<p>
Set the representation of a device within Home Assistant.<br />
This will not communicate with the actual device.
</p>
2016-07-31 07:48:39 +02:00
<paper-input label="Entity ID" autofocus required value='{{_entityId}}'></paper-input>
<paper-input label="State" required value='{{_state}}'></paper-input>
<paper-textarea label="State attributes (JSON, optional)" value='{{_stateAttributes}}'></paper-textarea>
<paper-button on-tap='handleSetState' raised>Set State</paper-button>
2015-07-13 01:57:15 +02:00
</div>
2016-07-31 07:48:39 +02:00
<h1>Current entities</h1>
<table class='entities'>
<tr>
<th>Entity</th>
<th>State</th>
<th hidden$='[[narrow]]'>
Attributes
<paper-checkbox checked='{{_showAttributes}}'></paper-checkbox>
</th>
</tr>
<template is='dom-repeat' items='[[_entities]]' as='entity'>
<tr>
<td><a href='#' on-tap='entitySelected'>[[entity.entity_id]]</a></td>
2016-07-31 07:48:39 +02:00
<td>[[entity.state]]</td>
<template is='dom-if' if='[[computeShowAttributes(narrow, _showAttributes)]]'>
<td>[[attributeString(entity)]]</td>
</template>
</tr>
</template>
</table>
2015-07-13 01:57:15 +02:00
</div>
2016-07-31 07:48:39 +02:00
</app-header-layout>
2015-07-13 01:57:15 +02:00
</template>
</dom-module>
2016-07-12 17:59:07 +02:00
<script>
Polymer({
2016-07-17 08:19:49 +02:00
is: 'ha-panel-dev-state',
2016-07-12 17:59:07 +02:00
properties: {
hass: {
type: Object,
},
narrow: {
type: Boolean,
value: false,
},
showMenu: {
type: Boolean,
value: false,
},
2016-07-31 07:48:39 +02:00
_entityId: {
2016-07-12 17:59:07 +02:00
type: String,
value: '',
},
2016-07-31 07:48:39 +02:00
_state: {
2016-07-12 17:59:07 +02:00
type: String,
value: '',
},
2016-07-31 07:48:39 +02:00
_stateAttributes: {
2016-07-12 17:59:07 +02:00
type: String,
value: '',
},
2016-07-31 07:48:39 +02:00
_showAttributes: {
type: Boolean,
value: true,
},
2016-07-12 17:59:07 +02:00
2016-07-31 07:48:39 +02:00
_entities: {
type: Array,
computed: 'computeEntities(hass)',
2016-07-31 07:48:39 +02:00
},
2016-07-12 17:59:07 +02:00
},
entitySelected: function (ev) {
2016-07-31 07:48:39 +02:00
var state = ev.model.entity;
this._entityId = state.entity_id;
2016-07-31 07:48:39 +02:00
this._state = state.state;
this._stateAttributes = JSON.stringify(state.attributes, null, ' ');
ev.preventDefault();
2016-07-12 17:59:07 +02:00
},
handleSetState: function () {
var attr;
try {
2016-09-16 05:49:53 +02:00
attr = this._stateAttributes ? JSON.parse(this._stateAttributes) : {};
2016-07-12 17:59:07 +02:00
} catch (err) {
/* eslint-disable no-alert */
alert('Error parsing JSON: ' + err);
/* eslint-enable no-alert */
return;
}
this.hass.callApi('POST', 'states/' + this._entityId, {
2016-07-31 07:48:39 +02:00
state: this._state,
2016-07-12 17:59:07 +02:00
attributes: attr,
});
},
computeEntities: function (hass) {
return Object.keys(hass.states).map(function (key) { return hass.states[key]; })
.sort(function (entityA, entityB) {
if (entityA.entity_id < entityB.entity_id) {
return -1;
}
if (entityB.entity_id > entityA.entity_id) {
return 1;
}
return 0;
});
},
2016-07-31 07:48:39 +02:00
computeShowAttributes: function (narrow, _showAttributes) {
return !narrow && _showAttributes;
},
attributeString: function (entity) {
var output = '';
var i;
var keys;
var key;
for (i = 0, keys = Object.keys(entity.attributes); i < keys.length; i++) {
key = keys[i];
output += key + ': ' + entity.attributes[key] + '\n';
}
return output;
2016-07-12 17:59:07 +02:00
},
});
</script>