From 79d3f533a9e2263e52a0a5452cca44c5a3b69d50 Mon Sep 17 00:00:00 2001 From: emontnemery Date: Mon, 4 Feb 2019 19:54:40 +0100 Subject: [PATCH] Add missing abbreviations (#20741) --- homeassistant/components/mqtt/discovery.py | 21 ++++++++++++++++++++- tests/components/mqtt/test_discovery.py | 10 +++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index 9a2daf388cb..688912070bd 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -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(): diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index 47bd912fbc8..ffc385021d7 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -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(