Enable MQTT discovery by default (#41361)

This commit is contained in:
Erik Montnemery authored and GitHub committed 2020-10-07 14:51:06 +02:00
1 parent b7c2e117be
commit 306ee30574
11 files changed
+33 -275

No files matched your search

@@ -6,7 +6,6 @@ import pytest
import homeassistant.components.automation as automation
from homeassistant.components.mqtt import DOMAIN, debug_info
from homeassistant.components.mqtt.device_trigger import async_attach_trigger
from homeassistant.components.mqtt.discovery import async_start
from homeassistant.setup import async_setup_component
from tests.common import (
@@ -39,9 +38,6 @@ def calls(hass):
async def test_get_triggers(hass, device_reg, entity_reg, mqtt_mock):
"""Test we get the expected triggers from a discovered mqtt device."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data1 = (
'{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},'
@@ -70,9 +66,6 @@ async def test_get_triggers(hass, device_reg, entity_reg, mqtt_mock):
async def test_get_unknown_triggers(hass, device_reg, entity_reg, mqtt_mock):
"""Test we don't get unknown triggers."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
# Discover a sensor (without device triggers)
data1 = (
'{ "device":{"identifiers":["0AFFD2"]},'
@@ -113,9 +106,6 @@ async def test_get_unknown_triggers(hass, device_reg, entity_reg, mqtt_mock):
async def test_get_non_existing_triggers(hass, device_reg, entity_reg, mqtt_mock):
"""Test getting non existing triggers."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
# Discover a sensor (without device triggers)
data1 = (
'{ "device":{"identifiers":["0AFFD2"]},'
@@ -133,9 +123,6 @@ async def test_get_non_existing_triggers(hass, device_reg, entity_reg, mqtt_mock
@pytest.mark.no_fail_on_log_exception
async def test_discover_bad_triggers(hass, device_reg, entity_reg, mqtt_mock):
"""Test bad discovery message."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
# Test sending bad data
data0 = (
'{ "automation_type":"trigger",'
@@ -178,9 +165,6 @@ async def test_discover_bad_triggers(hass, device_reg, entity_reg, mqtt_mock):
async def test_update_remove_triggers(hass, device_reg, entity_reg, mqtt_mock):
"""Test triggers can be updated and removed."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data1 = (
'{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},'
@@ -234,9 +218,6 @@ async def test_update_remove_triggers(hass, device_reg, entity_reg, mqtt_mock):
async def test_if_fires_on_mqtt_message(hass, device_reg, calls, mqtt_mock):
"""Test triggers firing."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data1 = (
'{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},'
@@ -312,9 +293,6 @@ async def test_if_fires_on_mqtt_message_late_discover(
hass, device_reg, calls, mqtt_mock
):
"""Test triggers firing of MQTT device triggers discovered after setup."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data0 = (
'{ "device":{"identifiers":["0AFFD2"]},'
' "state_topic": "foobar/sensor",'
@@ -398,9 +376,6 @@ async def test_if_fires_on_mqtt_message_after_update(
hass, device_reg, calls, mqtt_mock
):
"""Test triggers firing after update."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data1 = (
'{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},'
@@ -474,9 +449,6 @@ async def test_if_fires_on_mqtt_message_after_update(
async def test_no_resubscribe_same_topic(hass, device_reg, mqtt_mock):
"""Test subscription to topics without change."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data1 = (
'{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},'
@@ -521,9 +493,6 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt(
hass, device_reg, calls, mqtt_mock
):
"""Test triggers not firing after removal."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data1 = (
'{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},'
@@ -584,9 +553,6 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
hass, device_reg, calls, mqtt_mock
):
"""Test triggers not firing after removal."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data1 = (
'{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},'
@@ -637,9 +603,6 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry(
async def test_attach_remove(hass, device_reg, mqtt_mock):
"""Test attach and removal of trigger."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data1 = (
'{ "automation_type":"trigger",'
' "device":{"identifiers":["0AFFD2"]},'
@@ -689,9 +652,6 @@ async def test_attach_remove(hass, device_reg, mqtt_mock):
async def test_attach_remove_late(hass, device_reg, mqtt_mock):
"""Test attach and removal of trigger ."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data0 = (
'{ "device":{"identifiers":["0AFFD2"]},'
' "state_topic": "foobar/sensor",'
@@ -749,9 +709,6 @@ async def test_attach_remove_late(hass, device_reg, mqtt_mock):
async def test_attach_remove_late2(hass, device_reg, mqtt_mock):
"""Test attach and removal of trigger ."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
data0 = (
'{ "device":{"identifiers":["0AFFD2"]},'
' "state_topic": "foobar/sensor",'
@@ -803,8 +760,6 @@ async def test_attach_remove_late2(hass, device_reg, mqtt_mock):
async def test_entity_device_info_with_connection(hass, mqtt_mock):
"""Test MQTT device registry integration."""
entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", entry)
registry = await hass.helpers.device_registry.async_get_registry()
data = json.dumps(
@@ -836,8 +791,6 @@ async def test_entity_device_info_with_connection(hass, mqtt_mock):
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
"""Test MQTT device registry integration."""
entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", entry)
registry = await hass.helpers.device_registry.async_get_registry()
data = json.dumps(
@@ -869,8 +822,6 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock):
async def test_entity_device_info_update(hass, mqtt_mock):
"""Test device registry update."""
entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", entry)
registry = await hass.helpers.device_registry.async_get_registry()
config = {
@@ -908,9 +859,6 @@ async def test_entity_device_info_update(hass, mqtt_mock):
async def test_cleanup_trigger(hass, device_reg, entity_reg, mqtt_mock):
"""Test trigger discovery topic is cleaned when device is removed from registry."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
config = {
"automation_type": "trigger",
"topic": "test-topic",
@@ -946,9 +894,6 @@ async def test_cleanup_trigger(hass, device_reg, entity_reg, mqtt_mock):
async def test_cleanup_device(hass, device_reg, entity_reg, mqtt_mock):
"""Test removal from device registry when trigger is removed."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
config = {
"automation_type": "trigger",
"topic": "test-topic",
@@ -978,9 +923,6 @@ async def test_cleanup_device(hass, device_reg, entity_reg, mqtt_mock):
async def test_cleanup_device_several_triggers(hass, device_reg, entity_reg, mqtt_mock):
"""Test removal from device registry when the last trigger is removed."""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
config1 = {
"automation_type": "trigger",
"topic": "test-topic",
@@ -1037,9 +979,6 @@ async def test_cleanup_device_with_entity1(hass, device_reg, entity_reg, mqtt_mo
Trigger removed first, then entity.
"""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
config1 = {
"automation_type": "trigger",
"topic": "test-topic",
@@ -1092,9 +1031,6 @@ async def test_cleanup_device_with_entity2(hass, device_reg, entity_reg, mqtt_mo
Entity removed first, then trigger.
"""
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", config_entry)
config1 = {
"automation_type": "trigger",
"topic": "test-topic",
@@ -1147,8 +1083,6 @@ async def test_trigger_debug_info(hass, mqtt_mock):
This is a test helper for MQTT debug_info.
"""
entry = hass.config_entries.async_entries(DOMAIN)[0]
await async_start(hass, "homeassistant", entry)
registry = await hass.helpers.device_registry.async_get_registry()
config = {