@@ -1257,7 +1257,15 @@ async def test_debug_info_wildcard(hass, mqtt_mock):
12571257 assert len (debug_info_data ["entities" ][0 ]["subscriptions" ]) >= 1
12581258 assert {
12591259 "topic" : "sensor/#" ,
1260- "messages" : [{"topic" : "sensor/abc" , "payload" : "123" , "time" : start_dt }],
1260+ "messages" : [
1261+ {
1262+ "payload" : "123" ,
1263+ "qos" : 0 ,
1264+ "retain" : False ,
1265+ "time" : start_dt ,
1266+ "topic" : "sensor/abc" ,
1267+ }
1268+ ],
12611269 } in debug_info_data ["entities" ][0 ]["subscriptions" ]
12621270
12631271
@@ -1304,7 +1312,79 @@ async def test_debug_info_filter_same(hass, mqtt_mock):
13041312 assert {
13051313 "topic" : "sensor/#" ,
13061314 "messages" : [
1307- {"topic" : "sensor/abc" , "payload" : "123" , "time" : dt1 },
1308- {"topic" : "sensor/abc" , "payload" : "123" , "time" : dt2 },
1315+ {
1316+ "payload" : "123" ,
1317+ "qos" : 0 ,
1318+ "retain" : False ,
1319+ "time" : dt1 ,
1320+ "topic" : "sensor/abc" ,
1321+ },
1322+ {
1323+ "payload" : "123" ,
1324+ "qos" : 0 ,
1325+ "retain" : False ,
1326+ "time" : dt2 ,
1327+ "topic" : "sensor/abc" ,
1328+ },
13091329 ],
13101330 } == debug_info_data ["entities" ][0 ]["subscriptions" ][0 ]
1331+
1332+
1333+ async def test_debug_info_qos_retain (hass , mqtt_mock ):
1334+ """Test debug info."""
1335+ config = {
1336+ "device" : {"identifiers" : ["helloworld" ]},
1337+ "platform" : "mqtt" ,
1338+ "name" : "test" ,
1339+ "state_topic" : "sensor/#" ,
1340+ "unique_id" : "veryunique" ,
1341+ }
1342+
1343+ entry = MockConfigEntry (domain = mqtt .DOMAIN )
1344+ entry .add_to_hass (hass )
1345+ await async_start (hass , "homeassistant" , {}, entry )
1346+ registry = await hass .helpers .device_registry .async_get_registry ()
1347+
1348+ data = json .dumps (config )
1349+ async_fire_mqtt_message (hass , "homeassistant/sensor/bla/config" , data )
1350+ await hass .async_block_till_done ()
1351+
1352+ device = registry .async_get_device ({("mqtt" , "helloworld" )}, set ())
1353+ assert device is not None
1354+
1355+ debug_info_data = await debug_info .info_for_device (hass , device .id )
1356+ assert len (debug_info_data ["entities" ][0 ]["subscriptions" ]) >= 1
1357+ assert {"topic" : "sensor/#" , "messages" : []} in debug_info_data ["entities" ][0 ][
1358+ "subscriptions"
1359+ ]
1360+
1361+ start_dt = datetime (2019 , 1 , 1 , 0 , 0 , 0 )
1362+ with patch ("homeassistant.util.dt.utcnow" ) as dt_utcnow :
1363+ dt_utcnow .return_value = start_dt
1364+ async_fire_mqtt_message (hass , "sensor/abc" , "123" , qos = 0 , retain = False )
1365+ async_fire_mqtt_message (hass , "sensor/abc" , "123" , qos = 1 , retain = True )
1366+ async_fire_mqtt_message (hass , "sensor/abc" , "123" , qos = 2 , retain = False )
1367+
1368+ debug_info_data = await debug_info .info_for_device (hass , device .id )
1369+ assert len (debug_info_data ["entities" ][0 ]["subscriptions" ]) == 1
1370+ assert {
1371+ "payload" : "123" ,
1372+ "qos" : 0 ,
1373+ "retain" : False ,
1374+ "time" : start_dt ,
1375+ "topic" : "sensor/abc" ,
1376+ } in debug_info_data ["entities" ][0 ]["subscriptions" ][0 ]["messages" ]
1377+ assert {
1378+ "payload" : "123" ,
1379+ "qos" : 1 ,
1380+ "retain" : True ,
1381+ "time" : start_dt ,
1382+ "topic" : "sensor/abc" ,
1383+ } in debug_info_data ["entities" ][0 ]["subscriptions" ][0 ]["messages" ]
1384+ assert {
1385+ "payload" : "123" ,
1386+ "qos" : 2 ,
1387+ "retain" : False ,
1388+ "time" : start_dt ,
1389+ "topic" : "sensor/abc" ,
1390+ } in debug_info_data ["entities" ][0 ]["subscriptions" ][0 ]["messages" ]
0 commit comments