From d21a978e6172a691bff5c11de9c9dfd48d01b010 Mon Sep 17 00:00:00 2001 From: Kendell R Date: Mon, 25 Sep 2023 17:00:05 -0700 Subject: [PATCH] fix undefines --- hassio/src/addon-view/hassio-addon-dashboard.ts | 2 +- hassio/src/addon-view/info/hassio-addon-info.ts | 2 +- .../update-available/update-available-card.ts | 2 +- src/auth/ha-auth-flow.ts | 2 +- src/common/translations/localize.ts | 7 ++++++- src/components/ha-area-picker.ts | 2 +- src/components/ha-assist-pipeline-picker.ts | 17 ++++++++++------- src/components/ha-file-upload.ts | 2 +- src/data/automation_i18n.ts | 4 ++-- src/data/script_i18n.ts | 17 +++++++++++------ src/dialogs/more-info/ha-more-info-info.ts | 2 +- .../configurator-notification-item.ts | 2 +- .../config/automation/ha-automation-editor.ts | 2 +- .../ha-disabled-config-entry-card.ts | 2 +- src/panels/config/logs/error-log-card.ts | 3 +-- src/panels/config/repairs/ha-config-repairs.ts | 2 +- src/panels/config/scene/ha-scene-editor.ts | 2 +- src/panels/config/script/ha-script-editor.ts | 2 +- .../cards/energy/hui-energy-gas-graph-card.ts | 2 +- .../cards/energy/hui-energy-water-graph-card.ts | 2 +- src/panels/profile/ha-refresh-tokens-card.ts | 2 +- 21 files changed, 46 insertions(+), 34 deletions(-) diff --git a/hassio/src/addon-view/hassio-addon-dashboard.ts b/hassio/src/addon-view/hassio-addon-dashboard.ts index 4bb888290fac..0ae5370b2c70 100644 --- a/hassio/src/addon-view/hassio-addon-dashboard.ts +++ b/hassio/src/addon-view/hassio-addon-dashboard.ts @@ -183,7 +183,7 @@ class HassioAddonDashboard extends LitElement { if (this.route.path === "") { const requestedAddon = extractSearchParam("addon"); const requestedAddonRepository = extractSearchParam("repository_url"); - if (requestedAddonRepository) { + if (requestedAddon && requestedAddonRepository) { const storeInfo = await fetchSupervisorStore(this.hass); if ( !storeInfo.repositories.find( diff --git a/hassio/src/addon-view/info/hassio-addon-info.ts b/hassio/src/addon-view/info/hassio-addon-info.ts index 7a935518cc32..0fb8800b331f 100644 --- a/hassio/src/addon-view/info/hassio-addon-info.ts +++ b/hassio/src/addon-view/info/hassio-addon-info.ts @@ -577,7 +577,7 @@ class HassioAddonInfo extends LitElement { "addon.dashboard.not_available_version", { core_version_installed: this.supervisor.core.version, - core_version_needed: addonStoreInfo!.homeassistant, + core_version_needed: addonStoreInfo!.homeassistant!, } )} diff --git a/hassio/src/update-available/update-available-card.ts b/hassio/src/update-available/update-available-card.ts index c9fcb74d5e8e..86988c010a54 100644 --- a/hassio/src/update-available/update-available-card.ts +++ b/hassio/src/update-available/update-available-card.ts @@ -312,7 +312,7 @@ class UpdateAvailableCard extends LitElement { "addon.dashboard.not_available_version", { core_version_installed: this.supervisor.core.version, - core_version_needed: addonStoreInfo.homeassistant, + core_version_needed: addonStoreInfo.homeassistant!, } ); } diff --git a/src/auth/ha-auth-flow.ts b/src/auth/ha-auth-flow.ts index e0841ebe3803..2a90c3071c9d 100644 --- a/src/auth/ha-auth-flow.ts +++ b/src/auth/ha-auth-flow.ts @@ -160,7 +160,7 @@ export class HaAuthFlow extends LitElement { return html` ${this.localize("ui.panel.page-authorize.form.error", { - error: this._errorMessage, + error: this._errorMessage!, })}
diff --git a/src/common/translations/localize.ts b/src/common/translations/localize.ts index f40c11b8ea48..8cff8c6c58ff 100644 --- a/src/common/translations/localize.ts +++ b/src/common/translations/localize.ts @@ -1,4 +1,5 @@ import IntlMessageFormat from "intl-messageformat"; +import type { HTMLTemplateResult } from "lit"; import { polyfillLocaleData } from "../../resources/locale-data-polyfill"; import { Resources, TranslationDict } from "../../types"; @@ -42,7 +43,7 @@ export type FlattenObjectKeys< export type LocalizeFunc = ( key: Keys, - values?: Record + values?: Record ) => string; interface FormatType { @@ -101,6 +102,10 @@ export const computeLocalize = async ( const args = _args as any; if (args.length === 1 && typeof args[0] === "object") { argObject = args[0]; + if (Object.values(argObject).some((v) => v === undefined)) { + // eslint-disable-next-line no-console + console.warn("[FIXME] While localizing", key, "undefined was passed"); + } } else if (args.length >= 2) { // eslint-disable-next-line no-console console.warn("[FIXME] While localizing", key, "old format was passed"); diff --git a/src/components/ha-area-picker.ts b/src/components/ha-area-picker.ts index 5d56c6908203..9ed8cdf709f5 100644 --- a/src/components/ha-area-picker.ts +++ b/src/components/ha-area-picker.ts @@ -364,7 +364,7 @@ export class HaAreaPicker extends LitElement { area_id: "add_new_suggestion", name: this.hass.localize( "ui.components.area-picker.add_new_sugestion", - { name: this._suggestion } + { name: this._suggestion! } ), picture: null, }, diff --git a/src/components/ha-assist-pipeline-picker.ts b/src/components/ha-assist-pipeline-picker.ts index 80a69b2d2799..60a6aae1816a 100644 --- a/src/components/ha-assist-pipeline-picker.ts +++ b/src/components/ha-assist-pipeline-picker.ts @@ -46,6 +46,9 @@ export class HaAssistPipelinePicker extends LitElement { return nothing; } const value = this.value ?? this._default; + const preferredPipeline = this._pipelines.find( + (pipeline) => pipeline.id === this._preferredPipeline + ); return html` ` : null} - - ${this.hass!.localize("ui.components.pipeline-picker.preferred", { - preferred: this._pipelines.find( - (pipeline) => pipeline.id === this._preferredPipeline - )?.name, - })} - + ${preferredPipeline + ? html` + ${this.hass!.localize("ui.components.pipeline-picker.preferred", { + preferred: preferredPipeline.name, + })} + ` + : null} ${this._pipelines.map( (pipeline) => html` diff --git a/src/components/ha-file-upload.ts b/src/components/ha-file-upload.ts index cc0e97a29c72..7c2b133ae308 100644 --- a/src/components/ha-file-upload.ts +++ b/src/components/ha-file-upload.ts @@ -64,7 +64,7 @@ export class HaFileUpload extends LitElement { >${this.value ? this.hass?.localize( "ui.components.file-upload.uploading_name", - { name: this.value } + { name: this.value.toString() } ) : this.hass?.localize( "ui.components.file-upload.uploading" diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts index 244fad1ba3ef..aa3d72bd0746 100644 --- a/src/data/automation_i18n.ts +++ b/src/data/automation_i18n.ts @@ -336,7 +336,7 @@ const tryDescribeTrigger = ( trigger.event === "sunset" ? `${triggerTranslationBaseKey}.sun.description.sets` : `${triggerTranslationBaseKey}.sun.description.rises`, - { hasDuration: duration !== "", duration: duration } + { hasDuration: duration !== "" ? "true" : "", duration: duration } ); } @@ -561,7 +561,7 @@ const tryDescribeTrigger = ( return hass.localize( `${triggerTranslationBaseKey}.template.description.full`, - { hasDuration: duration !== "", duration: duration } + { hasDuration: duration !== "" ? "true" : "", duration: duration } ); } diff --git a/src/data/script_i18n.ts b/src/data/script_i18n.ts index 09e25862b3cd..5bbf39ba9722 100644 --- a/src/data/script_i18n.ts +++ b/src/data/script_i18n.ts @@ -213,7 +213,7 @@ const tryDescribeAction = ( duration = hass.localize( `${actionTranslationBaseKey}.delay.description.duration_string`, { - string: formatDuration(config.delay), + string: formatDuration(config.delay)!, } ); } else { @@ -259,10 +259,15 @@ const tryDescribeAction = ( return hass.localize( `${actionTranslationBaseKey}.play_media.description.full`, { - hasMedia: config.metadata.title || config.data.media_content_id, - media: config.metadata.title || config.data.media_content_id, - hasMediaPlayer: mediaStateObj ? true : entityId !== undefined, - mediaPlayer: mediaStateObj ? computeStateName(mediaStateObj) : entityId, + hasMedia: + config.metadata.title || config.data.media_content_id ? "true" : "", + media: + (config.metadata.title as string | undefined) || + config.data.media_content_id, + hasMediaPlayer: mediaStateObj || entityId !== undefined ? "true" : "", + mediaPlayer: mediaStateObj + ? computeStateName(mediaStateObj) + : entityId!, } ); } @@ -317,7 +322,7 @@ const tryDescribeAction = ( if (actionType === "stop") { const config = action as StopAction; return hass.localize(`${actionTranslationBaseKey}.stop.description.full`, { - hasReason: config.stop !== undefined, + hasReason: config.stop !== undefined ? "true" : "", reason: config.stop, }); } diff --git a/src/dialogs/more-info/ha-more-info-info.ts b/src/dialogs/more-info/ha-more-info-info.ts index 1df9ef1401d3..7954e489284b 100644 --- a/src/dialogs/more-info/ha-more-info-info.ts +++ b/src/dialogs/more-info/ha-more-info-info.ts @@ -55,7 +55,7 @@ export class MoreInfoInfo extends LitElement { ${this.hass.localize( "ui.dialogs.more_info_control.restored.no_longer_provided", { - integration: entityRegObj.platform, + integration: entityRegObj.platform!, } )} ` diff --git a/src/dialogs/notifications/configurator-notification-item.ts b/src/dialogs/notifications/configurator-notification-item.ts index ae69269952d1..e5f163d32e29 100644 --- a/src/dialogs/notifications/configurator-notification-item.ts +++ b/src/dialogs/notifications/configurator-notification-item.ts @@ -26,7 +26,7 @@ export class HuiConfiguratorNotificationItem extends LitElement {
${this.hass.localize("ui.notification_drawer.click_to_configure", { - entity: this.notification.attributes.friendly_name, + entity: this.notification.attributes.friendly_name!, })}
diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts index f3b8b0690063..acec8d6102db 100644 --- a/src/panels/config/automation/ha-automation-editor.ts +++ b/src/panels/config/automation/ha-automation-editor.ts @@ -672,7 +672,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) { ), text: this.hass.localize( "ui.panel.config.automation.picker.delete_confirm_text", - { name: this._config?.alias } + { name: this._config!.alias! } ), confirmText: this.hass!.localize("ui.common.delete"), destructive: true, diff --git a/src/panels/config/integrations/ha-disabled-config-entry-card.ts b/src/panels/config/integrations/ha-disabled-config-entry-card.ts index f6003515aead..49b285ab3b4f 100644 --- a/src/panels/config/integrations/ha-disabled-config-entry-card.ts +++ b/src/panels/config/integrations/ha-disabled-config-entry-card.ts @@ -32,7 +32,7 @@ export class HaDisabledConfigEntryCard extends LitElement { this.hass.localize( `ui.panel.config.integrations.config_entry.disable.disabled_by.${this .entry.disabled_by!}` - ) || this.entry.disabled_by, + ) || this.entry.disabled_by!, } )} .domain=${this.entry.domain} diff --git a/src/panels/config/logs/error-log-card.ts b/src/panels/config/logs/error-log-card.ts index 3e688149cc9c..b127edeaa096 100644 --- a/src/panels/config/logs/error-log-card.ts +++ b/src/panels/config/logs/error-log-card.ts @@ -179,8 +179,7 @@ class ErrorLogCard extends LitElement { } catch (err: any) { this._error = this.hass.localize( "ui.panel.config.logs.failed_get_logs", - {provider:this.provider, - error:extractApiErrorMessage(err)} + { provider: this.provider, error: extractApiErrorMessage(err) } ); return; } diff --git a/src/panels/config/repairs/ha-config-repairs.ts b/src/panels/config/repairs/ha-config-repairs.ts index 1643de6b06a0..1a17b8caec9e 100644 --- a/src/panels/config/repairs/ha-config-repairs.ts +++ b/src/panels/config/repairs/ha-config-repairs.ts @@ -92,7 +92,7 @@ class HaConfigRepairs extends LitElement { ${issue.ignored ? ` - ${this.hass.localize( "ui.panel.config.repairs.dialog.ignored_in_version_short", - { version: issue.dismissed_version } + { version: issue.dismissed_version! } )}` : ""} diff --git a/src/panels/config/scene/ha-scene-editor.ts b/src/panels/config/scene/ha-scene-editor.ts index 816b63100156..8631569b2201 100644 --- a/src/panels/config/scene/ha-scene-editor.ts +++ b/src/panels/config/scene/ha-scene-editor.ts @@ -768,7 +768,7 @@ export class HaSceneEditor extends SubscribeMixin( ), text: this.hass!.localize( "ui.panel.config.scene.picker.delete_confirm_text", - { name: this._config?.name } + { name: this._config!.name } ), confirmText: this.hass!.localize("ui.common.delete"), dismissText: this.hass!.localize("ui.common.cancel"), diff --git a/src/panels/config/script/ha-script-editor.ts b/src/panels/config/script/ha-script-editor.ts index 1ed7527f3ca5..0fe53de70957 100644 --- a/src/panels/config/script/ha-script-editor.ts +++ b/src/panels/config/script/ha-script-editor.ts @@ -779,7 +779,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) { ), text: this.hass.localize( "ui.panel.config.script.editor.delete_confirm_text", - { name: this._config?.alias } + { name: this._config!.alias } ), confirmText: this.hass!.localize("ui.common.delete"), dismissText: this.hass!.localize("ui.common.cancel"), diff --git a/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts index 3a67549e4f10..22b76a72232d 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-gas-graph-card.ts @@ -254,7 +254,7 @@ export class HuiEnergyGasGraphCard return [ this.hass.localize( "ui.panel.lovelace.cards.energy.energy_gas_graph.total_consumed", - { num: formatNumber(total, locale), unit } + { num: formatNumber(total, locale), unit: unit! } ), ]; }, diff --git a/src/panels/lovelace/cards/energy/hui-energy-water-graph-card.ts b/src/panels/lovelace/cards/energy/hui-energy-water-graph-card.ts index 4fc102ebf2a9..3fd779143729 100644 --- a/src/panels/lovelace/cards/energy/hui-energy-water-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-energy-water-graph-card.ts @@ -254,7 +254,7 @@ export class HuiEnergyWaterGraphCard return [ this.hass.localize( "ui.panel.lovelace.cards.energy.energy_water_graph.total_consumed", - { num: formatNumber(total, locale), unit } + { num: formatNumber(total, locale), unit: unit! } ), ]; }, diff --git a/src/panels/profile/ha-refresh-tokens-card.ts b/src/panels/profile/ha-refresh-tokens-card.ts index 6217936dcb46..24df4c7f738e 100644 --- a/src/panels/profile/ha-refresh-tokens-card.ts +++ b/src/panels/profile/ha-refresh-tokens-card.ts @@ -70,7 +70,7 @@ class HaRefreshTokens extends LitElement { )}
- ${token.last_used_at + ${token.last_used_at && token.last_used_ip ? this.hass.localize( "ui.panel.profile.refresh_tokens.last_used", {