Add service configuration URL to MQTT (#57731)

This commit is contained in:
Franck Nijhof 2021-10-15 03:27:40 +02:00 committed by GitHub
parent e34fb4cfb9
commit eed9f67402
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 0 deletions

View file

@ -22,6 +22,7 @@ ABBREVIATIONS = {
"clr_temp_cmd_tpl": "color_temp_command_template",
"bat_lev_t": "battery_level_topic",
"bat_lev_tpl": "battery_level_template",
"cu": "configuration_url",
"chrg_t": "charging_topic",
"chrg_tpl": "charging_template",
"clrm": "color_mode",

View file

@ -68,6 +68,7 @@ CONF_SW_VERSION = "sw_version"
CONF_VIA_DEVICE = "via_device"
CONF_DEPRECATED_VIA_HUB = "via_hub"
CONF_SUGGESTED_AREA = "suggested_area"
CONF_CONFIGURATION_URL = "configuration_url"
MQTT_ATTRIBUTES_BLOCKED = {
"assumed_state",
@ -154,6 +155,7 @@ MQTT_ENTITY_DEVICE_INFO_SCHEMA = vol.All(
vol.Optional(CONF_SW_VERSION): cv.string,
vol.Optional(CONF_VIA_DEVICE): cv.string,
vol.Optional(CONF_SUGGESTED_AREA): cv.string,
vol.Optional(CONF_CONFIGURATION_URL): cv.url,
}
),
validate_device_has_at_least_one_identifier,
@ -531,6 +533,9 @@ def device_info_from_config(config):
if CONF_SUGGESTED_AREA in config:
info["suggested_area"] = config[CONF_SUGGESTED_AREA]
if CONF_CONFIGURATION_URL in config:
info["configuration_url"] = config[CONF_CONFIGURATION_URL]
return info

View file

@ -22,6 +22,7 @@ DEFAULT_CONFIG_DEVICE_INFO_ID = {
"model": "Glass",
"sw_version": "0.1-beta",
"suggested_area": "default_area",
"configuration_url": "http://example.com",
}
DEFAULT_CONFIG_DEVICE_INFO_MAC = {
@ -31,6 +32,7 @@ DEFAULT_CONFIG_DEVICE_INFO_MAC = {
"model": "Glass",
"sw_version": "0.1-beta",
"suggested_area": "default_area",
"configuration_url": "http://example.com",
}
@ -771,6 +773,7 @@ async def help_test_entity_device_info_with_identifier(hass, mqtt_mock, domain,
assert device.model == "Glass"
assert device.sw_version == "0.1-beta"
assert device.suggested_area == "default_area"
assert device.configuration_url == "http://example.com"
async def help_test_entity_device_info_with_connection(hass, mqtt_mock, domain, config):
@ -799,6 +802,7 @@ async def help_test_entity_device_info_with_connection(hass, mqtt_mock, domain,
assert device.model == "Glass"
assert device.sw_version == "0.1-beta"
assert device.suggested_area == "default_area"
assert device.configuration_url == "http://example.com"
async def help_test_entity_device_info_remove(hass, mqtt_mock, domain, config):

View file

@ -301,6 +301,7 @@ def test_entity_device_info_schema():
"name": "Beer",
"model": "Glass",
"sw_version": "0.1-beta",
"configuration_url": "http://example.com",
}
)
# full device info with via_device
@ -316,6 +317,7 @@ def test_entity_device_info_schema():
"model": "Glass",
"sw_version": "0.1-beta",
"via_device": "test-hub",
"configuration_url": "http://example.com",
}
)
# no identifiers
@ -334,6 +336,18 @@ def test_entity_device_info_schema():
{"identifiers": [], "connections": [], "name": "Beer"}
)
# not an valid URL
with pytest.raises(vol.Invalid):
MQTT_ENTITY_DEVICE_INFO_SCHEMA(
{
"manufacturer": "Whatever",
"name": "Beer",
"model": "Glass",
"sw_version": "0.1-beta",
"configuration_url": "fake://link",
}
)
async def test_receiving_non_utf8_message_gets_logged(
hass, mqtt_mock, calls, record_calls, caplog