mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-25 22:07:20 +00:00
Add automation editor for calendar trigger (#12343)
This commit is contained in:
parent
558ab9761d
commit
36d30266e3
@ -152,6 +152,12 @@ export interface EventTrigger extends BaseTrigger {
|
|||||||
context?: ContextConstraint;
|
context?: ContextConstraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CalendarTrigger extends BaseTrigger {
|
||||||
|
platform: "calendar";
|
||||||
|
event: "start";
|
||||||
|
entity_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type Trigger =
|
export type Trigger =
|
||||||
| StateTrigger
|
| StateTrigger
|
||||||
| MqttTrigger
|
| MqttTrigger
|
||||||
@ -166,7 +172,8 @@ export type Trigger =
|
|||||||
| TimeTrigger
|
| TimeTrigger
|
||||||
| TemplateTrigger
|
| TemplateTrigger
|
||||||
| EventTrigger
|
| EventTrigger
|
||||||
| DeviceTrigger;
|
| DeviceTrigger
|
||||||
|
| CalendarTrigger;
|
||||||
|
|
||||||
interface BaseCondition {
|
interface BaseCondition {
|
||||||
condition: string;
|
condition: string;
|
||||||
|
@ -28,6 +28,7 @@ import {
|
|||||||
} from "../../../../dialogs/generic/show-dialog-box";
|
} from "../../../../dialogs/generic/show-dialog-box";
|
||||||
import { haStyle } from "../../../../resources/styles";
|
import { haStyle } from "../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
|
import "./types/ha-automation-trigger-calendar";
|
||||||
import "./types/ha-automation-trigger-device";
|
import "./types/ha-automation-trigger-device";
|
||||||
import "./types/ha-automation-trigger-event";
|
import "./types/ha-automation-trigger-event";
|
||||||
import "./types/ha-automation-trigger-geo_location";
|
import "./types/ha-automation-trigger-geo_location";
|
||||||
@ -44,6 +45,7 @@ import "./types/ha-automation-trigger-webhook";
|
|||||||
import "./types/ha-automation-trigger-zone";
|
import "./types/ha-automation-trigger-zone";
|
||||||
|
|
||||||
const OPTIONS = [
|
const OPTIONS = [
|
||||||
|
"calendar",
|
||||||
"device",
|
"device",
|
||||||
"event",
|
"event",
|
||||||
"state",
|
"state",
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
import { html, LitElement } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
|
import type { CalendarTrigger } from "../../../../../data/automation";
|
||||||
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
|
import type { TriggerElement } from "../ha-automation-trigger-row";
|
||||||
|
import type { HaFormSchema } from "../../../../../components/ha-form/types";
|
||||||
|
import type { LocalizeFunc } from "../../../../../common/translations/localize";
|
||||||
|
|
||||||
|
@customElement("ha-automation-trigger-calendar")
|
||||||
|
export class HaCalendarTrigger extends LitElement implements TriggerElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public trigger!: CalendarTrigger;
|
||||||
|
|
||||||
|
private _schema = memoizeOne((localize: LocalizeFunc) => [
|
||||||
|
{
|
||||||
|
name: "entity_id",
|
||||||
|
required: true,
|
||||||
|
selector: { entity: { domain: "calendar" } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "event",
|
||||||
|
type: "select",
|
||||||
|
required: true,
|
||||||
|
options: [
|
||||||
|
[
|
||||||
|
"start",
|
||||||
|
localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.type.calendar.start"
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
public static get defaultConfig() {
|
||||||
|
return {
|
||||||
|
event: "start" as CalendarTrigger["event"],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const schema = this._schema(this.hass.localize);
|
||||||
|
return html`
|
||||||
|
<ha-form
|
||||||
|
.schema=${schema}
|
||||||
|
.data=${this.trigger}
|
||||||
|
.hass=${this.hass}
|
||||||
|
.computeLabel=${this._computeLabelCallback}
|
||||||
|
@value-changed=${this._valueChanged}
|
||||||
|
></ha-form>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _valueChanged(ev: CustomEvent): void {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const newTrigger = ev.detail.value;
|
||||||
|
fireEvent(this, "value-changed", { value: newTrigger });
|
||||||
|
}
|
||||||
|
|
||||||
|
private _computeLabelCallback = (schema: HaFormSchema): string =>
|
||||||
|
this.hass.localize(
|
||||||
|
`ui.panel.config.automation.editor.triggers.type.calendar.${schema.name}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-automation-trigger-calendar": HaCalendarTrigger;
|
||||||
|
}
|
||||||
|
}
|
@ -1751,6 +1751,11 @@
|
|||||||
"unsupported_platform": "No visual editor support for platform: {platform}",
|
"unsupported_platform": "No visual editor support for platform: {platform}",
|
||||||
"type_select": "Trigger type",
|
"type_select": "Trigger type",
|
||||||
"type": {
|
"type": {
|
||||||
|
"calendar": {
|
||||||
|
"label": "Calendar",
|
||||||
|
"event": "[%key:ui::panel::config::automation::editor::triggers::type::homeassistant::event%]",
|
||||||
|
"start": "Event Start"
|
||||||
|
},
|
||||||
"device": {
|
"device": {
|
||||||
"label": "Device",
|
"label": "Device",
|
||||||
"trigger": "Trigger",
|
"trigger": "Trigger",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user