Process abbreviated availability options in mqtt discovery payload (#79712)

Expand availability in mqtt discovery payload
This commit is contained in:
Bert Melis 2022-10-08 15:36:49 +02:00 committed by GitHub
parent c6df823b35
commit 6546bba233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -139,6 +139,14 @@ async def async_start( # noqa: C901
key = DEVICE_ABBREVIATIONS.get(key, key) key = DEVICE_ABBREVIATIONS.get(key, key)
device[key] = device.pop(abbreviated_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: if TOPIC_BASE in payload:
base = payload.pop(TOPIC_BASE) base = payload.pop(TOPIC_BASE)
for key, value in payload.items(): for key, value in payload.items():

View File

@ -945,9 +945,9 @@ async def test_discovery_expansion(hass, mqtt_mock_entry_no_yaml_config, caplog)
' "payload_not_available": "not_available"' ' "payload_not_available": "not_available"'
" }," " },"
" {" " {"
' "topic":"avail_item2/~",' ' "t":"avail_item2/~",'
' "payload_available": "available",' ' "pl_avail": "available",'
' "payload_not_available": "not_available"' ' "pl_not_avail": "not_available"'
" }" " }"
" ]," " ],"
' "dev":{' ' "dev":{'
@ -999,9 +999,9 @@ async def test_discovery_expansion_2(hass, mqtt_mock_entry_no_yaml_config, caplo
' "stat_t": "test_topic/~",' ' "stat_t": "test_topic/~",'
' "cmd_t": "~/test_topic",' ' "cmd_t": "~/test_topic",'
' "availability": {' ' "availability": {'
' "topic":"~/avail_item1",' ' "t":"~/avail_item1",'
' "payload_available": "available",' ' "pl_avail": "available",'
' "payload_not_available": "not_available"' ' "pl_not_avail": "not_available"'
" }," " },"
' "dev":{' ' "dev":{'
' "ids":["5706DF"],' ' "ids":["5706DF"],'