Use friendly names in turned_on/turned_off notifications. (#224)

* Use friendly names in turned_on/turned_off notifications.

* Use el variable instead of binding this

* Use computeStateName
This commit is contained in:
Andrey 2017-03-03 06:00:43 +02:00 committed by Paulus Schoutsen
parent 354423387e
commit 31b87075f9

View File

@ -116,6 +116,7 @@ Polymer({
return;
}
var notifications = this.$.notifications;
var el = this;
this.hass = Object.assign({
connection: conn,
connected: true,
@ -129,10 +130,15 @@ Polymer({
return conn.callService(domain, service, serviceData || {})
.then(function () {
var message;
var name;
if (serviceData.entity_id && el.hass.states &&
el.hass.states[serviceData.entity_id]) {
name = window.hassUtil.computeStateName(el.hass.states[serviceData.entity_id]);
}
if (service === 'turn_on' && serviceData.entity_id) {
message = 'Turned on ' + serviceData.entity_id + '.';
message = 'Turned on ' + (name || serviceData.entity_id) + '.';
} else if (service === 'turn_off' && serviceData.entity_id) {
message = 'Turned off ' + serviceData.entity_id + '.';
message = 'Turned off ' + (name || serviceData.entity_id) + '.';
} else {
message = 'Service ' + domain + '/' + service + ' called.';
}