mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Add compatibility tests for MqttServiceInfo (#60754)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
38153b015f
commit
6caaa5f6bd
@ -11,7 +11,11 @@ from homeassistant.components.mqtt.abbreviations import (
|
|||||||
ABBREVIATIONS,
|
ABBREVIATIONS,
|
||||||
DEVICE_ABBREVIATIONS,
|
DEVICE_ABBREVIATIONS,
|
||||||
)
|
)
|
||||||
from homeassistant.components.mqtt.discovery import ALREADY_DISCOVERED, async_start
|
from homeassistant.components.mqtt.discovery import (
|
||||||
|
ALREADY_DISCOVERED,
|
||||||
|
MqttServiceInfo,
|
||||||
|
async_start,
|
||||||
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_STATE_CHANGED,
|
EVENT_STATE_CHANGED,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
@ -905,3 +909,27 @@ async def test_mqtt_discovery_unsubscribe_once(hass, mqtt_client_mock, mqtt_mock
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
mqtt_client_mock.unsubscribe.assert_called_once_with("comp/discovery/#")
|
mqtt_client_mock.unsubscribe.assert_called_once_with("comp/discovery/#")
|
||||||
|
|
||||||
|
|
||||||
|
async def test_service_info_compatibility(hass, caplog):
|
||||||
|
"""Test compatibility with old-style dict.
|
||||||
|
|
||||||
|
To be removed in 2022.6
|
||||||
|
"""
|
||||||
|
discovery_info = MqttServiceInfo(
|
||||||
|
topic="tasmota/discovery/DC4F220848A2/config",
|
||||||
|
payload="",
|
||||||
|
qos=0,
|
||||||
|
retain=False,
|
||||||
|
subscribed_topic="tasmota/discovery/#",
|
||||||
|
timestamp=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Ensure first call get logged
|
||||||
|
assert discovery_info["topic"] == "tasmota/discovery/DC4F220848A2/config"
|
||||||
|
assert "Detected code that accessed discovery_info['topic']" in caplog.text
|
||||||
|
|
||||||
|
# Ensure second call doesn't get logged
|
||||||
|
caplog.clear()
|
||||||
|
assert discovery_info["topic"] == "tasmota/discovery/DC4F220848A2/config"
|
||||||
|
assert "Detected code that accessed discovery_info['topic']" not in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user