Fix bugs in service picker and service dev tool (#687)

This commit is contained in:
Paulus Schoutsen 2017-11-26 10:05:07 -08:00 committed by GitHub
parent 48ecfe07a2
commit bc94dce8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 8 deletions

View File

@ -294,7 +294,7 @@
alert(`Error parsing JSON: ${this.serviceData}`); alert(`Error parsing JSON: ${this.serviceData}`);
} }
this.hass.callService(this.domain, this.service, this.parsedJSON); this.hass.callService(this._domain, this._service, this.parsedJSON);
} }
_entityPicked(ev) { _entityPicked(ev) {

View File

@ -16,7 +16,7 @@
} }
</style> </style>
<vaadin-combo-box-light <vaadin-combo-box-light
items='[[items]]' items='[[_items]]'
item-value-path='[[itemValuePath]]' item-value-path='[[itemValuePath]]'
item-label-path='[[itemLabelPath]]' item-label-path='[[itemLabelPath]]'
value='{{value}}' value='{{value}}'

View File

@ -6,7 +6,7 @@
<template> <template>
<ha-combo-box <ha-combo-box
label='Service' label='Service'
items='[[_computeServices(hass)]]' items='[[_services]]'
value='{{value}}' value='{{value}}'
allow-custom-value allow-custom-value
></ha-combo-box> ></ha-combo-box>
@ -19,7 +19,11 @@ class HaServicePicker extends Polymer.Element {
static get properties() { static get properties() {
return { return {
hass: Object, hass: {
type: Object,
observer: '_hassChanged',
},
_services: Array,
value: { value: {
type: String, type: String,
notify: true, notify: true,
@ -27,11 +31,14 @@ class HaServicePicker extends Polymer.Element {
}; };
} }
_computeServices(hass) { _hassChanged(hass, oldHass) {
if (!hass) {
this._services = [];
} else if (oldHass && hass.config.services === oldHass.config.services) {
return;
}
const result = []; const result = [];
if (!hass) return result;
Object.keys(hass.config.services).sort().forEach((domain) => { Object.keys(hass.config.services).sort().forEach((domain) => {
const services = Object.keys(hass.config.services[domain]).sort(); const services = Object.keys(hass.config.services[domain]).sort();
@ -40,7 +47,7 @@ class HaServicePicker extends Polymer.Element {
} }
}); });
return result; this._services = result;
} }
} }