1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-06-05 06:53:32 +01:00
Files
frontend/panels/dev-service/ha-panel-dev-service.html
T
2016-08-02 09:06:22 -07:00

159 lines
4.0 KiB
HTML

<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">
<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">
<link rel="import" href="../../src/components/ha-menu-button.html">
<link rel="import" href="../../src/resources/ha-style.html">
<link rel="import" href="./services-list.html">
<dom-module id="ha-panel-dev-service">
<template>
<style include="iron-flex iron-positioning ha-style">
:host {
background-color: white;
-ms-user-select: initial;
-webkit-user-select: initial;
-moz-user-select: initial;
}
.content {
padding: 24px;
}
.ha-form {
margin-right: 16px;
}
.description {
margin-top: 24px;
white-space: pre-wrap;
}
.header {
@apply(--paper-font-title);
}
</style>
<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>Services</div>
</app-toolbar>
</app-header>
<div class$='[[computeFormClasses(narrow)]]'>
<div class='flex'>
<p>
Call a service from a component.
</p>
<div class='ha-form'>
<paper-input label="Domain" autofocus value='{{domain}}'></paper-input>
<paper-input label="Service" value='{{service}}'></paper-input>
<paper-textarea label="Service Data (JSON, optional)" value='{{serviceData}}'></paper-textarea>
<paper-button on-tap='callService' raised>Call Service</paper-button>
</div>
<div class='description'>[[description]]</div>
</div>
<div>
<div class='header'>Available services</div>
<services-list on-service-selected='serviceSelected' hass='[[hass]]'></services-list>
</div>
</div>
</app-header-layout>
</template>
</dom-module>
<script>
Polymer({
is: 'ha-panel-dev-service',
properties: {
hass: {
type: Object,
},
narrow: {
type: Boolean,
value: false,
},
showMenu: {
type: Boolean,
value: false,
},
domain: {
type: String,
value: '',
},
service: {
type: String,
value: '',
},
serviceData: {
type: String,
value: '',
},
description: {
type: String,
computed: 'computeDescription(hass, domain, service)',
},
},
computeDescription: function (hass, domain, service) {
return hass.reactor.evaluate([
hass.serviceGetters.entityMap,
function (map) {
if (map.has(domain) && map.get(domain).get('services').has(service)) {
return JSON.stringify(
map
.get(domain)
.get('services')
.get(service)
.toJS(),
null, 2);
}
return 'No description available';
},
]);
},
serviceSelected: function (ev) {
this.domain = ev.detail.domain;
this.service = ev.detail.service;
},
callService: function () {
var serviceData;
try {
serviceData = this.serviceData ? JSON.parse(this.serviceData) : {};
} catch (err) {
/* eslint-disable no-alert */
alert('Error parsing JSON: ' + err);
/* eslint-enable no-alert */
return;
}
this.hass.serviceActions.callService(this.domain, this.service, serviceData);
},
computeFormClasses: function (narrow) {
return narrow ?
'content fit' : 'content fit layout horizontal';
},
});
</script>