Skip to content

Commit

Permalink
Support multi-value DPT data in GroupMonitor (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio authored May 25, 2024
1 parent 403bc37 commit 7ef4264
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 36 deletions.
77 changes: 44 additions & 33 deletions src/dialogs/knx-telegram-info-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,34 @@ class TelegramInfoDialog extends LitElement {
</div>
<div class="section">
<h4>${this.knx.localize("group_monitor_source")}</h4>
<div>${this.telegram.source}</div>
<div>${this.telegram.source_name}</div>
<div class="row-inline">
<div>${this.telegram.source}</div>
<div>${this.telegram.source_name}</div>
</div>
</div>
<div class="section">
<h4>${this.knx.localize("group_monitor_destination")}</h4>
<div>${this.telegram.destination}</div>
<div>${this.telegram.destination_name}</div>
<div class="row-inline">
<div>${this.telegram.destination}</div>
<div>${this.telegram.destination_name}</div>
</div>
</div>
<div class="section">
<h4>${this.knx.localize("group_monitor_message")}</h4>
<div class="row">
<div>${this.telegram.telegramtype}</div>
<div>${TelegramDictFormatter.dptNameNumber(this.telegram)}</div>
<div><code>${TelegramDictFormatter.dptNameNumber(this.telegram)}</code></div>
</div>
${this.telegram.value != null
${this.telegram.payload != null
? html` <div class="row">
<div>${this.knx.localize("group_monitor_value")}</div>
<div>${TelegramDictFormatter.valueWithUnit(this.telegram)}</div>
<div>${this.knx.localize("group_monitor_payload")}</div>
<div><code>${TelegramDictFormatter.payload(this.telegram)}</code></div>
</div>`
: nothing}
${this.telegram.payload != null
${this.telegram.value != null
? html` <div class="row">
<div>${this.knx.localize("group_monitor_payload")}</div>
<div>${TelegramDictFormatter.payload(this.telegram)}</div>
<div>${this.knx.localize("group_monitor_value")}</div>
<pre><code>${TelegramDictFormatter.valueWithUnit(this.telegram)}</code></pre>
</div>`
: nothing}
</div>
Expand Down Expand Up @@ -114,11 +118,24 @@ class TelegramInfoDialog extends LitElement {
haStyleDialog,
css`
ha-dialog {
/* Set the top top of the dialog to a fixed position, so it doesnt jump when the content changes size */
--vertical-align-dialog: flex-start;
--dialog-surface-margin-top: 40px;
--vertical-align-dialog: center;
--dialog-z-index: 20;
}
@media all and (max-width: 450px), all and (max-height: 500px) {
/* When in fullscreen dialog should be attached to top */
ha-dialog {
--dialog-surface-margin-top: 0px;
}
}
@media all and (min-width: 600px) and (min-height: 501px) {
/* Set the dialog to a fixed size, so it doesnt jump when the content changes size */
ha-dialog {
--mdc-dialog-min-width: 580px;
--mdc-dialog-max-width: 580px;
--mdc-dialog-min-height: 70%;
--mdc-dialog-max-height: 70%;
}
}
.content {
display: flex;
Expand All @@ -144,28 +161,22 @@ class TelegramInfoDialog extends LitElement {
flex-wrap: wrap;
}
@media all and (max-width: 450px), all and (max-height: 500px) {
/* When in fullscreen dialog should be attached to top */
ha-dialog {
--dialog-surface-margin-top: 0px;
}
.row-inline {
display: flex;
flex-direction: row;
gap: 10px;
}
@media all and (min-width: 600px) and (min-height: 501px) {
ha-dialog {
--mdc-dialog-min-width: 580px;
--mdc-dialog-max-width: 580px;
--mdc-dialog-max-height: calc(100% - 72px);
}
.main-title {
cursor: default;
}
pre {
margin-top: 0;
margin-bottom: 0;
}
:host([large]) ha-dialog {
--mdc-dialog-min-width: 90vw;
--mdc-dialog-max-width: 90vw;
}
mwc-button {
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
`,
];
Expand Down
14 changes: 11 additions & 3 deletions src/utils/format.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { dump } from "js-yaml";
import { DPT, TelegramDict } from "../types/websocket";

export const TelegramDictFormatter = {
Expand All @@ -10,7 +11,14 @@ export const TelegramDictFormatter = {

valueWithUnit: (telegram: TelegramDict): string => {
if (telegram.value == null) return "";
return telegram.value.toString() + (telegram.unit ? " " + telegram.unit : "");
if (
typeof telegram.value === "number" ||
typeof telegram.value === "boolean" ||
typeof telegram.value === "string"
) {
return telegram.value.toString() + (telegram.unit ? " " + telegram.unit : "");
}
return dump(telegram.value);
},

timeWithMilliseconds: (telegram: TelegramDict): string => {
Expand Down Expand Up @@ -46,8 +54,8 @@ export const TelegramDictFormatter = {

dptNameNumber: (telegram: TelegramDict): string => {
const dptNumber = TelegramDictFormatter.dptNumber(telegram);
if (telegram.dpt_name == null) return dptNumber;
return dptNumber ? telegram.dpt_name + " - " + dptNumber : telegram.dpt_name;
if (telegram.dpt_name == null) return `DPT ${dptNumber}`;
return dptNumber ? `DPT ${dptNumber} ${telegram.dpt_name}` : telegram.dpt_name;
},
};

Expand Down

0 comments on commit 7ef4264

Please sign in to comment.