mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add missing abbreviations (#20741)
This commit is contained in:
parent
7455d950b1
commit
79d3f533a9
@ -11,7 +11,7 @@ import re
|
|||||||
|
|
||||||
from homeassistant.components import mqtt
|
from homeassistant.components import mqtt
|
||||||
from homeassistant.components.mqtt import ATTR_DISCOVERY_HASH, CONF_STATE_TOPIC
|
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.discovery import async_load_platform
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
@ -81,6 +81,7 @@ ABBREVIATIONS = {
|
|||||||
'cln_tpl': 'cleaning_template',
|
'cln_tpl': 'cleaning_template',
|
||||||
'cmd_t': 'command_topic',
|
'cmd_t': 'command_topic',
|
||||||
'curr_temp_t': 'current_temperature_topic',
|
'curr_temp_t': 'current_temperature_topic',
|
||||||
|
'dev': 'device',
|
||||||
'dev_cla': 'device_class',
|
'dev_cla': 'device_class',
|
||||||
'dock_t': 'docked_topic',
|
'dock_t': 'docked_topic',
|
||||||
'dock_tpl': 'docked_template',
|
'dock_tpl': 'docked_template',
|
||||||
@ -104,6 +105,7 @@ ABBREVIATIONS = {
|
|||||||
'ic': 'icon',
|
'ic': 'icon',
|
||||||
'init': 'initial',
|
'init': 'initial',
|
||||||
'json_attr': 'json_attributes',
|
'json_attr': 'json_attributes',
|
||||||
|
'json_attr_t': 'json_attributes_topic',
|
||||||
'max_temp': 'max_temp',
|
'max_temp': 'max_temp',
|
||||||
'min_temp': 'min_temp',
|
'min_temp': 'min_temp',
|
||||||
'mode_cmd_t': 'mode_command_topic',
|
'mode_cmd_t': 'mode_command_topic',
|
||||||
@ -172,6 +174,7 @@ ABBREVIATIONS = {
|
|||||||
'unit_of_meas': 'unit_of_measurement',
|
'unit_of_meas': 'unit_of_measurement',
|
||||||
'val_tpl': 'value_template',
|
'val_tpl': 'value_template',
|
||||||
'whit_val_cmd_t': 'white_value_command_topic',
|
'whit_val_cmd_t': 'white_value_command_topic',
|
||||||
|
'whit_val_scl': 'white_value_scale',
|
||||||
'whit_val_stat_t': 'white_value_state_topic',
|
'whit_val_stat_t': 'white_value_state_topic',
|
||||||
'whit_val_tpl': 'white_value_template',
|
'whit_val_tpl': 'white_value_template',
|
||||||
'xy_cmd_t': 'xy_command_topic',
|
'xy_cmd_t': 'xy_command_topic',
|
||||||
@ -179,6 +182,15 @@ ABBREVIATIONS = {
|
|||||||
'xy_val_tpl': 'xy_value_template',
|
'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):
|
def clear_discovery_hash(hass, discovery_hash):
|
||||||
"""Clear entry in ALREADY_DISCOVERED list."""
|
"""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)
|
key = ABBREVIATIONS.get(key, key)
|
||||||
payload[key] = payload.pop(abbreviated_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)
|
base = payload.pop(TOPIC_BASE, None)
|
||||||
if base:
|
if base:
|
||||||
for key, value in payload.items():
|
for key, value in payload.items():
|
||||||
|
@ -222,7 +222,15 @@ def test_discovery_expansion(hass, mqtt_mock, caplog):
|
|||||||
'{ "~": "some/base/topic",'
|
'{ "~": "some/base/topic",'
|
||||||
' "name": "DiscoveryExpansionTest1",'
|
' "name": "DiscoveryExpansionTest1",'
|
||||||
' "stat_t": "test_topic/~",'
|
' "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(
|
async_fire_mqtt_message(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user