mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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: "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,16 @@ 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
|
||||||
|
@ -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.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,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_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",
|
||||||
|
"update_types": {
|
||||||
|
"added": "added",
|
||||||
|
"removed": "removed",
|
||||||
|
"current": "current",
|
||||||
|
"updated": "updated"
|
||||||
|
}
|
||||||
|
},
|
||||||
"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