From 6546bba2330e2b46243491a7eaaa144ebfd5841e Mon Sep 17 00:00:00 2001 From: Bert Melis Date: Sat, 8 Oct 2022 15:36:49 +0200 Subject: [PATCH] Process abbreviated availability options in mqtt discovery payload (#79712) Expand availability in mqtt discovery payload --- homeassistant/components/mqtt/discovery.py | 8 ++++++++ tests/components/mqtt/test_discovery.py | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index 23453e146ed..92ad50b7b4a 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -139,6 +139,14 @@ async def async_start( # noqa: C901 key = DEVICE_ABBREVIATIONS.get(key, key) device[key] = device.pop(abbreviated_key) + if CONF_AVAILABILITY in payload: + for availability_conf in cv.ensure_list(payload[CONF_AVAILABILITY]): + if isinstance(availability_conf, dict): + for key in list(availability_conf): + abbreviated_key = key + key = ABBREVIATIONS.get(key, key) + availability_conf[key] = availability_conf.pop(abbreviated_key) + if TOPIC_BASE in payload: base = payload.pop(TOPIC_BASE) for key, value in payload.items(): diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index 50c0a50bd40..77d7093830e 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -945,9 +945,9 @@ async def test_discovery_expansion(hass, mqtt_mock_entry_no_yaml_config, caplog) ' "payload_not_available": "not_available"' " }," " {" - ' "topic":"avail_item2/~",' - ' "payload_available": "available",' - ' "payload_not_available": "not_available"' + ' "t":"avail_item2/~",' + ' "pl_avail": "available",' + ' "pl_not_avail": "not_available"' " }" " ]," ' "dev":{' @@ -999,9 +999,9 @@ async def test_discovery_expansion_2(hass, mqtt_mock_entry_no_yaml_config, caplo ' "stat_t": "test_topic/~",' ' "cmd_t": "~/test_topic",' ' "availability": {' - ' "topic":"~/avail_item1",' - ' "payload_available": "available",' - ' "payload_not_available": "not_available"' + ' "t":"~/avail_item1",' + ' "pl_avail": "available",' + ' "pl_not_avail": "not_available"' " }," ' "dev":{' ' "ids":["5706DF"],'