Remove duplicated config from MQTT tests (#32689)
This commit is contained in:
1 parent
5216dc0ae1
commit
f7ddbc7e1e
14 files changed
+599
-1131
No files matched your search
@@ -26,7 +26,6 @@ If your light doesn't support white value feature, omit `white_value_template`.
|
||||
|
||||
If your light doesn't support RGB feature, omit `(red|green|blue)_template`.
|
||||
"""
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components import light, mqtt
|
||||
@@ -61,6 +60,37 @@ from tests.common import (
|
||||
mock_coro,
|
||||
)
|
||||
|
||||
DEFAULT_CONFIG_ATTR = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"schema": "template",
|
||||
"name": "test",
|
||||
"command_topic": "test-topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"json_attributes_topic": "attr-topic",
|
||||
}
|
||||
}
|
||||
|
||||
DEFAULT_CONFIG_DEVICE_INFO = {
|
||||
"platform": "mqtt",
|
||||
"name": "Test 1",
|
||||
"schema": "template",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "test-command-topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"device": {
|
||||
"identifiers": ["helloworld"],
|
||||
"connections": [["mac", "02:5b:26:a8:dc:12"]],
|
||||
"manufacturer": "Whatever",
|
||||
"name": "Beer",
|
||||
"model": "Glass",
|
||||
"sw_version": "0.1-beta",
|
||||
},
|
||||
"unique_id": "veryunique",
|
||||
}
|
||||
|
||||
|
||||
async def test_setup_fails(hass, mqtt_mock):
|
||||
"""Test that setup fails with missing required configuration items."""
|
||||
@@ -522,62 +552,29 @@ async def test_custom_availability_payload(hass, mqtt_mock):
|
||||
|
||||
async def test_setting_attribute_via_mqtt_json_message(hass, mqtt_mock):
|
||||
"""Test the setting of attribute via MQTT with JSON payload."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"schema": "template",
|
||||
"name": "test",
|
||||
"command_topic": "test-topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"json_attributes_topic": "attr-topic",
|
||||
}
|
||||
}
|
||||
await help_test_setting_attribute_via_mqtt_json_message(
|
||||
hass, mqtt_mock, light.DOMAIN, config
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG_ATTR
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_not_dict(hass, mqtt_mock, caplog):
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"schema": "template",
|
||||
"name": "test",
|
||||
"command_topic": "test-topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"json_attributes_topic": "attr-topic",
|
||||
}
|
||||
}
|
||||
await help_test_update_with_json_attrs_not_dict(
|
||||
hass, mqtt_mock, caplog, light.DOMAIN, config
|
||||
hass, mqtt_mock, caplog, light.DOMAIN, DEFAULT_CONFIG_ATTR
|
||||
)
|
||||
|
||||
|
||||
async def test_update_with_json_attrs_bad_JSON(hass, mqtt_mock, caplog):
|
||||
"""Test attributes get extracted from a JSON result."""
|
||||
config = {
|
||||
light.DOMAIN: {
|
||||
"platform": "mqtt",
|
||||
"schema": "template",
|
||||
"name": "test",
|
||||
"command_topic": "test-topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"json_attributes_topic": "attr-topic",
|
||||
}
|
||||
}
|
||||
await help_test_update_with_json_attrs_bad_JSON(
|
||||
hass, mqtt_mock, caplog, light.DOMAIN, config
|
||||
hass, mqtt_mock, caplog, light.DOMAIN, DEFAULT_CONFIG_ATTR
|
||||
)
|
||||
|
||||
|
||||
async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
"""Test update of discovered MQTTAttributes."""
|
||||
data1 = (
|
||||
'{ "name": "Beer",'
|
||||
'{ "name": "test",'
|
||||
' "schema": "template",'
|
||||
' "command_topic": "test_topic",'
|
||||
' "command_on_template": "on",'
|
||||
@@ -585,7 +582,7 @@ async def test_discovery_update_attr(hass, mqtt_mock, caplog):
|
||||
' "json_attributes_topic": "attr-topic1" }'
|
||||
)
|
||||
data2 = (
|
||||
'{ "name": "Beer",'
|
||||
'{ "name": "test",'
|
||||
' "schema": "template",'
|
||||
' "command_topic": "test_topic",'
|
||||
' "command_on_template": "on",'
|
||||
@@ -627,7 +624,7 @@ async def test_unique_id(hass):
|
||||
async def test_discovery_removal(hass, mqtt_mock, caplog):
|
||||
"""Test removal of discovered mqtt_json lights."""
|
||||
data = (
|
||||
'{ "name": "Beer",'
|
||||
'{ "name": "test",'
|
||||
' "schema": "template",'
|
||||
' "command_topic": "test_topic",'
|
||||
' "command_on_template": "on",'
|
||||
@@ -695,52 +692,16 @@ async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||
|
||||
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
|
||||
"""Test MQTT light device registry integration."""
|
||||
data = json.dumps(
|
||||
{
|
||||
"platform": "mqtt",
|
||||
"name": "Test 1",
|
||||
"schema": "template",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "test-topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"device": {
|
||||
"identifiers": ["helloworld"],
|
||||
"connections": [["mac", "02:5b:26:a8:dc:12"]],
|
||||
"manufacturer": "Whatever",
|
||||
"name": "Beer",
|
||||
"model": "Glass",
|
||||
"sw_version": "0.1-beta",
|
||||
},
|
||||
"unique_id": "veryunique",
|
||||
}
|
||||
)
|
||||
await help_test_entity_device_info_with_identifier(
|
||||
hass, mqtt_mock, light.DOMAIN, data
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG_DEVICE_INFO
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_device_info_update(hass, mqtt_mock):
|
||||
"""Test device registry update."""
|
||||
config = {
|
||||
"platform": "mqtt",
|
||||
"name": "Test 1",
|
||||
"schema": "template",
|
||||
"state_topic": "test-topic",
|
||||
"command_topic": "test-command-topic",
|
||||
"command_on_template": "on,{{ transition }}",
|
||||
"command_off_template": "off,{{ transition|d }}",
|
||||
"device": {
|
||||
"identifiers": ["helloworld"],
|
||||
"connections": [["mac", "02:5b:26:a8:dc:12"]],
|
||||
"manufacturer": "Whatever",
|
||||
"name": "Beer",
|
||||
"model": "Glass",
|
||||
"sw_version": "0.1-beta",
|
||||
},
|
||||
"unique_id": "veryunique",
|
||||
}
|
||||
await help_test_entity_device_info_update(hass, mqtt_mock, light.DOMAIN, config)
|
||||
await help_test_entity_device_info_update(
|
||||
hass, mqtt_mock, light.DOMAIN, DEFAULT_CONFIG_DEVICE_INFO
|
||||
)
|
||||
|
||||
|
||||
async def test_entity_id_update(hass, mqtt_mock):
|
||||
|
||||
Reference in new issue
Block a user