mirror of
https://github.com/home-assistant/frontend.git
synced 2026-05-21 23:48:58 +01:00
d3980dc8b6
* Initial Commit * Update dropdown variables * Move available service list to a dropdown menu * Fix dropdown width * Add localstorage for panel state * clean up * Remove dropdown in favor of combo boxes * travis fix * Fix travis * Fix Travis * Fix combo box and remove neon-animations * Remove styling for sidebar. * Set max width on ha-form * Increase max-width to 500px * Update ha-panel-dev-service.html
199 lines
4.9 KiB
HTML
199 lines
4.9 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-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="../../bower_components/app-storage/app-localstorage/app-localstorage-document.html">
|
|
|
|
<link rel="import" href="../../bower_components/vaadin-combo-box/vaadin-combo-box.html">
|
|
|
|
<link rel='import' href='../../src/components/ha-menu-button.html'>
|
|
<link rel='import' href='../../src/resources/ha-style.html'>
|
|
<link rel='import' href='../../src/util/hass-behavior.html'>
|
|
|
|
<dom-module id='ha-panel-dev-service'>
|
|
<template>
|
|
<style include='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;
|
|
max-width: 500px;
|
|
}
|
|
|
|
.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>
|
|
|
|
<app-localstorage-document
|
|
key='panel-dev-service-state-domain'
|
|
data='{{domain}}'>
|
|
</app-localstorage-document>
|
|
<app-localstorage-document
|
|
key='panel-dev-service-state-service'
|
|
data='{{service}}'>
|
|
</app-localstorage-document>
|
|
<app-localstorage-document
|
|
key='panel-dev-service-state-servicedata'
|
|
data='{{serviceData}}'>
|
|
</app-localstorage-document>
|
|
|
|
<div class='content'>
|
|
<p>
|
|
Call a service from a component.
|
|
|
|
</p>
|
|
|
|
<div class='ha-form'>
|
|
<vaadin-combo-box label='Domain' items='[[computeDomains(serviceDomains)]]' value='{{domain}}'></vaadin-combo-box>
|
|
<vaadin-combo-box label='Service' items='[[computeServices(serviceDomains, domain)]]' value='{{service}}'></vaadin-combo-box>
|
|
<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>
|
|
|
|
</app-header-layout>
|
|
</template>
|
|
</dom-module>
|
|
|
|
<script>
|
|
Polymer({
|
|
is: 'ha-panel-dev-service',
|
|
|
|
behaviors: [window.hassBehavior],
|
|
|
|
properties: {
|
|
hass: {
|
|
type: Object,
|
|
},
|
|
|
|
narrow: {
|
|
type: Boolean,
|
|
value: false,
|
|
},
|
|
|
|
showMenu: {
|
|
type: Boolean,
|
|
value: false,
|
|
},
|
|
|
|
domain: {
|
|
type: String,
|
|
value: '',
|
|
observer: 'domainChanged',
|
|
},
|
|
|
|
service: {
|
|
type: String,
|
|
value: '',
|
|
observer: 'serviceChanged',
|
|
},
|
|
|
|
serviceData: {
|
|
type: String,
|
|
value: '',
|
|
},
|
|
|
|
description: {
|
|
type: String,
|
|
computed: 'computeDescription(hass, domain, service)',
|
|
},
|
|
|
|
serviceDomains: {
|
|
type: Array,
|
|
bindNuclear: function (hass) {
|
|
return hass.serviceGetters.entityMap;
|
|
},
|
|
},
|
|
},
|
|
|
|
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';
|
|
},
|
|
]);
|
|
},
|
|
|
|
computeDomains: function (serviceDomains) {
|
|
return serviceDomains
|
|
.valueSeq()
|
|
.map(function (domain) { return domain.domain; })
|
|
.sort()
|
|
.toJS();
|
|
},
|
|
|
|
computeServices: function (serviceDomains, domain) {
|
|
if (domain) {
|
|
return serviceDomains
|
|
.get(domain)
|
|
.get('services')
|
|
.keySeq()
|
|
.toArray();
|
|
}
|
|
return '';
|
|
},
|
|
|
|
domainChanged: function () {
|
|
this.service = '';
|
|
this.serviceData = '';
|
|
},
|
|
|
|
serviceChanged: function () {
|
|
this.serviceData = '';
|
|
},
|
|
|
|
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);
|
|
},
|
|
});
|
|
</script>
|