Skip to content

Display MQTT debug info#5375

Merged
bramkragten merged 14 commits intohome-assistant:devfrom
emontnemery:mqtt_debug_info
Apr 22, 2020
Merged

Display MQTT debug info#5375
bramkragten merged 14 commits intohome-assistant:devfrom
emontnemery:mqtt_debug_info

Conversation

@emontnemery
Copy link
Copy Markdown
Collaborator

@emontnemery emontnemery commented Mar 31, 2020

Breaking change

Proposed change

Display MQTT debug info

Screenshots:
image

Showing recent messages, maybe timestamps should be added:
image

MQTT Discovery payload and subsribed topic payload can be displayed as JSON:
image

or as YAML:
image

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/panels/config/devices/device-detail/ha-device-card-mqtt.ts Outdated
Comment thread src/panels/config/mqtt/mqtt-device-debug-info-card.ts Outdated
@emontnemery emontnemery changed the title WIP - Display MQTT debug info Display MQTT debug info Apr 1, 2020
Comment thread src/data/mqtt.ts Outdated
Comment thread src/data/mqtt.ts Outdated
Comment thread src/data/mqtt.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/mqtt-payload.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/mqtt-payload.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/dialog-mqtt-device-debug-info.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/mqtt-messages.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/mqtt-messages.ts Outdated
Comment thread src/dialogs/mqtt-device-debug-info-dialog/mqtt-messages.ts Outdated
@property() private _showTopic = false;

protected firstUpdated(): void {
this._payloadsJson = new Array(this.messages.length);
Copy link
Copy Markdown
Member

@bramkragten bramkragten Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a WeakMap instead of an Array

? html`
<ul>
${this.messages.map(
(_, i) => html`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(_, i) => html`
(message) => html`

${this.messages.map(
(_, i) => html`
<li>
${this._renderSingleMessage(i)}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
${this._renderSingleMessage(i)}
${this._renderSingleMessage(message)}

`;
}

private _renderSingleMessage(i: number): TemplateResult {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private _renderSingleMessage(i: number): TemplateResult {
private _renderSingleMessage(message): TemplateResult {

}

private _renderSingleMessage(i: number): TemplateResult {
const topic = this.messages[i].topic;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const topic = this.messages[i].topic;
const topic = message.topic;

Topic: ${topic}
</li>
<li>
Payload: ${this._renderSinglePayload(i)}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Payload: ${this._renderSinglePayload(i)}
Payload: ${this._renderSinglePayload(message)}

</li>
</ul>
`
: this._renderSinglePayload(i);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: this._renderSinglePayload(i);
: this._renderSinglePayload(message);

: this._renderSinglePayload(i);
}

private _renderSinglePayload(i: number): TemplateResult {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private _renderSinglePayload(i: number): TemplateResult {
private _renderSinglePayload(message): TemplateResult {

Comment on lines +79 to +81
if (this._payloadsJson && this._payloadsJson[i] === undefined) {
this._payloadsJson[i] = this._tryParseJson(this.messages[i].payload);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this below the check for this.showDeserialized


private _renderSinglePayload(i: number): TemplateResult {
if (this._payloadsJson && this._payloadsJson[i] === undefined) {
this._payloadsJson[i] = this._tryParseJson(this.messages[i].payload);
Copy link
Copy Markdown
Member

@bramkragten bramkragten Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let json;
if (!this._payloadsJson.has(message)) {
	json = this._tryParseJson(message.payload);
	this._payloadsJson.set(message, json);
} else {
	json = this._payloadsJson.get(message);
}

@bramkragten bramkragten merged commit 9a00078 into home-assistant:dev Apr 22, 2020
@bramkragten bramkragten mentioned this pull request Apr 22, 2020
@lock lock Bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants