From 33e5b1c770d25080d4bc735a6bdc36882828a7c7 Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Wed, 10 Jul 2024 10:07:49 +0000 Subject: [PATCH] Clear events --- .../event/developer-tools-event.ts | 101 ++++++++++-------- .../event/event-subscribe-card.ts | 79 +++++++++----- src/translations/en.json | 1 + 3 files changed, 108 insertions(+), 73 deletions(-) diff --git a/src/panels/developer-tools/event/developer-tools-event.ts b/src/panels/developer-tools/event/developer-tools-event.ts index cd29d3176d4d..a72b570e3a17 100644 --- a/src/panels/developer-tools/event/developer-tools-event.ts +++ b/src/panels/developer-tools/event/developer-tools-event.ts @@ -1,8 +1,9 @@ import { CSSResultGroup, LitElement, TemplateResult, css, html } from "lit"; import { customElement, property, state } from "lit/decorators"; -import "@material/mwc-button"; import "../../../components/ha-yaml-editor"; import "../../../components/ha-textfield"; +import "../../../components/ha-button"; +import "../../../components/ha-card"; import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box"; import { documentationUrl } from "../../../util/documentation-url"; import "./event-subscribe-card"; @@ -31,49 +32,61 @@ class HaPanelDevEvent extends LitElement { : "content layout horizontal"} >
-

- ${this.hass.localize( - "ui.panel.developer-tools.tabs.events.description" - )} - - ${this.hass.localize( - "ui.panel.developer-tools.tabs.events.documentation" - )} - -

-
- -

- ${this.hass.localize("ui.panel.developer-tools.tabs.events.data")} -

-
-
- -
- ${this.hass.localize( - "ui.panel.developer-tools.tabs.events.fire_event" - )} + +
+

+ ${this.hass.localize( + "ui.panel.developer-tools.tabs.events.description" + )} + + ${this.hass.localize( + "ui.panel.developer-tools.tabs.events.documentation" + )} + +

+
+ +

+ ${this.hass.localize( + "ui.panel.developer-tools.tabs.events.data" + )} +

+
+
+ +
+
+
+ ${this.hass.localize( + "ui.panel.developer-tools.tabs.events.fire_event" + )} +
+
+
diff --git a/src/panels/developer-tools/event/event-subscribe-card.ts b/src/panels/developer-tools/event/event-subscribe-card.ts index ada37484ce19..564af64c4b3e 100644 --- a/src/panels/developer-tools/event/event-subscribe-card.ts +++ b/src/panels/developer-tools/event/event-subscribe-card.ts @@ -1,4 +1,3 @@ -import "@material/mwc-button"; import { HassEvent } from "home-assistant-js-websocket"; import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { customElement, property, state } from "lit/decorators"; @@ -7,6 +6,7 @@ import { formatTime } from "../../../common/datetime/format_time"; import "../../../components/ha-card"; import "../../../components/ha-textfield"; import "../../../components/ha-yaml-editor"; +import "../../../components/ha-button"; import { HomeAssistant } from "../../../types"; @customElement("event-subscribe-card") @@ -40,33 +40,46 @@ class EventSubscribeCard extends LitElement { )} >
-
- - - ${this._subscribed - ? this.hass!.localize( - "ui.panel.developer-tools.tabs.events.stop_listening" - ) - : this.hass!.localize( - "ui.panel.developer-tools.tabs.events.start_listening" - )} - -
+ +
+
+ + ${this._subscribed + ? this.hass!.localize( + "ui.panel.developer-tools.tabs.events.stop_listening" + ) + : this.hass!.localize( + "ui.panel.developer-tools.tabs.events.start_listening" + )} + + + ${this.hass!.localize( + "ui.panel.developer-tools.tabs.events.clear_events" + )} + +
+ + +
${repeat( this._events, @@ -99,7 +112,7 @@ class EventSubscribeCard extends LitElement { this._eventType = ev.target.value; } - private async _handleSubmit(): Promise { + private async _startOrStopListening(): Promise { if (this._subscribed) { this._subscribed(); this._subscribed = undefined; @@ -121,6 +134,11 @@ class EventSubscribeCard extends LitElement { } } + private _clearEvents(): void { + this._events = []; + this._eventCount = 0; + } + static get styles(): CSSResultGroup { return css` ha-textfield { @@ -140,6 +158,9 @@ class EventSubscribeCard extends LitElement { pre { font-family: var(--code-font-family, monospace); } + ha-card { + margin-bottom: 5px; + } `; } } diff --git a/src/translations/en.json b/src/translations/en.json index 75271fe1a472..781342a860f8 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -6675,6 +6675,7 @@ "subscribe_to": "Event to subscribe to", "start_listening": "Start listening", "stop_listening": "Stop listening", + "clear_events": "Clear events", "alert_event_type": "Event type is a mandatory field", "notification_event_fired": "Event {type} successfully fired!" },