Stringify MQTT payload in mqtt/debug/info WS response (#65429)
This commit is contained in:
parent
5a34feb7de
commit
fda0fbd115
3 changed files with 65 additions and 3 deletions
|
@ -139,7 +139,7 @@ async def info_for_device(hass, device_id):
|
|||
"topic": topic,
|
||||
"messages": [
|
||||
{
|
||||
"payload": msg.payload,
|
||||
"payload": str(msg.payload),
|
||||
"qos": msg.qos,
|
||||
"retain": msg.retain,
|
||||
"time": msg.timestamp,
|
||||
|
|
|
@ -1222,7 +1222,7 @@ async def help_test_entity_debug_info_message(
|
|||
"topic": topic,
|
||||
"messages": [
|
||||
{
|
||||
"payload": payload,
|
||||
"payload": str(payload),
|
||||
"qos": 0,
|
||||
"retain": False,
|
||||
"time": start_dt,
|
||||
|
|
|
@ -3,7 +3,7 @@ import asyncio
|
|||
from datetime import datetime, timedelta
|
||||
import json
|
||||
import ssl
|
||||
from unittest.mock import AsyncMock, MagicMock, call, mock_open, patch
|
||||
from unittest.mock import ANY, AsyncMock, MagicMock, call, mock_open, patch
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
@ -1540,6 +1540,68 @@ async def test_mqtt_ws_get_device_debug_info(
|
|||
assert response["result"] == expected_result
|
||||
|
||||
|
||||
async def test_mqtt_ws_get_device_debug_info_binary(
|
||||
hass, device_reg, hass_ws_client, mqtt_mock
|
||||
):
|
||||
"""Test MQTT websocket device debug info."""
|
||||
config = {
|
||||
"device": {"identifiers": ["0AFFD2"]},
|
||||
"platform": "mqtt",
|
||||
"topic": "foobar/image",
|
||||
"unique_id": "unique",
|
||||
}
|
||||
data = json.dumps(config)
|
||||
|
||||
async_fire_mqtt_message(hass, "homeassistant/camera/bla/config", data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Verify device entry is created
|
||||
device_entry = device_reg.async_get_device({("mqtt", "0AFFD2")})
|
||||
assert device_entry is not None
|
||||
|
||||
small_png = (
|
||||
b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x04\x00\x00\x00\x04\x08\x06"
|
||||
b"\x00\x00\x00\xa9\xf1\x9e~\x00\x00\x00\x13IDATx\xdac\xfc\xcf\xc0P\xcf\x80\x04"
|
||||
b"\x18I\x17\x00\x00\xf2\xae\x05\xfdR\x01\xc2\xde\x00\x00\x00\x00IEND\xaeB`\x82"
|
||||
)
|
||||
async_fire_mqtt_message(hass, "foobar/image", small_png)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
client = await hass_ws_client(hass)
|
||||
await client.send_json(
|
||||
{"id": 5, "type": "mqtt/device/debug_info", "device_id": device_entry.id}
|
||||
)
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
expected_result = {
|
||||
"entities": [
|
||||
{
|
||||
"entity_id": "camera.mqtt_camera",
|
||||
"subscriptions": [
|
||||
{
|
||||
"topic": "foobar/image",
|
||||
"messages": [
|
||||
{
|
||||
"payload": str(small_png),
|
||||
"qos": 0,
|
||||
"retain": False,
|
||||
"time": ANY,
|
||||
"topic": "foobar/image",
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
"discovery_data": {
|
||||
"payload": config,
|
||||
"topic": "homeassistant/camera/bla/config",
|
||||
},
|
||||
}
|
||||
],
|
||||
"triggers": [],
|
||||
}
|
||||
assert response["result"] == expected_result
|
||||
|
||||
|
||||
async def test_debug_info_multiple_devices(hass, mqtt_mock):
|
||||
"""Test we get correct debug_info when multiple devices are present."""
|
||||
devices = [
|
||||
|
|
Loading…
Add table
Reference in a new issue