Move MqttServiceInfo to init.py (#60905)

Co-authored-by: epenet <epenet@users.noreply.github.com>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
epenet
2021-12-03 19:34:48 +01:00
committed by GitHub
parent 74d1c340d7
commit b65b25c1bb
8 changed files with 66 additions and 72 deletions

View File

@@ -1812,3 +1812,27 @@ async def test_publish_json_from_template(hass, mqtt_mock):
assert mqtt_mock.async_publish.called
assert mqtt_mock.async_publish.call_args[0][1] == test_str
async def test_service_info_compatibility(hass, caplog):
"""Test compatibility with old-style dict.
To be removed in 2022.6
"""
discovery_info = mqtt.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