mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +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
|
self, discovery_info: MqttServiceInfo
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle MQTT discovery."""
|
"""Handle MQTT discovery."""
|
||||||
|
if not discovery_info.payload:
|
||||||
|
return self.async_abort(reason="mqtt_missing_payload")
|
||||||
|
|
||||||
device_info = json_loads_object(discovery_info.payload)
|
device_info = json_loads_object(discovery_info.payload)
|
||||||
if "mac" not in device_info:
|
if "mac" not in device_info:
|
||||||
return self.async_abort(reason="mqtt_missing_mac")
|
return self.async_abort(reason="mqtt_missing_mac")
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
"service_received": "Action received",
|
"service_received": "Action received",
|
||||||
"mqtt_missing_mac": "Missing MAC address in MQTT properties.",
|
"mqtt_missing_mac": "Missing MAC address in MQTT properties.",
|
||||||
"mqtt_missing_api": "Missing API port 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": {
|
"error": {
|
||||||
"resolve_error": "Can't resolve address of the ESP. If this error persists, please set a static IP address",
|
"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")
|
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")
|
@pytest.mark.usefixtures("mock_zeroconf")
|
||||||
async def test_discovery_mqtt_no_api(
|
async def test_discovery_mqtt_no_api(
|
||||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user