Skip to content

Commit

Permalink
fix undefines
Browse files Browse the repository at this point in the history
  • Loading branch information
KTibow committed Sep 26, 2023
1 parent 89e3cbf commit d21a978
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 34 deletions.
2 changes: 1 addition & 1 deletion hassio/src/addon-view/hassio-addon-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion hassio/src/addon-view/info/hassio-addon-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
}
)}
</ha-alert>
Expand Down
2 changes: 1 addition & 1 deletion hassio/src/update-available/update-available-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/ha-auth-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export class HaAuthFlow extends LitElement {
return html`
<ha-alert alert-type="error">
${this.localize("ui.panel.page-authorize.form.error", {
error: this._errorMessage,
error: this._errorMessage!,
})}
</ha-alert>
<div class="action">
Expand Down
7 changes: 6 additions & 1 deletion src/common/translations/localize.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -42,7 +43,7 @@ export type FlattenObjectKeys<

export type LocalizeFunc<Keys extends string = LocalizeKeys> = (
key: Keys,
values?: Record<string, any>
values?: Record<string, string | number | HTMLTemplateResult>
) => string;

interface FormatType {
Expand Down Expand Up @@ -101,6 +102,10 @@ export const computeLocalize = async <Keys extends string = LocalizeKeys>(
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");
Expand Down
2 changes: 1 addition & 1 deletion src/components/ha-area-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
17 changes: 10 additions & 7 deletions src/components/ha-assist-pipeline-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<ha-select
.label=${this.label ||
Expand All @@ -67,13 +70,13 @@ export class HaAssistPipelinePicker extends LitElement {
</ha-list-item>
`
: null}
<ha-list-item .value=${PREFERRED}>
${this.hass!.localize("ui.components.pipeline-picker.preferred", {
preferred: this._pipelines.find(
(pipeline) => pipeline.id === this._preferredPipeline
)?.name,
})}
</ha-list-item>
${preferredPipeline
? html`<ha-list-item .value=${PREFERRED}>
${this.hass!.localize("ui.components.pipeline-picker.preferred", {
preferred: preferredPipeline.name,
})}
</ha-list-item>`
: null}
${this._pipelines.map(
(pipeline) =>
html`<ha-list-item .value=${pipeline.id}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ha-file-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/data/automation_i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
);
}

Expand Down Expand Up @@ -561,7 +561,7 @@ const tryDescribeTrigger = (

return hass.localize(
`${triggerTranslationBaseKey}.template.description.full`,
{ hasDuration: duration !== "", duration: duration }
{ hasDuration: duration !== "" ? "true" : "", duration: duration }
);
}

Expand Down
17 changes: 11 additions & 6 deletions src/data/script_i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const tryDescribeAction = <T extends ActionType>(
duration = hass.localize(
`${actionTranslationBaseKey}.delay.description.duration_string`,
{
string: formatDuration(config.delay),
string: formatDuration(config.delay)!,
}
);
} else {
Expand Down Expand Up @@ -259,10 +259,15 @@ const tryDescribeAction = <T extends ActionType>(
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!,
}
);
}
Expand Down Expand Up @@ -317,7 +322,7 @@ const tryDescribeAction = <T extends ActionType>(
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,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/more-info/ha-more-info-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
}
)}
</ha-alert>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class HuiConfiguratorNotificationItem extends LitElement {
<div>
${this.hass.localize("ui.notification_drawer.click_to_configure", {
entity: this.notification.attributes.friendly_name,
entity: this.notification.attributes.friendly_name!,
})}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/automation/ha-automation-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
3 changes: 1 addition & 2 deletions src/panels/config/logs/error-log-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/repairs/ha-config-repairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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! }
)}`
: ""}
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/scene/ha-scene-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/script/ha-script-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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! }
),
];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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! }
),
];
},
Expand Down
2 changes: 1 addition & 1 deletion src/panels/profile/ha-refresh-tokens-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class HaRefreshTokens extends LitElement {
)}
</div>
<div slot="description">
${token.last_used_at
${token.last_used_at && token.last_used_ip
? this.hass.localize(
"ui.panel.profile.refresh_tokens.last_used",
{
Expand Down

0 comments on commit d21a978

Please sign in to comment.