Fix service button element (#2343)

This commit is contained in:
Paulus Schoutsen 2018-12-17 09:36:55 +01:00 committed by GitHub
parent d1a56d6acc
commit e5bf842801
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -56,6 +56,10 @@ export default (superClass) =>
dockedSidebar: false, dockedSidebar: false,
moreInfoEntityId: null, moreInfoEntityId: null,
callService: async (domain, service, serviceData = {}) => { callService: async (domain, service, serviceData = {}) => {
if (__DEV__) {
// eslint-disable-next-line
console.log("Calling service", domain, service, serviceData);
}
try { try {
await callService(conn, domain, service, serviceData); await callService(conn, domain, service, serviceData);
@ -91,6 +95,15 @@ export default (superClass) =>
} }
this.fire("hass-notification", { message }); this.fire("hass-notification", { message });
} catch (err) { } catch (err) {
if (__DEV__) {
// eslint-disable-next-line
console.error(
"Error calling service",
domain,
service,
serviceData
);
}
const message = this.localize( const message = this.localize(
"ui.notification_toast.service_call_failed", "ui.notification_toast.service_call_failed",
"service", "service",
@ -106,21 +119,25 @@ export default (superClass) =>
fetchWithAuth(auth, `${auth.data.hassUrl}${path}`, init), fetchWithAuth(auth, `${auth.data.hassUrl}${path}`, init),
// For messages that do not get a response // For messages that do not get a response
sendWS: (msg) => { sendWS: (msg) => {
// eslint-disable-next-line if (__DEV__) {
if (__DEV__) console.log("Sending", msg); // eslint-disable-next-line
console.log("Sending", msg);
}
conn.sendMessage(msg); conn.sendMessage(msg);
}, },
// For messages that expect a response // For messages that expect a response
callWS: (msg) => { callWS: (msg) => {
/* eslint-disable no-console */ if (__DEV__) {
if (__DEV__) console.log("Sending", msg); /* eslint-disable no-console */
console.log("Sending", msg);
}
const resp = conn.sendMessagePromise(msg); const resp = conn.sendMessagePromise(msg);
if (__DEV__) { if (__DEV__) {
resp.then( resp.then(
(result) => console.log("Received", result), (result) => console.log("Received", result),
(err) => console.log("Error", err) (err) => console.error("Error", err)
); );
} }
return resp; return resp;

View File

@ -48,7 +48,7 @@ export class HuiServiceButtonElement extends LitElement
.hass="${this.hass}" .hass="${this.hass}"
.domain="${this._domain}" .domain="${this._domain}"
.service="${this._service}" .service="${this._service}"
.service-data="${this._config.service_data}" .serviceData="${this._config.service_data}"
>${this._config.title}</ha-call-service-button >${this._config.title}</ha-call-service-button
> >
`; `;