Skip to content

Commit

Permalink
Reintroduce floor context (#22192)
Browse files Browse the repository at this point in the history
  • Loading branch information
silamon authored Oct 22, 2024
1 parent 8932dfd commit 849cfed
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gallery/src/pages/automation/describe-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class DemoAutomationDescribeAction extends LitElement {
<div class="action">
<span>
${this._action
? describeAction(this.hass, [], [], this._action)
? describeAction(this.hass, [], [], {}, this._action)
: "<invalid YAML>"}
</span>
<ha-yaml-editor
Expand All @@ -155,7 +155,7 @@ export class DemoAutomationDescribeAction extends LitElement {
${ACTIONS.map(
(conf) => html`
<div class="action">
<span>${describeAction(this.hass, [], [], conf as any)}</span>
<span>${describeAction(this.hass, [], [], {}, conf as any)}</span>
<pre>${dump(conf)}</pre>
</div>
`
Expand Down
23 changes: 21 additions & 2 deletions src/components/trace/hat-trace-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ import { formatDateTimeWithSeconds } from "../../common/datetime/format_date_tim
import { relativeTime } from "../../common/datetime/relative_time";
import { fireEvent } from "../../common/dom/fire_event";
import { toggleAttribute } from "../../common/dom/toggle_attribute";
import { fullEntitiesContext, labelsContext } from "../../data/context";
import {
floorsContext,
fullEntitiesContext,
labelsContext,
} from "../../data/context";
import { EntityRegistryEntry } from "../../data/entity_registry";
import { FloorRegistryEntry } from "../../data/floor_registry";
import { LabelRegistryEntry } from "../../data/label_registry";
import { LogbookEntry } from "../../data/logbook";
import {
Expand Down Expand Up @@ -201,6 +206,7 @@ class ActionRenderer {
private hass: HomeAssistant,
private entityReg: EntityRegistryEntry[],
private labelReg: LabelRegistryEntry[],
private floorReg: { [id: string]: FloorRegistryEntry },
private entries: TemplateResult[],
private trace: AutomationTraceExtended,
private logbookRenderer: LogbookRenderer,
Expand Down Expand Up @@ -319,6 +325,7 @@ class ActionRenderer {
this.hass,
this.entityReg,
this.labelReg,
this.floorReg,
data,
actionType
),
Expand Down Expand Up @@ -486,7 +493,13 @@ class ActionRenderer {

const name =
repeatConfig.alias ||
describeAction(this.hass, this.entityReg, this.labelReg, repeatConfig);
describeAction(
this.hass,
this.entityReg,
this.labelReg,
this.floorReg,
repeatConfig
);

this._renderEntry(repeatPath, name, undefined, disabled);

Expand Down Expand Up @@ -584,6 +597,7 @@ class ActionRenderer {
this.hass,
this.entityReg,
this.labelReg,
this.floorReg,
sequenceConfig,
"sequence"
),
Expand Down Expand Up @@ -680,6 +694,10 @@ export class HaAutomationTracer extends LitElement {
@consume({ context: labelsContext, subscribe: true })
_labelReg!: LabelRegistryEntry[];

@state()
@consume({ context: floorsContext, subscribe: true })
_floorReg!: { [id: string]: FloorRegistryEntry };

protected render() {
if (!this.trace) {
return nothing;
Expand All @@ -697,6 +715,7 @@ export class HaAutomationTracer extends LitElement {
this.hass,
this._entityReg,
this._labelReg,
this._floorReg,
entries,
this.trace,
logbookRenderer,
Expand Down
2 changes: 2 additions & 0 deletions src/data/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ export const panelsContext = createContext<HomeAssistant["panels"]>("panels");
export const fullEntitiesContext =
createContext<EntityRegistryEntry[]>("extendedEntities");

export const floorsContext = createContext<HomeAssistant["floors"]>("floors");

export const labelsContext = createContext<LabelRegistryEntry[]>("labels");
6 changes: 5 additions & 1 deletion src/data/script_i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
computeEntityRegistryName,
entityRegistryById,
} from "./entity_registry";
import { FloorRegistryEntry } from "./floor_registry";
import { domainToName } from "./integration";
import { LabelRegistryEntry } from "./label_registry";
import {
Expand Down Expand Up @@ -43,6 +44,7 @@ export const describeAction = <T extends ActionType>(
hass: HomeAssistant,
entityRegistry: EntityRegistryEntry[],
labelRegistry: LabelRegistryEntry[],
floorRegistry: { [id: string]: FloorRegistryEntry },
action: ActionTypes[T],
actionType?: T,
ignoreAlias = false
Expand All @@ -52,6 +54,7 @@ export const describeAction = <T extends ActionType>(
hass,
entityRegistry,
labelRegistry,
floorRegistry,
action,
actionType,
ignoreAlias
Expand All @@ -75,6 +78,7 @@ const tryDescribeAction = <T extends ActionType>(
hass: HomeAssistant,
entityRegistry: EntityRegistryEntry[],
labelRegistry: LabelRegistryEntry[],
floorRegistry: { [id: string]: FloorRegistryEntry },
action: ActionTypes[T],
actionType?: T,
ignoreAlias = false
Expand Down Expand Up @@ -164,7 +168,7 @@ const tryDescribeAction = <T extends ActionType>(
);
}
} else if (key === "floor_id") {
const floor = hass.floors[targetThing] ?? undefined;
const floor = floorRegistry[targetThing] ?? undefined;
if (floor?.name) {
targets.push(floor.name);
} else {
Expand Down
13 changes: 12 additions & 1 deletion src/panels/config/automation/action/ha-automation-action-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
import { ACTION_ICONS, YAML_ONLY_ACTION_TYPES } from "../../../../data/action";
import { AutomationClipboard } from "../../../../data/automation";
import { validateConfig } from "../../../../data/config";
import { fullEntitiesContext, labelsContext } from "../../../../data/context";
import {
floorsContext,
fullEntitiesContext,
labelsContext,
} from "../../../../data/context";
import { EntityRegistryEntry } from "../../../../data/entity_registry";
import { FloorRegistryEntry } from "../../../../data/floor_registry";
import { LabelRegistryEntry } from "../../../../data/label_registry";
import {
Action,
Expand Down Expand Up @@ -154,6 +159,10 @@ export default class HaAutomationActionRow extends LitElement {
@consume({ context: labelsContext, subscribe: true })
_labelReg!: LabelRegistryEntry[];

@state()
@consume({ context: floorsContext, subscribe: true })
_floorReg!: { [id: string]: FloorRegistryEntry };

@state() private _warnings?: string[];

@state() private _uiModeAvailable = true;
Expand Down Expand Up @@ -222,6 +231,7 @@ export default class HaAutomationActionRow extends LitElement {
this.hass,
this._entityReg,
this._labelReg,
this._floorReg,
this.action
)
)}
Expand Down Expand Up @@ -593,6 +603,7 @@ export default class HaAutomationActionRow extends LitElement {
this.hass,
this._entityReg,
this._labelReg,
this._floorReg,
this.action,
undefined,
true
Expand Down
5 changes: 5 additions & 0 deletions src/state/context-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
connectionContext,
devicesContext,
entitiesContext,
floorsContext,
localeContext,
localizeContext,
panelsContext,
Expand Down Expand Up @@ -87,6 +88,10 @@ export const contextMixin = <T extends Constructor<HassBaseEl>>(
context: panelsContext,
initialValue: this.hass ? this.hass.panels : this._pendingHass.panels,
}),
floors: new ContextProvider(this, {
context: floorsContext,
initialValue: this.hass ? this.hass.floors : this._pendingHass.floors,
}),
};

protected hassConnected() {
Expand Down

0 comments on commit 849cfed

Please sign in to comment.