1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-17 23:54:28 +01:00

Fix possible undefined errors in transformer functions (#30299)

This commit is contained in:
Wendelin
2026-03-24 17:37:24 +01:00
committed by GitHub
parent c506fa8990
commit 6ea15f507a
4 changed files with 11 additions and 9 deletions

View File

@@ -1,10 +1,12 @@
import { consume } from "@lit/context";
import type { CSSResult, TemplateResult, LitElement } from "lit";
import type { CSSResult, LitElement, TemplateResult } from "lit";
import { css, html } from "lit";
import { property, state } from "lit/decorators";
import { transform } from "../../../common/decorators/transform";
import { goBack, navigate } from "../../../common/navigate";
import { afterNextRender } from "../../../common/util/render-status";
import "../../../components/ha-fade-in";
import "../../../components/ha-spinner"; // used by renderLoading() provided to both editors
import { fullEntitiesContext } from "../../../data/context";
import type { EntityRegistryEntry } from "../../../data/entity/entity_registry";
import {
@@ -14,8 +16,6 @@ import {
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
import type { Constructor, HomeAssistant, Route } from "../../../types";
import type { EntityRegistryUpdate } from "./automation-save-dialog/show-dialog-automation-save";
import "../../../components/ha-fade-in";
import "../../../components/ha-spinner"; // used by renderLoading() provided to both editors
/** Minimum config shape shared by both AutomationConfig and ScriptConfig. */
interface BaseEditorConfig {
@@ -119,7 +119,7 @@ export const AutomationScriptEditorMixin = <TConfig extends BaseEditorConfig>(
@consume({ context: fullEntitiesContext, subscribe: true })
@transform<EntityRegistryEntry[], EntityRegistryEntry>({
transformer: function (this: { currentEntityId?: string }, value) {
return value.find(
return value?.find(
({ entity_id }) => entity_id === this.currentEntityId
);
},

View File

@@ -63,7 +63,9 @@ export class HaAutomationRowTargets extends LitElement {
@consume({ context: configEntriesContext, subscribe: true })
@transform<ConfigEntry[], Record<string, ConfigEntry>>({
transformer: function (value) {
return Object.fromEntries(value.map((entry) => [entry.entry_id, entry]));
return value
? Object.fromEntries(value.map((entry) => [entry.entry_id, entry]))
: undefined;
},
})
private _configEntryLookup?: Record<string, ConfigEntry>;

View File

@@ -36,6 +36,7 @@ import "../../../components/ha-alert";
import "../../../components/ha-button";
import "../../../components/ha-card";
import "../../../components/ha-dropdown";
import type { HaDropdownSelectEvent } from "../../../components/ha-dropdown";
import "../../../components/ha-dropdown-item";
import "../../../components/ha-fab";
import "../../../components/ha-icon-button";
@@ -79,7 +80,6 @@ import {
showSceneSaveDialog,
type EntityRegistryUpdate,
} from "./scene-save-dialog/show-dialog-scene-save";
import type { HaDropdownSelectEvent } from "../../../components/ha-dropdown";
interface DeviceEntities {
id: string;
@@ -123,7 +123,7 @@ export class HaSceneEditor extends PreventUnsavedMixin(
@consume({ context: fullEntitiesContext, subscribe: true })
@transform<EntityRegistryEntry[], EntityRegistryEntry>({
transformer: function (this: HaSceneEditor, value) {
return value.find(
return value?.find(
({ entity_id }) => entity_id === this._scene?.entity_id
);
},

View File

@@ -92,7 +92,7 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
@consume<any>({ context: statesContext, subscribe: true })
@transform({
transformer: function (this: HuiButtonCard, value: HassEntities) {
return this._config?.entity ? value[this._config?.entity] : undefined;
return this._config?.entity ? value?.[this._config?.entity] : undefined;
},
watch: ["_config"],
})
@@ -118,7 +118,7 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
@consume<any>({ context: entitiesContext, subscribe: true })
@transform<HomeAssistant["entities"], EntityRegistryDisplayEntry>({
transformer: function (this: HuiButtonCard, value) {
return this._config?.entity ? value[this._config?.entity] : undefined;
return this._config?.entity ? value?.[this._config?.entity] : undefined;
},
watch: ["_config"],
})