Reintroduce floor context (#22192)

This commit is contained in:
Simon Lamon 2024-10-22 16:21:47 +02:00 committed by GitHub
parent 8932dfd504
commit 849cfed669
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 6 deletions

View File

@ -142,7 +142,7 @@ export class DemoAutomationDescribeAction extends LitElement {
<div class="action"> <div class="action">
<span> <span>
${this._action ${this._action
? describeAction(this.hass, [], [], this._action) ? describeAction(this.hass, [], [], {}, this._action)
: "<invalid YAML>"} : "<invalid YAML>"}
</span> </span>
<ha-yaml-editor <ha-yaml-editor
@ -155,7 +155,7 @@ export class DemoAutomationDescribeAction extends LitElement {
${ACTIONS.map( ${ACTIONS.map(
(conf) => html` (conf) => html`
<div class="action"> <div class="action">
<span>${describeAction(this.hass, [], [], conf as any)}</span> <span>${describeAction(this.hass, [], [], {}, conf as any)}</span>
<pre>${dump(conf)}</pre> <pre>${dump(conf)}</pre>
</div> </div>
` `

View File

@ -22,8 +22,13 @@ import { formatDateTimeWithSeconds } from "../../common/datetime/format_date_tim
import { relativeTime } from "../../common/datetime/relative_time"; import { relativeTime } from "../../common/datetime/relative_time";
import { fireEvent } from "../../common/dom/fire_event"; import { fireEvent } from "../../common/dom/fire_event";
import { toggleAttribute } from "../../common/dom/toggle_attribute"; 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 { EntityRegistryEntry } from "../../data/entity_registry";
import { FloorRegistryEntry } from "../../data/floor_registry";
import { LabelRegistryEntry } from "../../data/label_registry"; import { LabelRegistryEntry } from "../../data/label_registry";
import { LogbookEntry } from "../../data/logbook"; import { LogbookEntry } from "../../data/logbook";
import { import {
@ -201,6 +206,7 @@ class ActionRenderer {
private hass: HomeAssistant, private hass: HomeAssistant,
private entityReg: EntityRegistryEntry[], private entityReg: EntityRegistryEntry[],
private labelReg: LabelRegistryEntry[], private labelReg: LabelRegistryEntry[],
private floorReg: { [id: string]: FloorRegistryEntry },
private entries: TemplateResult[], private entries: TemplateResult[],
private trace: AutomationTraceExtended, private trace: AutomationTraceExtended,
private logbookRenderer: LogbookRenderer, private logbookRenderer: LogbookRenderer,
@ -319,6 +325,7 @@ class ActionRenderer {
this.hass, this.hass,
this.entityReg, this.entityReg,
this.labelReg, this.labelReg,
this.floorReg,
data, data,
actionType actionType
), ),
@ -486,7 +493,13 @@ class ActionRenderer {
const name = const name =
repeatConfig.alias || 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); this._renderEntry(repeatPath, name, undefined, disabled);
@ -584,6 +597,7 @@ class ActionRenderer {
this.hass, this.hass,
this.entityReg, this.entityReg,
this.labelReg, this.labelReg,
this.floorReg,
sequenceConfig, sequenceConfig,
"sequence" "sequence"
), ),
@ -680,6 +694,10 @@ export class HaAutomationTracer extends LitElement {
@consume({ context: labelsContext, subscribe: true }) @consume({ context: labelsContext, subscribe: true })
_labelReg!: LabelRegistryEntry[]; _labelReg!: LabelRegistryEntry[];
@state()
@consume({ context: floorsContext, subscribe: true })
_floorReg!: { [id: string]: FloorRegistryEntry };
protected render() { protected render() {
if (!this.trace) { if (!this.trace) {
return nothing; return nothing;
@ -697,6 +715,7 @@ export class HaAutomationTracer extends LitElement {
this.hass, this.hass,
this._entityReg, this._entityReg,
this._labelReg, this._labelReg,
this._floorReg,
entries, entries,
this.trace, this.trace,
logbookRenderer, logbookRenderer,

View File

@ -27,4 +27,6 @@ export const panelsContext = createContext<HomeAssistant["panels"]>("panels");
export const fullEntitiesContext = export const fullEntitiesContext =
createContext<EntityRegistryEntry[]>("extendedEntities"); createContext<EntityRegistryEntry[]>("extendedEntities");
export const floorsContext = createContext<HomeAssistant["floors"]>("floors");
export const labelsContext = createContext<LabelRegistryEntry[]>("labels"); export const labelsContext = createContext<LabelRegistryEntry[]>("labels");

View File

@ -14,6 +14,7 @@ import {
computeEntityRegistryName, computeEntityRegistryName,
entityRegistryById, entityRegistryById,
} from "./entity_registry"; } from "./entity_registry";
import { FloorRegistryEntry } from "./floor_registry";
import { domainToName } from "./integration"; import { domainToName } from "./integration";
import { LabelRegistryEntry } from "./label_registry"; import { LabelRegistryEntry } from "./label_registry";
import { import {
@ -43,6 +44,7 @@ export const describeAction = <T extends ActionType>(
hass: HomeAssistant, hass: HomeAssistant,
entityRegistry: EntityRegistryEntry[], entityRegistry: EntityRegistryEntry[],
labelRegistry: LabelRegistryEntry[], labelRegistry: LabelRegistryEntry[],
floorRegistry: { [id: string]: FloorRegistryEntry },
action: ActionTypes[T], action: ActionTypes[T],
actionType?: T, actionType?: T,
ignoreAlias = false ignoreAlias = false
@ -52,6 +54,7 @@ export const describeAction = <T extends ActionType>(
hass, hass,
entityRegistry, entityRegistry,
labelRegistry, labelRegistry,
floorRegistry,
action, action,
actionType, actionType,
ignoreAlias ignoreAlias
@ -75,6 +78,7 @@ const tryDescribeAction = <T extends ActionType>(
hass: HomeAssistant, hass: HomeAssistant,
entityRegistry: EntityRegistryEntry[], entityRegistry: EntityRegistryEntry[],
labelRegistry: LabelRegistryEntry[], labelRegistry: LabelRegistryEntry[],
floorRegistry: { [id: string]: FloorRegistryEntry },
action: ActionTypes[T], action: ActionTypes[T],
actionType?: T, actionType?: T,
ignoreAlias = false ignoreAlias = false
@ -164,7 +168,7 @@ const tryDescribeAction = <T extends ActionType>(
); );
} }
} else if (key === "floor_id") { } else if (key === "floor_id") {
const floor = hass.floors[targetThing] ?? undefined; const floor = floorRegistry[targetThing] ?? undefined;
if (floor?.name) { if (floor?.name) {
targets.push(floor.name); targets.push(floor.name);
} else { } else {

View File

@ -43,8 +43,13 @@ import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
import { ACTION_ICONS, YAML_ONLY_ACTION_TYPES } from "../../../../data/action"; import { ACTION_ICONS, YAML_ONLY_ACTION_TYPES } from "../../../../data/action";
import { AutomationClipboard } from "../../../../data/automation"; import { AutomationClipboard } from "../../../../data/automation";
import { validateConfig } from "../../../../data/config"; 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 { EntityRegistryEntry } from "../../../../data/entity_registry";
import { FloorRegistryEntry } from "../../../../data/floor_registry";
import { LabelRegistryEntry } from "../../../../data/label_registry"; import { LabelRegistryEntry } from "../../../../data/label_registry";
import { import {
Action, Action,
@ -154,6 +159,10 @@ export default class HaAutomationActionRow extends LitElement {
@consume({ context: labelsContext, subscribe: true }) @consume({ context: labelsContext, subscribe: true })
_labelReg!: LabelRegistryEntry[]; _labelReg!: LabelRegistryEntry[];
@state()
@consume({ context: floorsContext, subscribe: true })
_floorReg!: { [id: string]: FloorRegistryEntry };
@state() private _warnings?: string[]; @state() private _warnings?: string[];
@state() private _uiModeAvailable = true; @state() private _uiModeAvailable = true;
@ -222,6 +231,7 @@ export default class HaAutomationActionRow extends LitElement {
this.hass, this.hass,
this._entityReg, this._entityReg,
this._labelReg, this._labelReg,
this._floorReg,
this.action this.action
) )
)} )}
@ -593,6 +603,7 @@ export default class HaAutomationActionRow extends LitElement {
this.hass, this.hass,
this._entityReg, this._entityReg,
this._labelReg, this._labelReg,
this._floorReg,
this.action, this.action,
undefined, undefined,
true true

View File

@ -5,6 +5,7 @@ import {
connectionContext, connectionContext,
devicesContext, devicesContext,
entitiesContext, entitiesContext,
floorsContext,
localeContext, localeContext,
localizeContext, localizeContext,
panelsContext, panelsContext,
@ -87,6 +88,10 @@ export const contextMixin = <T extends Constructor<HassBaseEl>>(
context: panelsContext, context: panelsContext,
initialValue: this.hass ? this.hass.panels : this._pendingHass.panels, 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() { protected hassConnected() {