mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix esphome mqtt discovery by handling case where payload is a empty string (#129969)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
536e686892
commit
ee30520b57
@ -257,6 +257,9 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
self, discovery_info: MqttServiceInfo
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle MQTT discovery."""
|
||||
if not discovery_info.payload:
|
||||
return self.async_abort(reason="mqtt_missing_payload")
|
||||
|
||||
device_info = json_loads_object(discovery_info.payload)
|
||||
if "mac" not in device_info:
|
||||
return self.async_abort(reason="mqtt_missing_mac")
|
||||
|
@ -8,7 +8,8 @@
|
||||
"service_received": "Action received",
|
||||
"mqtt_missing_mac": "Missing MAC address in MQTT properties.",
|
||||
"mqtt_missing_api": "Missing API port in MQTT properties.",
|
||||
"mqtt_missing_ip": "Missing IP address in MQTT properties."
|
||||
"mqtt_missing_ip": "Missing IP address in MQTT properties.",
|
||||
"mqtt_missing_payload": "Missing MQTT Payload."
|
||||
},
|
||||
"error": {
|
||||
"resolve_error": "Can't resolve address of the ESP. If this error persists, please set a static IP address",
|
||||
|
@ -1400,6 +1400,14 @@ async def test_discovery_mqtt_no_mac(
|
||||
await mqtt_discovery_test_abort(hass, "{}", "mqtt_missing_mac")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_discovery_mqtt_empty_payload(
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test discovery aborted if MQTT payload is empty."""
|
||||
await mqtt_discovery_test_abort(hass, "", "mqtt_missing_payload")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_discovery_mqtt_no_api(
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
|
Loading…
x
Reference in New Issue
Block a user