Add missing abbreviations (#20741)

This commit is contained in:
emontnemery 2019-02-04 19:54:40 +01:00 committed by Paulus Schoutsen
parent 7455d950b1
commit 79d3f533a9
2 changed files with 29 additions and 2 deletions

View File

@ -11,7 +11,7 @@ import re
from homeassistant.components import mqtt
from homeassistant.components.mqtt import ATTR_DISCOVERY_HASH, CONF_STATE_TOPIC
from homeassistant.const import CONF_PLATFORM
from homeassistant.const import CONF_DEVICE, CONF_PLATFORM
from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.typing import HomeAssistantType
@ -81,6 +81,7 @@ ABBREVIATIONS = {
'cln_tpl': 'cleaning_template',
'cmd_t': 'command_topic',
'curr_temp_t': 'current_temperature_topic',
'dev': 'device',
'dev_cla': 'device_class',
'dock_t': 'docked_topic',
'dock_tpl': 'docked_template',
@ -104,6 +105,7 @@ ABBREVIATIONS = {
'ic': 'icon',
'init': 'initial',
'json_attr': 'json_attributes',
'json_attr_t': 'json_attributes_topic',
'max_temp': 'max_temp',
'min_temp': 'min_temp',
'mode_cmd_t': 'mode_command_topic',
@ -172,6 +174,7 @@ ABBREVIATIONS = {
'unit_of_meas': 'unit_of_measurement',
'val_tpl': 'value_template',
'whit_val_cmd_t': 'white_value_command_topic',
'whit_val_scl': 'white_value_scale',
'whit_val_stat_t': 'white_value_state_topic',
'whit_val_tpl': 'white_value_template',
'xy_cmd_t': 'xy_command_topic',
@ -179,6 +182,15 @@ ABBREVIATIONS = {
'xy_val_tpl': 'xy_value_template',
}
DEVICE_ABBREVIATIONS = {
'cns': 'connections',
'ids': 'identifiers',
'name': 'name',
'mf': 'manufacturer',
'mdl': 'model',
'sw': 'sw_version',
}
def clear_discovery_hash(hass, discovery_hash):
"""Clear entry in ALREADY_DISCOVERED list."""
@ -216,6 +228,13 @@ async def async_start(hass: HomeAssistantType, discovery_topic, hass_config,
key = ABBREVIATIONS.get(key, key)
payload[key] = payload.pop(abbreviated_key)
if CONF_DEVICE in payload:
device = payload[CONF_DEVICE]
for key in list(device.keys()):
abbreviated_key = key
key = DEVICE_ABBREVIATIONS.get(key, key)
device[key] = device.pop(abbreviated_key)
base = payload.pop(TOPIC_BASE, None)
if base:
for key, value in payload.items():

View File

@ -222,7 +222,15 @@ def test_discovery_expansion(hass, mqtt_mock, caplog):
'{ "~": "some/base/topic",'
' "name": "DiscoveryExpansionTest1",'
' "stat_t": "test_topic/~",'
' "cmd_t": "~/test_topic" }'
' "cmd_t": "~/test_topic",'
' "dev":{'
' "ids":["5706DF"],'
' "name":"DiscoveryExpansionTest1 Device",'
' "mdl":"Generic",'
' "sw":"1.2.3.4",'
' "mf":"Noone"'
' }'
'}'
)
async_fire_mqtt_message(