Use MqttServiceInfo in tasmota (#60113)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/60241/head
parent
a5dc0e37b8
commit
4480e1255a
|
@ -29,15 +29,15 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
await self.async_set_unique_id(DOMAIN)
|
||||
|
||||
# Validate the message, abort if it fails
|
||||
if not discovery_info["topic"].endswith("/config"):
|
||||
if not discovery_info.topic.endswith("/config"):
|
||||
# Not a Tasmota discovery message
|
||||
return self.async_abort(reason="invalid_discovery_info")
|
||||
if not discovery_info["payload"]:
|
||||
if not discovery_info.payload:
|
||||
# Empty payload, the Tasmota is not configured for native discovery
|
||||
return self.async_abort(reason="invalid_discovery_info")
|
||||
|
||||
# "tasmota/discovery/#" is hardcoded in Tasmota's manifest
|
||||
assert discovery_info["subscribed_topic"] == "tasmota/discovery/#"
|
||||
assert discovery_info.subscribed_topic == "tasmota/discovery/#"
|
||||
self._prefix = "tasmota/discovery"
|
||||
|
||||
return await self.async_step_confirm()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Test config flow."""
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.mqtt import discovery as mqtt
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
@ -18,9 +19,9 @@ async def test_mqtt_abort_if_existing_entry(hass, mqtt_mock):
|
|||
|
||||
async def test_mqtt_abort_invalid_topic(hass, mqtt_mock):
|
||||
"""Check MQTT flow aborts if discovery topic is invalid."""
|
||||
discovery_info = {
|
||||
"topic": "tasmota/discovery/DC4F220848A2/bla",
|
||||
"payload": (
|
||||
discovery_info = mqtt.MqttServiceInfo(
|
||||
topic="tasmota/discovery/DC4F220848A2/bla",
|
||||
payload=(
|
||||
'{"ip":"192.168.0.136","dn":"Tasmota","fn":["Tasmota",null,null,null,null,'
|
||||
'null,null,null],"hn":"tasmota_0848A2","mac":"DC4F220848A2","md":"Sonoff Basic",'
|
||||
'"ty":0,"if":0,"ofln":"Offline","onln":"Online","state":["OFF","ON",'
|
||||
|
@ -30,34 +31,34 @@ async def test_mqtt_abort_invalid_topic(hass, mqtt_mock):
|
|||
'"so":{"4":0,"11":0,"13":0,"17":1,"20":0,"30":0,"68":0,"73":0,"82":0,"114":1,"117":0},'
|
||||
'"lk":1,"lt_st":0,"sho":[0,0,0,0],"ver":1}'
|
||||
),
|
||||
"qos": 0,
|
||||
"retain": False,
|
||||
"subscribed_topic": "tasmota/discovery/#",
|
||||
"timestamp": None,
|
||||
}
|
||||
qos=0,
|
||||
retain=False,
|
||||
subscribed_topic="tasmota/discovery/#",
|
||||
timestamp=None,
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tasmota", context={"source": config_entries.SOURCE_MQTT}, data=discovery_info
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "invalid_discovery_info"
|
||||
|
||||
discovery_info = {
|
||||
"topic": "tasmota/discovery/DC4F220848A2/config",
|
||||
"payload": "",
|
||||
"qos": 0,
|
||||
"retain": False,
|
||||
"subscribed_topic": "tasmota/discovery/#",
|
||||
"timestamp": None,
|
||||
}
|
||||
discovery_info = mqtt.MqttServiceInfo(
|
||||
topic="tasmota/discovery/DC4F220848A2/config",
|
||||
payload="",
|
||||
qos=0,
|
||||
retain=False,
|
||||
subscribed_topic="tasmota/discovery/#",
|
||||
timestamp=None,
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tasmota", context={"source": config_entries.SOURCE_MQTT}, data=discovery_info
|
||||
)
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "invalid_discovery_info"
|
||||
|
||||
discovery_info = {
|
||||
"topic": "tasmota/discovery/DC4F220848A2/config",
|
||||
"payload": (
|
||||
discovery_info = mqtt.MqttServiceInfo(
|
||||
topic="tasmota/discovery/DC4F220848A2/config",
|
||||
payload=(
|
||||
'{"ip":"192.168.0.136","dn":"Tasmota","fn":["Tasmota",null,null,null,null,'
|
||||
'null,null,null],"hn":"tasmota_0848A2","mac":"DC4F220848A2","md":"Sonoff Basic",'
|
||||
'"ty":0,"if":0,"ofln":"Offline","onln":"Online","state":["OFF","ON",'
|
||||
|
@ -67,11 +68,11 @@ async def test_mqtt_abort_invalid_topic(hass, mqtt_mock):
|
|||
'"so":{"4":0,"11":0,"13":0,"17":1,"20":0,"30":0,"68":0,"73":0,"82":0,"114":1,"117":0},'
|
||||
'"lk":1,"lt_st":0,"sho":[0,0,0,0],"ver":1}'
|
||||
),
|
||||
"qos": 0,
|
||||
"retain": False,
|
||||
"subscribed_topic": "tasmota/discovery/#",
|
||||
"timestamp": None,
|
||||
}
|
||||
qos=0,
|
||||
retain=False,
|
||||
subscribed_topic="tasmota/discovery/#",
|
||||
timestamp=None,
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tasmota", context={"source": config_entries.SOURCE_MQTT}, data=discovery_info
|
||||
)
|
||||
|
@ -80,9 +81,9 @@ async def test_mqtt_abort_invalid_topic(hass, mqtt_mock):
|
|||
|
||||
async def test_mqtt_setup(hass, mqtt_mock) -> None:
|
||||
"""Test we can finish a config flow through MQTT with custom prefix."""
|
||||
discovery_info = {
|
||||
"topic": "tasmota/discovery/DC4F220848A2/config",
|
||||
"payload": (
|
||||
discovery_info = mqtt.MqttServiceInfo(
|
||||
topic="tasmota/discovery/DC4F220848A2/config",
|
||||
payload=(
|
||||
'{"ip":"192.168.0.136","dn":"Tasmota","fn":["Tasmota",null,null,null,null,'
|
||||
'null,null,null],"hn":"tasmota_0848A2","mac":"DC4F220848A2","md":"Sonoff Basic",'
|
||||
'"ty":0,"if":0,"ofln":"Offline","onln":"Online","state":["OFF","ON",'
|
||||
|
@ -92,11 +93,11 @@ async def test_mqtt_setup(hass, mqtt_mock) -> None:
|
|||
'"so":{"4":0,"11":0,"13":0,"17":1,"20":0,"30":0,"68":0,"73":0,"82":0,"114":1,"117":0},'
|
||||
'"lk":1,"lt_st":0,"sho":[0,0,0,0],"ver":1}'
|
||||
),
|
||||
"qos": 0,
|
||||
"retain": False,
|
||||
"subscribed_topic": "tasmota/discovery/#",
|
||||
"timestamp": None,
|
||||
}
|
||||
qos=0,
|
||||
retain=False,
|
||||
subscribed_topic="tasmota/discovery/#",
|
||||
timestamp=None,
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"tasmota", context={"source": config_entries.SOURCE_MQTT}, data=discovery_info
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue