1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Remove duplicated config from MQTT tests (#32689)

This commit is contained in:
Erik Montnemery
2020-03-11 17:34:19 +01:00
committed by GitHub
parent 5216dc0ae1
commit f7ddbc7e1e
14 changed files with 599 additions and 1131 deletions

View File

@@ -1,6 +1,4 @@
"""The tests for the MQTT cover platform."""
import json
from homeassistant.components import cover
from homeassistant.components.cover import ATTR_POSITION, ATTR_TILT_POSITION
from homeassistant.components.mqtt.cover import MqttCover
@@ -41,6 +39,31 @@ from .common import (
from tests.common import async_fire_mqtt_message
DEFAULT_CONFIG_ATTR = {
cover.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "test-topic",
"json_attributes_topic": "attr-topic",
}
}
DEFAULT_CONFIG_DEVICE_INFO = {
"platform": "mqtt",
"name": "Test 1",
"state_topic": "test-topic",
"command_topic": "test-command-topic",
"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_state_via_state_topic(hass, mqtt_mock):
"""Test the controlling state via topic."""
@@ -1700,61 +1723,38 @@ async def test_invalid_device_class(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 = {
cover.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "test-topic",
"json_attributes_topic": "attr-topic",
}
}
await help_test_setting_attribute_via_mqtt_json_message(
hass, mqtt_mock, cover.DOMAIN, config
hass, mqtt_mock, cover.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 = {
cover.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "test-topic",
"json_attributes_topic": "attr-topic",
}
}
await help_test_update_with_json_attrs_not_dict(
hass, mqtt_mock, caplog, cover.DOMAIN, config
hass, mqtt_mock, caplog, cover.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 = {
cover.DOMAIN: {
"platform": "mqtt",
"name": "test",
"state_topic": "test-topic",
"json_attributes_topic": "attr-topic",
}
}
await help_test_update_with_json_attrs_bad_JSON(
hass, mqtt_mock, caplog, cover.DOMAIN, config
hass, mqtt_mock, caplog, cover.DOMAIN, DEFAULT_CONFIG_ATTR
)
async def test_discovery_update_attr(hass, mqtt_mock, caplog):
"""Test update of discovered MQTTAttributes."""
data1 = (
'{ "name": "Beer",'
'{ "name": "test",'
' "command_topic": "test_topic",'
' "json_attributes_topic": "attr-topic1" }'
)
data2 = (
'{ "name": "Beer",'
'{ "name": "test",'
' "command_topic": "test_topic",'
' "json_attributes_topic": "attr-topic2" }'
)
await help_test_discovery_update_attr(
hass, mqtt_mock, caplog, cover.DOMAIN, data1, data2
)
@@ -1783,7 +1783,7 @@ async def test_unique_id(hass):
async def test_discovery_removal_cover(hass, mqtt_mock, caplog):
"""Test removal of discovered cover."""
data = '{ "name": "Beer",' ' "command_topic": "test_topic" }'
data = '{ "name": "test",' ' "command_topic": "test_topic" }'
await help_test_discovery_removal(hass, mqtt_mock, caplog, cover.DOMAIN, data)
@@ -1807,46 +1807,16 @@ async def test_discovery_broken(hass, mqtt_mock, caplog):
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
"""Test MQTT cover device registry integration."""
data = json.dumps(
{
"platform": "mqtt",
"name": "Test 1",
"state_topic": "test-topic",
"command_topic": "test-command-topic",
"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, cover.DOMAIN, data
hass, mqtt_mock, cover.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",
"state_topic": "test-topic",
"command_topic": "test-command-topic",
"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, cover.DOMAIN, config)
await help_test_entity_device_info_update(
hass, mqtt_mock, cover.DOMAIN, DEFAULT_CONFIG_DEVICE_INFO
)
async def test_entity_id_update(hass, mqtt_mock):