From e7e8dff0ecec6808553d7bc5e362a1320356b54e Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 10 Feb 2020 20:17:24 +0100 Subject: [PATCH] Graceful fallback if translations for device automations are missing (#4824) * Graceful fallback if translations for device automations are missing * Update src/data/device_automation.ts Co-Authored-By: Bram Kragten * Update src/data/device_automation.ts Co-Authored-By: Bram Kragten * Update src/data/device_automation.ts Co-Authored-By: Bram Kragten * tweak Co-authored-by: Bram Kragten --- src/data/device_automation.ts | 48 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/data/device_automation.ts b/src/data/device_automation.ts index bc58f1b00a..03c5a6870e 100644 --- a/src/data/device_automation.ts +++ b/src/data/device_automation.ts @@ -101,14 +101,16 @@ export const localizeDeviceAutomationAction = ( action: DeviceAction ) => { const state = action.entity_id ? hass.states[action.entity_id] : undefined; - return hass.localize( - `component.${action.domain}.device_automation.action_type.${action.type}`, - "entity_name", - state ? computeStateName(state) : "", - "subtype", + return ( hass.localize( - `component.${action.domain}.device_automation.action_subtype.${action.subtype}` - ) + `component.${action.domain}.device_automation.action_type.${action.type}`, + "entity_name", + state ? computeStateName(state) : action.entity_id || "", + "subtype", + hass.localize( + `component.${action.domain}.device_automation.action_subtype.${action.subtype}` + ) || action.subtype + ) || `"${action.subtype}" ${action.type}` ); }; @@ -119,14 +121,16 @@ export const localizeDeviceAutomationCondition = ( const state = condition.entity_id ? hass.states[condition.entity_id] : undefined; - return hass.localize( - `component.${condition.domain}.device_automation.condition_type.${condition.type}`, - "entity_name", - state ? computeStateName(state) : "", - "subtype", + return ( hass.localize( - `component.${condition.domain}.device_automation.condition_subtype.${condition.subtype}` - ) + `component.${condition.domain}.device_automation.condition_type.${condition.type}`, + "entity_name", + state ? computeStateName(state) : condition.entity_id || "", + "subtype", + hass.localize( + `component.${condition.domain}.device_automation.condition_subtype.${condition.subtype}` + ) || condition.subtype + ) || `"${condition.subtype}" ${condition.type}` ); }; @@ -135,13 +139,15 @@ export const localizeDeviceAutomationTrigger = ( trigger: DeviceTrigger ) => { const state = trigger.entity_id ? hass.states[trigger.entity_id] : undefined; - return hass.localize( - `component.${trigger.domain}.device_automation.trigger_type.${trigger.type}`, - "entity_name", - state ? computeStateName(state) : "", - "subtype", + return ( hass.localize( - `component.${trigger.domain}.device_automation.trigger_subtype.${trigger.subtype}` - ) + `component.${trigger.domain}.device_automation.trigger_type.${trigger.type}`, + "entity_name", + state ? computeStateName(state) : trigger.entity_id || "", + "subtype", + hass.localize( + `component.${trigger.domain}.device_automation.trigger_subtype.${trigger.subtype}` + ) || trigger.subtype + ) || `"${trigger.subtype}" ${trigger.type}` ); };