Skip to content

Commit a74550b

Browse files
authored
Add Pause button to GroupMonitor (#150)
1 parent 82a364e commit a74550b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/views/group_monitor.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { html, CSSResultGroup, LitElement, TemplateResult, nothing } from "lit";
22
import { customElement, property, state } from "lit/decorators";
33

4+
import { mdiPause, mdiAutorenew } from "@mdi/js";
45
import memoize from "memoize-one";
56

67
import "@ha/layouts/hass-loading-screen";
@@ -13,6 +14,7 @@ import type {
1314
DataTableRowData,
1415
RowClickedEvent,
1516
} from "@ha/components/data-table/ha-data-table";
17+
import "@ha/components/ha-icon-button";
1618
import { haStyle } from "@ha/resources/styles";
1719
import { HomeAssistant, Route } from "@ha/types";
1820
import type { PageNavigation } from "@ha/layouts/hass-tabs-subpage";
@@ -47,6 +49,8 @@ export class KNXGroupMonitor extends LitElement {
4749

4850
@state() private _dialogIndex: number | null = null;
4951

52+
@state() private _pause: boolean = false;
53+
5054
public disconnectedCallback() {
5155
super.disconnectedCallback();
5256
if (this.subscribed) {
@@ -99,6 +103,7 @@ export class KNXGroupMonitor extends LitElement {
99103
sortable: true,
100104
title: this.knx.localize("group_monitor_source"),
101105
flex: 2,
106+
minWidth: "0", // prevent horizontal scroll on very narrow screens
102107
template: (row) =>
103108
projectLoaded
104109
? html`<div>${row.sourceAddress}</div>
@@ -117,6 +122,7 @@ export class KNXGroupMonitor extends LitElement {
117122
filterable: true,
118123
title: this.knx.localize("group_monitor_destination"),
119124
flex: 2,
125+
minWidth: "0", // prevent horizontal scroll on very narrow screens
120126
template: (row) =>
121127
projectLoaded
122128
? html`<div>${row.destinationAddress}</div>
@@ -155,12 +161,14 @@ export class KNXGroupMonitor extends LitElement {
155161
title: this.knx.localize("group_monitor_value"),
156162
filterable: true,
157163
flex: 1,
164+
minWidth: "0", // prevent horizontal scroll on very narrow screens
158165
},
159166
}),
160167
);
161168

162169
protected telegram_callback(telegram: TelegramDict): void {
163170
this.telegrams.push(telegram);
171+
if (this._pause) return;
164172
const rows = [...this.rows];
165173
rows.push(this._telegramToRow(telegram, rows.length));
166174
this.rows = rows;
@@ -208,11 +216,31 @@ export class KNXGroupMonitor extends LitElement {
208216
id="index"
209217
.clickable=${true}
210218
@row-click=${this._rowClicked}
211-
></hass-tabs-subpage-data-table>
219+
>
220+
<ha-icon-button
221+
slot="toolbar-icon"
222+
.label=${this._pause ? "Resume" : "Pause"}
223+
.path=${this._pause ? mdiAutorenew : mdiPause}
224+
@click=${this._togglePause}
225+
></ha-icon-button>
226+
</hass-tabs-subpage-data-table>
212227
${this._dialogIndex !== null ? this._renderTelegramInfoDialog(this._dialogIndex) : nothing}
213228
`;
214229
}
215230

231+
private _togglePause(): void {
232+
this._pause = !this._pause;
233+
if (!this._pause) {
234+
const currentRowCount = this.rows.length;
235+
const pauseTelegrams = this.telegrams.slice(currentRowCount);
236+
this.rows = this.rows.concat(
237+
pauseTelegrams.map((telegram, index) =>
238+
this._telegramToRow(telegram, currentRowCount + index),
239+
),
240+
);
241+
}
242+
}
243+
216244
private _renderTelegramInfoDialog(index: number): TemplateResult {
217245
return html` <knx-telegram-info-dialog
218246
.hass=${this.hass}

0 commit comments

Comments
 (0)