From 35cd6b9abf7efbbc855411008a8a37fcadb431c3 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sun, 7 Jun 2020 19:35:35 +0200 Subject: [PATCH] Remove unused parameter for MQTT discovery (#36526) * Remove unused parameter for MQTT discovery * Fix tests --- homeassistant/components/mqtt/__init__.py | 18 ++------ homeassistant/components/mqtt/discovery.py | 4 +- tests/components/mqtt/test_binary_sensor.py | 2 +- tests/components/mqtt/test_camera.py | 4 +- tests/components/mqtt/test_common.py | 28 ++++++------ tests/components/mqtt/test_device_trigger.py | 46 ++++++++++---------- tests/components/mqtt/test_discovery.py | 35 ++++++++------- tests/components/mqtt/test_init.py | 20 ++++----- tests/components/mqtt/test_light.py | 2 +- tests/components/mqtt/test_sensor.py | 2 +- 10 files changed, 74 insertions(+), 87 deletions(-) diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 26c844f106af..bab36ee854ef 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -66,7 +66,6 @@ DOMAIN = "mqtt" DATA_MQTT = "mqtt" DATA_MQTT_CONFIG = "mqtt_config" -DATA_MQTT_HASS_CONFIG = "mqtt_hass_config" SERVICE_PUBLISH = "publish" SERVICE_DUMP = "dump" @@ -484,18 +483,14 @@ async def _async_setup_server(hass: HomeAssistantType, config: ConfigType): async def _async_setup_discovery( - hass: HomeAssistantType, conf: ConfigType, hass_config: ConfigType, config_entry + hass: HomeAssistantType, conf: ConfigType, config_entry ) -> bool: """Try to start the discovery of MQTT devices. This method is a coroutine. """ - if discovery is None: - _LOGGER.error("Unable to load MQTT discovery") - return False - success: bool = await discovery.async_start( - hass, conf[CONF_DISCOVERY_PREFIX], hass_config, config_entry + hass, conf[CONF_DISCOVERY_PREFIX], config_entry ) return success @@ -505,11 +500,6 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: """Start the MQTT protocol service.""" conf: Optional[ConfigType] = config.get(DOMAIN) - # We need this because discovery can cause components to be set up and - # otherwise it will not load the users config. - # This needs a better solution. - hass.data[DATA_MQTT_HASS_CONFIG] = config - websocket_api.async_register_command(hass, websocket_subscribe) websocket_api.async_register_command(hass, websocket_remove_device) websocket_api.async_register_command(hass, websocket_mqtt_info) @@ -716,9 +706,7 @@ async def async_setup_entry(hass, entry): ) if conf.get(CONF_DISCOVERY): - await _async_setup_discovery( - hass, conf, hass.data[DATA_MQTT_HASS_CONFIG], entry - ) + await _async_setup_discovery(hass, conf, entry) return True diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py index 1f2b7162556a..0ab108cabde1 100644 --- a/homeassistant/components/mqtt/discovery.py +++ b/homeassistant/components/mqtt/discovery.py @@ -58,9 +58,9 @@ class MQTTConfig(dict): async def async_start( - hass: HomeAssistantType, discovery_topic, hass_config, config_entry=None + hass: HomeAssistantType, discovery_topic, config_entry=None ) -> bool: - """Initialize of MQTT Discovery.""" + """Start MQTT Discovery.""" async def async_device_message_received(msg): """Process the received message.""" diff --git a/tests/components/mqtt/test_binary_sensor.py b/tests/components/mqtt/test_binary_sensor.py index dccf8396c5a6..35fae27bd861 100644 --- a/tests/components/mqtt/test_binary_sensor.py +++ b/tests/components/mqtt/test_binary_sensor.py @@ -528,7 +528,7 @@ async def test_expiration_on_discovery_and_discovery_update_of_binary_sensor( ): """Test that binary_sensor with expire_after set behaves correctly on discovery and discovery update.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) config = { "name": "Test", diff --git a/tests/components/mqtt/test_camera.py b/tests/components/mqtt/test_camera.py index 98e85e2df7c6..33652ca776bd 100644 --- a/tests/components/mqtt/test_camera.py +++ b/tests/components/mqtt/test_camera.py @@ -156,7 +156,7 @@ async def test_discovery_removal_camera(hass, mqtt_mock, caplog): async def test_discovery_update_camera(hass, mqtt_mock, caplog): """Test update of discovered camera.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) data1 = '{ "name": "Beer",' ' "topic": "test_topic"}' data2 = '{ "name": "Milk",' ' "topic": "test_topic"}' @@ -170,7 +170,7 @@ async def test_discovery_update_camera(hass, mqtt_mock, caplog): async def test_discovery_broken(hass, mqtt_mock, caplog): """Test handling of bad discovery message.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) data1 = '{ "name": "Beer" }' data2 = '{ "name": "Milk",' ' "topic": "test_topic"}' diff --git a/tests/components/mqtt/test_common.py b/tests/components/mqtt/test_common.py index d91c236680dd..7ea4897ca5c2 100644 --- a/tests/components/mqtt/test_common.py +++ b/tests/components/mqtt/test_common.py @@ -251,7 +251,7 @@ async def help_test_discovery_update_attr(hass, mqtt_mock, caplog, domain, confi data2 = json.dumps(config2[domain]) entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1) await hass.async_block_till_done() async_fire_mqtt_message(hass, "attr-topic1", '{ "val": "100" }') @@ -287,7 +287,7 @@ async def help_test_discovery_removal(hass, mqtt_mock, caplog, domain, data): This is a test helper for the MqttDiscoveryUpdate mixin. """ entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data) await hass.async_block_till_done() @@ -309,7 +309,7 @@ async def help_test_discovery_update(hass, mqtt_mock, caplog, domain, data1, dat This is a test helper for the MqttDiscoveryUpdate mixin. """ entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1) await hass.async_block_till_done() @@ -332,7 +332,7 @@ async def help_test_discovery_update(hass, mqtt_mock, caplog, domain, data1, dat async def help_test_discovery_broken(hass, mqtt_mock, caplog, domain, data1, data2): """Test handling of bad discovery message.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message(hass, f"homeassistant/{domain}/bla/config", data1) await hass.async_block_till_done() @@ -362,7 +362,7 @@ async def help_test_entity_device_info_with_identifier(hass, mqtt_mock, domain, entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -390,7 +390,7 @@ async def help_test_entity_device_info_with_connection(hass, mqtt_mock, domain, entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -415,7 +415,7 @@ async def help_test_entity_device_info_remove(hass, mqtt_mock, domain, config): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) dev_registry = await hass.helpers.device_registry.async_get_registry() ent_registry = await hass.helpers.entity_registry.async_get_registry() @@ -447,7 +447,7 @@ async def help_test_entity_device_info_update(hass, mqtt_mock, domain, config): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -521,7 +521,7 @@ async def help_test_entity_id_update_discovery_update( entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) ent_registry = mock_registry(hass, {}) data = json.dumps(config[domain]) @@ -562,7 +562,7 @@ async def help_test_entity_debug_info(hass, mqtt_mock, domain, config): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -598,7 +598,7 @@ async def help_test_entity_debug_info_max_messages(hass, mqtt_mock, domain, conf entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -663,7 +663,7 @@ async def help_test_entity_debug_info_message( entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -712,7 +712,7 @@ async def help_test_entity_debug_info_remove(hass, mqtt_mock, domain, config): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -758,7 +758,7 @@ async def help_test_entity_debug_info_update_entity_id(hass, mqtt_mock, domain, entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) dev_registry = await hass.helpers.device_registry.async_get_registry() ent_registry = mock_registry(hass, {}) diff --git a/tests/components/mqtt/test_device_trigger.py b/tests/components/mqtt/test_device_trigger.py index aa7dc746951f..b756458e81b2 100644 --- a/tests/components/mqtt/test_device_trigger.py +++ b/tests/components/mqtt/test_device_trigger.py @@ -43,7 +43,7 @@ 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 = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data1 = ( '{ "automation_type":"trigger",' @@ -75,7 +75,7 @@ async def test_get_unknown_triggers(hass, device_reg, entity_reg, mqtt_mock): """Test we don't get unknown triggers.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) # Discover a sensor (without device triggers) data1 = ( @@ -119,7 +119,7 @@ async def test_get_non_existing_triggers(hass, device_reg, entity_reg, mqtt_mock """Test getting non existing triggers.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) # Discover a sensor (without device triggers) data1 = ( @@ -140,7 +140,7 @@ async def test_discover_bad_triggers(hass, device_reg, entity_reg, mqtt_mock): """Test bad discovery message.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) # Test sending bad data data0 = ( @@ -186,7 +186,7 @@ async def test_update_remove_triggers(hass, device_reg, entity_reg, mqtt_mock): """Test triggers can be updated and removed.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data1 = ( '{ "automation_type":"trigger",' @@ -243,7 +243,7 @@ async def test_if_fires_on_mqtt_message(hass, device_reg, calls, mqtt_mock): """Test triggers firing.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data1 = ( '{ "automation_type":"trigger",' @@ -322,7 +322,7 @@ async def test_if_fires_on_mqtt_message_late_discover( """Test triggers firing of MQTT device triggers discovered after setup.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data0 = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -409,7 +409,7 @@ async def test_if_fires_on_mqtt_message_after_update( """Test triggers firing after update.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data1 = ( '{ "automation_type":"trigger",' @@ -487,7 +487,7 @@ async def test_no_resubscribe_same_topic(hass, device_reg, mqtt_mock): mock_mqtt = await async_mock_mqtt_component(hass) config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data1 = ( '{ "automation_type":"trigger",' @@ -535,7 +535,7 @@ async def test_not_fires_on_mqtt_message_after_remove_by_mqtt( """Test triggers not firing after removal.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data1 = ( '{ "automation_type":"trigger",' @@ -599,7 +599,7 @@ async def test_not_fires_on_mqtt_message_after_remove_from_registry( """Test triggers not firing after removal.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data1 = ( '{ "automation_type":"trigger",' @@ -653,7 +653,7 @@ async def test_attach_remove(hass, device_reg, mqtt_mock): """Test attach and removal of trigger.""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data1 = ( '{ "automation_type":"trigger",' @@ -706,7 +706,7 @@ async def test_attach_remove_late(hass, device_reg, mqtt_mock): """Test attach and removal of trigger .""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data0 = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -767,7 +767,7 @@ async def test_attach_remove_late2(hass, device_reg, mqtt_mock): """Test attach and removal of trigger .""" config_entry = MockConfigEntry(domain=DOMAIN, data={}) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data0 = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -822,7 +822,7 @@ async def test_entity_device_info_with_connection(hass, mqtt_mock): """Test MQTT device registry integration.""" entry = MockConfigEntry(domain=DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps( @@ -856,7 +856,7 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock): """Test MQTT device registry integration.""" entry = MockConfigEntry(domain=DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps( @@ -890,7 +890,7 @@ async def test_entity_device_info_update(hass, mqtt_mock): """Test device registry update.""" entry = MockConfigEntry(domain=DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() config = { @@ -930,7 +930,7 @@ 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 = MockConfigEntry(domain=DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) config = { "automation_type": "trigger", @@ -969,7 +969,7 @@ async def test_cleanup_device(hass, device_reg, entity_reg, mqtt_mock): """Test removal from device registry when trigger is removed.""" config_entry = MockConfigEntry(domain=DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) config = { "automation_type": "trigger", @@ -1002,7 +1002,7 @@ async def test_cleanup_device_several_triggers(hass, device_reg, entity_reg, mqt """Test removal from device registry when the last trigger is removed.""" config_entry = MockConfigEntry(domain=DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) config1 = { "automation_type": "trigger", @@ -1062,7 +1062,7 @@ async def test_cleanup_device_with_entity1(hass, device_reg, entity_reg, mqtt_mo """ config_entry = MockConfigEntry(domain=DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) config1 = { "automation_type": "trigger", @@ -1118,7 +1118,7 @@ async def test_cleanup_device_with_entity2(hass, device_reg, entity_reg, mqtt_mo """ config_entry = MockConfigEntry(domain=DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) config1 = { "automation_type": "trigger", @@ -1174,7 +1174,7 @@ async def test_trigger_debug_info(hass, mqtt_mock): """ entry = MockConfigEntry(domain=DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() config = { diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index 8c75d77efb83..9c0ca4d971e0 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -37,9 +37,8 @@ async def test_subscribing_config_topic(hass, mqtt_mock): """Test setting up discovery.""" entry = MockConfigEntry(domain=mqtt.DOMAIN, data={mqtt.CONF_BROKER: "test-broker"}) - hass_config = {} discovery_topic = "homeassistant" - await async_start(hass, discovery_topic, hass_config, entry) + await async_start(hass, discovery_topic, entry) assert mqtt_mock.async_subscribe.called call_args = mqtt_mock.async_subscribe.mock_calls[0][1] @@ -57,7 +56,7 @@ async def test_invalid_topic(hass, mqtt_mock): ) mock_dispatcher_send = AsyncMock(return_value=None) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, "homeassistant/binary_sensor/bla/not_config", "{}" @@ -76,7 +75,7 @@ async def test_invalid_json(hass, mqtt_mock, caplog): ) mock_dispatcher_send = AsyncMock(return_value=None) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, "homeassistant/binary_sensor/bla/config", "not json" @@ -96,7 +95,7 @@ async def test_only_valid_components(hass, mqtt_mock, caplog): invalid_component = "timer" mock_dispatcher_send = AsyncMock(return_value=None) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, f"homeassistant/{invalid_component}/bla/config", "{}" @@ -113,7 +112,7 @@ async def test_correct_config_discovery(hass, mqtt_mock, caplog): """Test sending in correct JSON.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, @@ -133,7 +132,7 @@ async def test_discover_fan(hass, mqtt_mock, caplog): """Test discovering an MQTT fan.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, @@ -153,7 +152,7 @@ async def test_discover_climate(hass, mqtt_mock, caplog): """Test discovering an MQTT climate component.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) data = ( '{ "name": "ClimateTest",' @@ -175,7 +174,7 @@ async def test_discover_alarm_control_panel(hass, mqtt_mock, caplog): """Test discovering an MQTT alarm control panel component.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) data = ( '{ "name": "AlarmControlPanelTest",' @@ -197,7 +196,7 @@ async def test_discovery_incl_nodeid(hass, mqtt_mock, caplog): """Test sending in correct JSON with optional node_id included.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, @@ -217,7 +216,7 @@ async def test_non_duplicate_discovery(hass, mqtt_mock, caplog): """Test for a non duplicate component.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, @@ -244,7 +243,7 @@ async def test_removal(hass, mqtt_mock, caplog): """Test removal of component through empty discovery message.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, @@ -265,7 +264,7 @@ async def test_rediscover(hass, mqtt_mock, caplog): """Test rediscover of removed component.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, @@ -295,7 +294,7 @@ async def test_duplicate_removal(hass, mqtt_mock, caplog): """Test for a non duplicate component.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) async_fire_mqtt_message( hass, @@ -317,7 +316,7 @@ async def test_cleanup_device(hass, device_reg, entity_reg, mqtt_mock): """Test discvered device is cleaned up when removed from registry.""" config_entry = MockConfigEntry(domain=mqtt.DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -360,7 +359,7 @@ async def test_discovery_expansion(hass, mqtt_mock, caplog): """Test expansion of abbreviated discovery payload.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) data = ( '{ "~": "some/base/topic",' @@ -450,7 +449,7 @@ async def test_no_implicit_state_topic_switch(hass, mqtt_mock, caplog): """Test no implicit state topic for switch.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) data = '{ "name": "Test1",' ' "command_topic": "cmnd"' "}" @@ -475,7 +474,7 @@ async def test_complex_discovery_topic_prefix(hass, mqtt_mock, caplog): """Tests handling of discovery topic prefix with multiple slashes.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "my_home/homeassistant/register", {}, entry) + await async_start(hass, "my_home/homeassistant/register", entry) async_fire_mqtt_message( hass, diff --git a/tests/components/mqtt/test_init.py b/tests/components/mqtt/test_init.py index 3626c5a746c5..94961ebfe7a0 100644 --- a/tests/components/mqtt/test_init.py +++ b/tests/components/mqtt/test_init.py @@ -895,7 +895,7 @@ async def test_mqtt_ws_remove_discovered_device( """Test MQTT websocket device removal.""" config_entry = MockConfigEntry(domain=mqtt.DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -928,7 +928,7 @@ async def test_mqtt_ws_remove_discovered_device_twice( """Test MQTT websocket device removal.""" config_entry = MockConfigEntry(domain=mqtt.DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -963,7 +963,7 @@ async def test_mqtt_ws_remove_discovered_device_same_topic( """Test MQTT websocket device removal.""" config_entry = MockConfigEntry(domain=mqtt.DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) data = ( '{ "device":{"identifiers":["0AFFD2"]},' @@ -1021,7 +1021,7 @@ async def test_mqtt_ws_get_device_debug_info( """Test MQTT websocket device debug info.""" config_entry = MockConfigEntry(domain=mqtt.DOMAIN) config_entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, config_entry) + await async_start(hass, "homeassistant", config_entry) config = { "device": {"identifiers": ["0AFFD2"]}, @@ -1107,7 +1107,7 @@ async def test_debug_info_multiple_devices(hass, mqtt_mock): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() for d in devices: @@ -1189,7 +1189,7 @@ async def test_debug_info_multiple_entities_triggers(hass, mqtt_mock): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() for c in config: @@ -1267,7 +1267,7 @@ async def test_debug_info_wildcard(hass, mqtt_mock): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -1316,7 +1316,7 @@ async def test_debug_info_filter_same(hass, mqtt_mock): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -1378,7 +1378,7 @@ async def test_debug_info_same_topic(hass, mqtt_mock): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) @@ -1432,7 +1432,7 @@ async def test_debug_info_qos_retain(hass, mqtt_mock): entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() data = json.dumps(config) diff --git a/tests/components/mqtt/test_light.py b/tests/components/mqtt/test_light.py index 0e8d0c19a199..faaf84b91345 100644 --- a/tests/components/mqtt/test_light.py +++ b/tests/components/mqtt/test_light.py @@ -1426,7 +1426,7 @@ async def test_discovery_removal_light(hass, mqtt_mock, caplog): async def test_discovery_deprecated(hass, mqtt_mock, caplog): """Test discovery of mqtt light with deprecated platform option.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) - await async_start(hass, "homeassistant", {"mqtt": {}}, entry) + await async_start(hass, "homeassistant", entry) data = ( '{ "name": "Beer",' ' "platform": "mqtt",' ' "command_topic": "test_topic"}' ) diff --git a/tests/components/mqtt/test_sensor.py b/tests/components/mqtt/test_sensor.py index be4b50128179..600c1b11b867 100644 --- a/tests/components/mqtt/test_sensor.py +++ b/tests/components/mqtt/test_sensor.py @@ -433,7 +433,7 @@ async def test_entity_device_info_with_hub(hass, mqtt_mock): """Test MQTT sensor device registry integration.""" entry = MockConfigEntry(domain=mqtt.DOMAIN) entry.add_to_hass(hass) - await async_start(hass, "homeassistant", {}, entry) + await async_start(hass, "homeassistant", entry) registry = await hass.helpers.device_registry.async_get_registry() hub = registry.async_get_or_create(