mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-04 06:57:47 +00:00
Add persistent_notification trigger
This commit is contained in:
parent
41310007fe
commit
4526a46a56
@ -41,6 +41,7 @@ const triggers = [
|
|||||||
{ platform: "sun", event: "sunset" },
|
{ platform: "sun", event: "sunset" },
|
||||||
{ platform: "time_pattern" },
|
{ platform: "time_pattern" },
|
||||||
{ platform: "webhook" },
|
{ platform: "webhook" },
|
||||||
|
{ platform: "persistent_notification" },
|
||||||
{
|
{
|
||||||
platform: "zone",
|
platform: "zone",
|
||||||
entity_id: "person.person",
|
entity_id: "person.person",
|
||||||
|
@ -19,6 +19,7 @@ import { HaTemplateTrigger } from "../../../../src/panels/config/automation/trig
|
|||||||
import { HaTimeTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-time";
|
import { HaTimeTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-time";
|
||||||
import { HaTimePatternTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-time_pattern";
|
import { HaTimePatternTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-time_pattern";
|
||||||
import { HaWebhookTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-webhook";
|
import { HaWebhookTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-webhook";
|
||||||
|
import { HaPersistentNotificationTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-persistent_notification";
|
||||||
import { HaZoneTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-zone";
|
import { HaZoneTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-zone";
|
||||||
import { HaDeviceTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-device";
|
import { HaDeviceTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-device";
|
||||||
import { HaStateTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-state";
|
import { HaStateTrigger } from "../../../../src/panels/config/automation/trigger/types/ha-automation-trigger-state";
|
||||||
@ -72,6 +73,11 @@ const SCHEMAS: { name: string; triggers: Trigger[] }[] = [
|
|||||||
triggers: [{ platform: "webhook", ...HaWebhookTrigger.defaultConfig }],
|
triggers: [{ platform: "webhook", ...HaWebhookTrigger.defaultConfig }],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "Persistent Notification",
|
||||||
|
triggers: [{ platform: "persistent_notification", ...HaPersistentNotificationTrigger.defaultConfig }],
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: "Zone",
|
name: "Zone",
|
||||||
triggers: [{ platform: "zone", ...HaZoneTrigger.defaultConfig }],
|
triggers: [{ platform: "zone", ...HaZoneTrigger.defaultConfig }],
|
||||||
|
@ -127,6 +127,12 @@ export interface WebhookTrigger extends BaseTrigger {
|
|||||||
local_only?: boolean;
|
local_only?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PersistentNotificationTrigger extends BaseTrigger {
|
||||||
|
platform: "persistent_notification";
|
||||||
|
notification_id?: string;
|
||||||
|
update_type?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface ZoneTrigger extends BaseTrigger {
|
export interface ZoneTrigger extends BaseTrigger {
|
||||||
platform: "zone";
|
platform: "zone";
|
||||||
entity_id: string;
|
entity_id: string;
|
||||||
@ -174,6 +180,7 @@ export type Trigger =
|
|||||||
| SunTrigger
|
| SunTrigger
|
||||||
| TimePatternTrigger
|
| TimePatternTrigger
|
||||||
| WebhookTrigger
|
| WebhookTrigger
|
||||||
|
| PersistentNotificationTrigger
|
||||||
| ZoneTrigger
|
| ZoneTrigger
|
||||||
| TagTrigger
|
| TagTrigger
|
||||||
| TimeTrigger
|
| TimeTrigger
|
||||||
|
@ -600,6 +600,12 @@ export const describeTrigger = (
|
|||||||
return "When a Webhook payload has been received";
|
return "When a Webhook payload has been received";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Persistent Notification Trigger
|
||||||
|
if (trigger.platform === "persistent_notification") {
|
||||||
|
return "When a persistent_notification is updated";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Device Trigger
|
||||||
if (trigger.platform === "device") {
|
if (trigger.platform === "device") {
|
||||||
if (!trigger.device_id) {
|
if (!trigger.device_id) {
|
||||||
return "Device trigger";
|
return "Device trigger";
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
mdiHomeAssistant,
|
mdiHomeAssistant,
|
||||||
mdiMapMarker,
|
mdiMapMarker,
|
||||||
mdiMapMarkerRadius,
|
mdiMapMarkerRadius,
|
||||||
|
mdiMessageAlert,
|
||||||
mdiNfcVariant,
|
mdiNfcVariant,
|
||||||
mdiNumeric,
|
mdiNumeric,
|
||||||
mdiStateMachine,
|
mdiStateMachine,
|
||||||
@ -31,5 +32,6 @@ export const TRIGGER_TYPES = {
|
|||||||
time: mdiClockOutline,
|
time: mdiClockOutline,
|
||||||
time_pattern: mdiAvTimer,
|
time_pattern: mdiAvTimer,
|
||||||
webhook: mdiWebhook,
|
webhook: mdiWebhook,
|
||||||
|
persistent_notification: mdiMessageAlert,
|
||||||
zone: mdiMapMarkerRadius,
|
zone: mdiMapMarkerRadius,
|
||||||
};
|
};
|
||||||
|
@ -50,6 +50,7 @@ import "./types/ha-automation-trigger-geo_location";
|
|||||||
import "./types/ha-automation-trigger-homeassistant";
|
import "./types/ha-automation-trigger-homeassistant";
|
||||||
import "./types/ha-automation-trigger-mqtt";
|
import "./types/ha-automation-trigger-mqtt";
|
||||||
import "./types/ha-automation-trigger-numeric_state";
|
import "./types/ha-automation-trigger-numeric_state";
|
||||||
|
import "./types/ha-automation-trigger-persistent_notification";
|
||||||
import "./types/ha-automation-trigger-state";
|
import "./types/ha-automation-trigger-state";
|
||||||
import "./types/ha-automation-trigger-sun";
|
import "./types/ha-automation-trigger-sun";
|
||||||
import "./types/ha-automation-trigger-tag";
|
import "./types/ha-automation-trigger-tag";
|
||||||
|
@ -42,6 +42,7 @@ import "./types/ha-automation-trigger-geo_location";
|
|||||||
import "./types/ha-automation-trigger-homeassistant";
|
import "./types/ha-automation-trigger-homeassistant";
|
||||||
import "./types/ha-automation-trigger-mqtt";
|
import "./types/ha-automation-trigger-mqtt";
|
||||||
import "./types/ha-automation-trigger-numeric_state";
|
import "./types/ha-automation-trigger-numeric_state";
|
||||||
|
import "./types/ha-automation-trigger-persistent_notification";
|
||||||
import "./types/ha-automation-trigger-state";
|
import "./types/ha-automation-trigger-state";
|
||||||
import "./types/ha-automation-trigger-sun";
|
import "./types/ha-automation-trigger-sun";
|
||||||
import "./types/ha-automation-trigger-tag";
|
import "./types/ha-automation-trigger-tag";
|
||||||
|
@ -0,0 +1,107 @@
|
|||||||
|
import type { RequestSelectedDetail } from "@material/mwc-list/mwc-list-item";
|
||||||
|
import { css, html, LitElement } from "lit";
|
||||||
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
|
import "../../../../../components/ha-button-menu";
|
||||||
|
import "../../../../../components/ha-check-list-item";
|
||||||
|
import "../../../../../components/ha-icon-button";
|
||||||
|
import "../../../../../components/ha-textfield";
|
||||||
|
import { PersistentNotificationTrigger } from "../../../../../data/automation";
|
||||||
|
import { HomeAssistant } from "../../../../../types";
|
||||||
|
import { handleChangeEvent } from "../ha-automation-trigger-row";
|
||||||
|
|
||||||
|
const SUPPORTED_UPDATE_TYPES = ["added", "removed", "current", "updated"];
|
||||||
|
const DEFAULT_UPDATE_TYPES = ["added", "removed"];
|
||||||
|
const DEFAULT_NOTIFICATION_ID = "";
|
||||||
|
|
||||||
|
@customElement("ha-automation-trigger-persistent_notification")
|
||||||
|
export class HaPersistentNotificationTrigger extends LitElement {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@property() public trigger!: PersistentNotificationTrigger;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
|
public static get defaultConfig() {
|
||||||
|
return {
|
||||||
|
update_type: [...DEFAULT_UPDATE_TYPES],
|
||||||
|
notification_id: DEFAULT_NOTIFICATION_ID,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const {
|
||||||
|
update_type: updateTypes,
|
||||||
|
notification_id: notificationId,
|
||||||
|
} = this.trigger;
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<div class="form">
|
||||||
|
<ha-textfield
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.type.persistent_notification.notification_id"
|
||||||
|
)}
|
||||||
|
name="notification_id"
|
||||||
|
.value=${notificationId}
|
||||||
|
.disabled=${this.disabled}
|
||||||
|
@change=${this._valueChanged}
|
||||||
|
></ha-textfield>
|
||||||
|
<ha-formfield
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.type.persistent_notification.update_type"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
${SUPPORTED_UPDATE_TYPES.map(
|
||||||
|
(update_type) => html`
|
||||||
|
<ha-check-list-item
|
||||||
|
left
|
||||||
|
.value=${update_type}
|
||||||
|
@request-selected=${this._updateTypeChanged}
|
||||||
|
.selected=${updateTypes!.includes(update_type)}
|
||||||
|
>
|
||||||
|
${update_type}
|
||||||
|
</ha-check-list-item>
|
||||||
|
</ha-formfield>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _valueChanged(ev: CustomEvent): void {
|
||||||
|
handleChangeEvent(this, ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _updateTypeChanged(ev: CustomEvent<RequestSelectedDetail>): void {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const updateType = (ev.target as any).value;
|
||||||
|
const selected = ev.detail.selected;
|
||||||
|
|
||||||
|
if (selected === this.trigger.update_type?.includes(updateType)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateTypes = this.trigger.update_type ?? [];
|
||||||
|
const newUpdateTypes = [...updateTypes];
|
||||||
|
|
||||||
|
if (selected) {
|
||||||
|
newUpdateTypes.push(updateType);
|
||||||
|
} else {
|
||||||
|
newUpdateTypes.splice(newUpdateTypes.indexOf(updateType), 1);
|
||||||
|
}
|
||||||
|
const newTrigger = { ...this.trigger, update_type: newUpdateTypes };
|
||||||
|
fireEvent(this, "value-changed", { value: newTrigger });
|
||||||
|
}
|
||||||
|
|
||||||
|
static styles = css`
|
||||||
|
ha-textfield {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-automation-trigger-persistent_notification": HaPersistentNotificationTrigger;
|
||||||
|
}
|
||||||
|
}
|
@ -2325,6 +2325,11 @@
|
|||||||
"type_value": "Fixed number",
|
"type_value": "Fixed number",
|
||||||
"type_input": "Numeric value of another entity"
|
"type_input": "Numeric value of another entity"
|
||||||
},
|
},
|
||||||
|
"persistent_notification": {
|
||||||
|
"label": "Persistent notification",
|
||||||
|
"notification_id": "Notification Id",
|
||||||
|
"update_type": "Update type"
|
||||||
|
},
|
||||||
"sun": {
|
"sun": {
|
||||||
"label": "Sun",
|
"label": "Sun",
|
||||||
"event": "[%key:ui::panel::config::automation::editor::triggers::type::homeassistant::event%]",
|
"event": "[%key:ui::panel::config::automation::editor::triggers::type::homeassistant::event%]",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user