mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Add persistent_notification trigger (#16967)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
b46c74fe76
commit
9b35c06eef
@ -41,6 +41,7 @@ const triggers = [
|
||||
{ platform: "sun", event: "sunset" },
|
||||
{ platform: "time_pattern" },
|
||||
{ platform: "webhook" },
|
||||
{ platform: "persistent_notification" },
|
||||
{
|
||||
platform: "zone",
|
||||
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 { 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 { 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 { 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";
|
||||
@ -72,6 +73,16 @@ const SCHEMAS: { name: string; triggers: Trigger[] }[] = [
|
||||
triggers: [{ platform: "webhook", ...HaWebhookTrigger.defaultConfig }],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Persistent Notification",
|
||||
triggers: [
|
||||
{
|
||||
platform: "persistent_notification",
|
||||
...HaPersistentNotificationTrigger.defaultConfig,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name: "Zone",
|
||||
triggers: [{ platform: "zone", ...HaZoneTrigger.defaultConfig }],
|
||||
|
@ -127,6 +127,12 @@ export interface WebhookTrigger extends BaseTrigger {
|
||||
local_only?: boolean;
|
||||
}
|
||||
|
||||
export interface PersistentNotificationTrigger extends BaseTrigger {
|
||||
platform: "persistent_notification";
|
||||
notification_id?: string;
|
||||
update_type?: string[];
|
||||
}
|
||||
|
||||
export interface ZoneTrigger extends BaseTrigger {
|
||||
platform: "zone";
|
||||
entity_id: string;
|
||||
@ -174,6 +180,7 @@ export type Trigger =
|
||||
| SunTrigger
|
||||
| TimePatternTrigger
|
||||
| WebhookTrigger
|
||||
| PersistentNotificationTrigger
|
||||
| ZoneTrigger
|
||||
| TagTrigger
|
||||
| TimeTrigger
|
||||
|
@ -590,6 +590,12 @@ export const describeTrigger = (
|
||||
);
|
||||
}
|
||||
|
||||
// Persistent Notification Trigger
|
||||
if (trigger.platform === "persistent_notification") {
|
||||
return "When a persistent notification is updated";
|
||||
}
|
||||
|
||||
// Device Trigger
|
||||
if (trigger.platform === "device") {
|
||||
if (!trigger.device_id) {
|
||||
return "Device trigger";
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
mdiHomeAssistant,
|
||||
mdiMapMarker,
|
||||
mdiMapMarkerRadius,
|
||||
mdiMessageAlert,
|
||||
mdiNfcVariant,
|
||||
mdiNumeric,
|
||||
mdiStateMachine,
|
||||
@ -31,5 +32,6 @@ export const TRIGGER_TYPES = {
|
||||
time: mdiClockOutline,
|
||||
time_pattern: mdiAvTimer,
|
||||
webhook: mdiWebhook,
|
||||
persistent_notification: mdiMessageAlert,
|
||||
zone: mdiMapMarkerRadius,
|
||||
};
|
||||
|
@ -50,6 +50,7 @@ import "./types/ha-automation-trigger-geo_location";
|
||||
import "./types/ha-automation-trigger-homeassistant";
|
||||
import "./types/ha-automation-trigger-mqtt";
|
||||
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-sun";
|
||||
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-mqtt";
|
||||
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-sun";
|
||||
import "./types/ha-automation-trigger-tag";
|
||||
|
@ -0,0 +1,117 @@
|
||||
import memoizeOne from "memoize-one";
|
||||
|
||||
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 type { TriggerElement } from "../ha-automation-trigger-row";
|
||||
import type { LocalizeFunc } from "../../../../../common/translations/localize";
|
||||
import type { SchemaUnion } from "../../../../../components/ha-form/types";
|
||||
|
||||
const DEFAULT_UPDATE_TYPES = ["added", "removed"];
|
||||
const DEFAULT_NOTIFICATION_ID = "";
|
||||
|
||||
@customElement("ha-automation-trigger-persistent_notification")
|
||||
export class HaPersistentNotificationTrigger
|
||||
extends LitElement
|
||||
implements TriggerElement
|
||||
{
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property() public trigger!: PersistentNotificationTrigger;
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
private _schema = memoizeOne(
|
||||
(localize: LocalizeFunc) =>
|
||||
[
|
||||
{
|
||||
name: "notification_id",
|
||||
required: false,
|
||||
selector: { text: {} },
|
||||
},
|
||||
{
|
||||
name: "update_type",
|
||||
type: "multi_select",
|
||||
required: false,
|
||||
options: [
|
||||
[
|
||||
"added",
|
||||
localize(
|
||||
"ui.panel.config.automation.editor.triggers.type.persistent_notification.update_types.added"
|
||||
),
|
||||
],
|
||||
[
|
||||
"removed",
|
||||
localize(
|
||||
"ui.panel.config.automation.editor.triggers.type.persistent_notification.update_types.removed"
|
||||
),
|
||||
],
|
||||
[
|
||||
"current",
|
||||
localize(
|
||||
"ui.panel.config.automation.editor.triggers.type.persistent_notification.update_types.current"
|
||||
),
|
||||
],
|
||||
[
|
||||
"updated",
|
||||
localize(
|
||||
"ui.panel.config.automation.editor.triggers.type.persistent_notification.update_types.updated"
|
||||
),
|
||||
],
|
||||
],
|
||||
},
|
||||
] as const
|
||||
);
|
||||
|
||||
public static get defaultConfig() {
|
||||
return {
|
||||
update_type: [...DEFAULT_UPDATE_TYPES],
|
||||
notification_id: DEFAULT_NOTIFICATION_ID,
|
||||
};
|
||||
}
|
||||
|
||||
protected render() {
|
||||
const schema = this._schema(this.hass.localize);
|
||||
return html`
|
||||
<ha-form
|
||||
.schema=${schema}
|
||||
.data=${this.trigger}
|
||||
.hass=${this.hass}
|
||||
.disabled=${this.disabled}
|
||||
.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: SchemaUnion<ReturnType<typeof this._schema>>
|
||||
): string =>
|
||||
this.hass.localize(
|
||||
`ui.panel.config.automation.editor.triggers.type.persistent_notification.${schema.name}`
|
||||
);
|
||||
|
||||
static styles = css`
|
||||
ha-textfield {
|
||||
display: block;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"ha-automation-trigger-persistent_notification": HaPersistentNotificationTrigger;
|
||||
}
|
||||
}
|
@ -2341,6 +2341,17 @@
|
||||
"type_value": "Fixed number",
|
||||
"type_input": "Numeric value of another entity"
|
||||
},
|
||||
"persistent_notification": {
|
||||
"label": "Persistent notification",
|
||||
"notification_id": "Notification Id",
|
||||
"update_type": "Update type",
|
||||
"update_types": {
|
||||
"added": "added",
|
||||
"removed": "removed",
|
||||
"current": "current",
|
||||
"updated": "updated"
|
||||
}
|
||||
},
|
||||
"sun": {
|
||||
"label": "Sun",
|
||||
"event": "[%key:ui::panel::config::automation::editor::triggers::type::homeassistant::event%]",
|
||||
|
Loading…
x
Reference in New Issue
Block a user