Fix entity names in notification (#2612)

This commit is contained in:
Paulus Schoutsen 2019-01-28 19:36:11 -08:00 committed by GitHub
parent 30ab056aa4
commit a090b291aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,28 +66,34 @@ export default (superClass) =>
try { try {
await callService(conn, domain, service, serviceData); await callService(conn, domain, service, serviceData);
let message; const entityIds = Array.isArray(serviceData.entity_id)
let name; ? serviceData.entity_id
if ( : [serviceData.entity_id];
serviceData.entity_id &&
this.hass.states && const names = [];
this.hass.states[serviceData.entity_id] for (const entityId of entityIds) {
) { const stateObj = this.hass.states[entityId];
name = computeStateName( if (stateObj) {
this.hass.states[serviceData.entity_id] names.push(computeStateName(stateObj));
);
} }
}
if (names.length === 0) {
names.push(entityIds[0]);
}
let message;
const name = names.join(", ");
if (service === "turn_on" && serviceData.entity_id) { if (service === "turn_on" && serviceData.entity_id) {
message = this.hass.localize( message = this.hass.localize(
"ui.notification_toast.entity_turned_on", "ui.notification_toast.entity_turned_on",
"entity", "entity",
name || serviceData.entity_id name
); );
} else if (service === "turn_off" && serviceData.entity_id) { } else if (service === "turn_off" && serviceData.entity_id) {
message = this.hass.localize( message = this.hass.localize(
"ui.notification_toast.entity_turned_off", "ui.notification_toast.entity_turned_off",
"entity", "entity",
name || serviceData.entity_id name
); );
} else { } else {
message = this.hass.localize( message = this.hass.localize(