2016-07-17 08:19:49 +02:00
|
|
|
<!--
|
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">
|
|
|
|
|
|
|
|
<link rel="import" href="./partial-base.html">
|
2016-07-17 08:19:49 +02:00
|
|
|
-->
|
|
|
|
<link rel="import" href="./services-list.html">
|
2015-07-13 01:57:15 +02:00
|
|
|
|
2016-07-17 08:19:49 +02:00
|
|
|
<dom-module id="ha-panel-dev-service">
|
2015-07-13 01:57:15 +02:00
|
|
|
<template>
|
2016-07-18 08:18:48 +02:00
|
|
|
<style is="custom-style" include="iron-flex iron-positioning"></style>
|
|
|
|
<style>
|
|
|
|
.content {
|
|
|
|
@apply(--paper-font-body1);
|
|
|
|
margin-top: 64px;
|
|
|
|
padding: 24px;
|
|
|
|
background-color: white;
|
|
|
|
-ms-user-select: initial;
|
|
|
|
-webkit-user-select: initial;
|
|
|
|
-moz-user-select: initial;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ha-form {
|
|
|
|
margin-right: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.description {
|
|
|
|
margin-top: 24px;
|
|
|
|
white-space: pre-wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
.header {
|
|
|
|
@apply(--paper-font-title);
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2015-08-30 03:15:58 +02:00
|
|
|
<partial-base narrow="[[narrow]]" show-menu='[[showMenu]]'>
|
2016-05-07 08:04:54 +02:00
|
|
|
<span header-title>Services</span>
|
2015-07-13 01:57:15 +02:00
|
|
|
|
2016-04-09 06:10:32 +02:00
|
|
|
<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>
|
2015-07-13 01:57:15 +02:00
|
|
|
</div>
|
2016-04-09 06:10:32 +02:00
|
|
|
<div class='description'>[[description]]</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<div class='header'>Available services</div>
|
2016-05-29 01:03:51 +02:00
|
|
|
<services-list on-service-selected='serviceSelected' hass='[[hass]]'></services-list>
|
2015-07-13 01:57:15 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</partial-base>
|
|
|
|
</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-service',
|
2016-07-12 17:59:07 +02:00
|
|
|
|
|
|
|
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>
|