mirror of
https://github.com/home-assistant/frontend.git
synced 2026-11-18 02:42:30 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2241eccbc | ||
|
|
225d8fefe3 |
No files matched your search
@@ -672,14 +672,6 @@ export const isCondition = (config: unknown): boolean => {
|
||||
return "condition" in condition && typeof condition.condition === "string";
|
||||
};
|
||||
|
||||
export const isScriptField = (config: unknown): boolean => {
|
||||
if (!config || typeof config !== "object") {
|
||||
return false;
|
||||
}
|
||||
const field = config as Record<string, unknown>;
|
||||
return "field" in field && typeof field.field === "object";
|
||||
};
|
||||
|
||||
export const subscribeTrigger = (
|
||||
hass: HomeAssistant,
|
||||
onChange: (result: {
|
||||
@@ -736,6 +728,7 @@ export interface BaseSidebarConfig {
|
||||
}
|
||||
|
||||
export interface TriggerSidebarConfig extends BaseSidebarConfig {
|
||||
type: "trigger";
|
||||
save: (value: Trigger) => void;
|
||||
replace?: () => void;
|
||||
rename: () => void;
|
||||
@@ -755,6 +748,7 @@ export interface TriggerSidebarConfig extends BaseSidebarConfig {
|
||||
}
|
||||
|
||||
export interface ConditionSidebarConfig extends BaseSidebarConfig {
|
||||
type: "condition";
|
||||
save: (value: Condition) => void;
|
||||
replace?: () => void;
|
||||
rename: () => void;
|
||||
@@ -774,6 +768,7 @@ export interface ConditionSidebarConfig extends BaseSidebarConfig {
|
||||
}
|
||||
|
||||
export interface ActionSidebarConfig extends BaseSidebarConfig {
|
||||
type: "action";
|
||||
save: (value: Action) => void;
|
||||
replace?: () => void;
|
||||
rename: () => void;
|
||||
@@ -795,6 +790,7 @@ export interface ActionSidebarConfig extends BaseSidebarConfig {
|
||||
}
|
||||
|
||||
export interface OptionSidebarConfig extends BaseSidebarConfig {
|
||||
type: "option";
|
||||
save: (value: unknown) => void;
|
||||
rename: () => void;
|
||||
duplicate: () => void;
|
||||
@@ -808,6 +804,7 @@ export interface OptionSidebarConfig extends BaseSidebarConfig {
|
||||
}
|
||||
|
||||
export interface ScriptFieldSidebarConfig extends BaseSidebarConfig {
|
||||
type: "script-field";
|
||||
save: (value: Field) => void;
|
||||
config: {
|
||||
field: Field;
|
||||
|
||||
@@ -1269,6 +1269,7 @@ export default class HaAutomationActionRow extends LitElement {
|
||||
const actionType = getAutomationActionType(sidebarAction);
|
||||
|
||||
fireEvent(this, "open-sidebar", {
|
||||
type: "action",
|
||||
save: (value) => {
|
||||
this._sidebarAction = value;
|
||||
fireEvent(this, "value-changed", { value });
|
||||
|
||||
@@ -980,6 +980,7 @@ export default class HaAutomationConditionRow extends LitElement {
|
||||
const sidebarCondition = condition || this.condition;
|
||||
this._sidebarCondition = sidebarCondition;
|
||||
fireEvent(this, "open-sidebar", {
|
||||
type: "condition",
|
||||
save: (value) => {
|
||||
this._sidebarCondition = value;
|
||||
fireEvent(this, "value-changed", { value });
|
||||
|
||||
@@ -7,20 +7,12 @@ import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||
import { computeRTL } from "../../../common/util/compute_rtl";
|
||||
import "../../../components/ha-snap-bottom-sheet";
|
||||
import type { HaSnapBottomSheet } from "../../../components/ha-snap-bottom-sheet";
|
||||
import {
|
||||
isCondition,
|
||||
isScriptField,
|
||||
isTrigger,
|
||||
type ActionSidebarConfig,
|
||||
type ConditionSidebarConfig,
|
||||
type OptionSidebarConfig,
|
||||
type ScriptFieldSidebarConfig,
|
||||
type SidebarConfig,
|
||||
type TriggerSidebarConfig,
|
||||
import type {
|
||||
ActionSidebarConfig,
|
||||
SidebarConfig,
|
||||
} from "../../../data/automation";
|
||||
import { manifestsContext } from "../../../data/context";
|
||||
import type { DomainManifestLookup } from "../../../data/integration";
|
||||
import { isTriggerList } from "../../../data/trigger";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import "./sidebar/ha-automation-sidebar-action";
|
||||
import type HaAutomationSidebarAction from "./sidebar/ha-automation-sidebar-action";
|
||||
@@ -251,36 +243,12 @@ export default class HaAutomationSidebar extends LitElement {
|
||||
}
|
||||
|
||||
private _getType() {
|
||||
if (
|
||||
(this.config as TriggerSidebarConfig)?.config &&
|
||||
(isTrigger((this.config as TriggerSidebarConfig)?.config) ||
|
||||
isTriggerList((this.config as TriggerSidebarConfig)?.config))
|
||||
) {
|
||||
return "trigger";
|
||||
}
|
||||
if (isCondition((this.config as ConditionSidebarConfig)?.config)) {
|
||||
return "condition";
|
||||
}
|
||||
if (
|
||||
(this.config as ScriptFieldSidebarConfig)?.config &&
|
||||
isScriptField((this.config as ScriptFieldSidebarConfig)?.config)
|
||||
) {
|
||||
return (this.config as ScriptFieldSidebarConfig)?.config.selector
|
||||
if (this.config?.type === "script-field") {
|
||||
return this.config.config.selector
|
||||
? "script-field-selector"
|
||||
: "script-field";
|
||||
}
|
||||
|
||||
// option is a building block; its config only carries the option itself
|
||||
const optionConfig = (this.config as OptionSidebarConfig)?.config;
|
||||
if (this.config && (!optionConfig || "option" in optionConfig)) {
|
||||
return "option";
|
||||
}
|
||||
|
||||
if ((this.config as ActionSidebarConfig)?.config.action) {
|
||||
return "action";
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return this.config?.type;
|
||||
}
|
||||
|
||||
public triggerCloseSidebar(ev?: CustomEvent) {
|
||||
|
||||
@@ -725,6 +725,7 @@ export default class HaAutomationOptionRow extends LitElement {
|
||||
const sidebarOption = option ?? this.option;
|
||||
this._sidebarOption = sidebarOption;
|
||||
fireEvent(this, "open-sidebar", {
|
||||
type: "option",
|
||||
save: (value) => {
|
||||
this._saveYamlOption(value);
|
||||
},
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
type BlueprintTriggersStatus,
|
||||
} from "./automation-trigger-id";
|
||||
import { preserveAutomationRowKeys } from "../ha-automation-sortable-list-mixin";
|
||||
import { isConfigObject } from "../ui-support";
|
||||
|
||||
interface AutomationTriggerControllerOptions {
|
||||
/** Read the editor's current configuration, including after an awaited dialog. */
|
||||
@@ -149,23 +150,18 @@ export class AutomationTriggerController implements ReactiveController {
|
||||
private _isTriggerConditionSidebarActive(
|
||||
sidebarConfig: SidebarConfig | undefined
|
||||
): boolean {
|
||||
if (!sidebarConfig || !("config" in sidebarConfig)) {
|
||||
return false;
|
||||
if (sidebarConfig?.type === "condition") {
|
||||
return sidebarConfig.config.condition === "trigger";
|
||||
}
|
||||
const config = sidebarConfig.config as
|
||||
{ condition?: unknown } | { action?: unknown };
|
||||
if ("condition" in config && config.condition === "trigger") {
|
||||
return true;
|
||||
if (sidebarConfig?.type === "action") {
|
||||
const action = sidebarConfig.config.action;
|
||||
return (
|
||||
isConfigObject(action) &&
|
||||
"condition" in action &&
|
||||
action.condition === "trigger"
|
||||
);
|
||||
}
|
||||
// A row can hold any YAML, so `action` may be a service name instead of
|
||||
// the wrapped action of an action sidebar.
|
||||
return !!(
|
||||
"action" in config &&
|
||||
typeof config.action === "object" &&
|
||||
config.action &&
|
||||
"condition" in config.action &&
|
||||
config.action.condition === "trigger"
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -846,6 +846,7 @@ export default class HaAutomationTriggerRow extends LitElement {
|
||||
public openSidebar(trigger?: Trigger): void {
|
||||
trigger = trigger || this.trigger;
|
||||
fireEvent(this, "open-sidebar", {
|
||||
type: "trigger",
|
||||
save: (value) => {
|
||||
fireEvent(this, "value-changed", { value });
|
||||
},
|
||||
|
||||
@@ -423,6 +423,7 @@ export default class HaScriptFieldRow extends LitElement {
|
||||
const field = fieldValue ?? this.field;
|
||||
|
||||
fireEvent(this, "open-sidebar", {
|
||||
type: "script-field",
|
||||
save: (value) => {
|
||||
fireEvent(this, "value-changed", { value });
|
||||
},
|
||||
|
||||
@@ -212,7 +212,8 @@ describe("AutomationTriggerController.checkShowIndices", () => {
|
||||
return value!.showIndices;
|
||||
};
|
||||
|
||||
const sidebar = (config: unknown) => ({ config }) as unknown as SidebarConfig;
|
||||
const sidebar = (type: SidebarConfig["type"], config: unknown) =>
|
||||
({ type, config }) as unknown as SidebarConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
host = document.createElement("test-automation-trigger-host");
|
||||
@@ -229,27 +230,35 @@ describe("AutomationTriggerController.checkShowIndices", () => {
|
||||
});
|
||||
|
||||
it.each([
|
||||
["a trigger condition", { condition: "trigger", id: "a" }],
|
||||
["a trigger condition", sidebar("condition", { condition: "trigger" })],
|
||||
[
|
||||
"a trigger condition used as action",
|
||||
{ action: { condition: "trigger", id: "a" } },
|
||||
sidebar("action", { action: { condition: "trigger", id: "a" } }),
|
||||
],
|
||||
])("shows the indices for %s", (_name, config) => {
|
||||
controller.checkShowIndices(sidebar(config));
|
||||
])("shows the indices for %s", (_name, sidebarConfig) => {
|
||||
controller.checkShowIndices(sidebarConfig);
|
||||
expect(showIndices()).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["no sidebar", undefined],
|
||||
["another condition", sidebar({ condition: "state" })],
|
||||
["a service action", sidebar({ action: { action: "number.set_value" } })],
|
||||
["another condition", sidebar("condition", { condition: "state" })],
|
||||
[
|
||||
"a service action",
|
||||
sidebar("action", { action: { action: "number.set_value" } }),
|
||||
],
|
||||
// What a condition row holds after an action was entered as YAML.
|
||||
[
|
||||
"a service action in a condition row",
|
||||
sidebar({ action: "number.set_value", data: { value: 20 } }),
|
||||
sidebar("condition", { action: "number.set_value", data: { value: 20 } }),
|
||||
],
|
||||
// What a trigger row holds after a condition was entered as YAML.
|
||||
[
|
||||
"a trigger condition in a trigger row",
|
||||
sidebar("trigger", { condition: "trigger" }),
|
||||
],
|
||||
])("hides the indices for %s", (_name, sidebarConfig) => {
|
||||
controller.checkShowIndices(sidebar({ condition: "trigger" }));
|
||||
controller.checkShowIndices(sidebar("condition", { condition: "trigger" }));
|
||||
controller.checkShowIndices(sidebarConfig);
|
||||
expect(showIndices()).toBe(false);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user