diff --git a/homeassistant/components/device_tracker/legacy.py b/homeassistant/components/device_tracker/legacy.py index a90d92944a4..2614bd4228a 100644 --- a/homeassistant/components/device_tracker/legacy.py +++ b/homeassistant/components/device_tracker/legacy.py @@ -250,21 +250,19 @@ class DeviceTrackerPlatform: else: raise HomeAssistantError("Invalid legacy device_tracker platform.") - if setup: - hass.config.components.add(full_name) - if scanner: async_setup_scanner_platform( hass, self.config, scanner, tracker.async_see, self.type ) - return - if not setup: + if not setup and not scanner: LOGGER.error( "Error setting up platform %s %s", self.type, self.name ) return + hass.config.components.add(full_name) + except Exception: # pylint: disable=broad-except LOGGER.exception( "Error setting up platform %s %s", self.type, self.name diff --git a/tests/components/device_tracker/test_init.py b/tests/components/device_tracker/test_init.py index af0c7658ac7..6155ed7d1db 100644 --- a/tests/components/device_tracker/test_init.py +++ b/tests/components/device_tracker/test_init.py @@ -120,6 +120,7 @@ async def test_reading_yaml_config(hass, yaml_devices): assert device.config_picture == config.config_picture assert device.consider_home == config.consider_home assert device.icon == config.icon + assert f"{device_tracker.DOMAIN}.test" in hass.config.components @patch("homeassistant.components.device_tracker.const.LOGGER.warning") @@ -558,6 +559,8 @@ async def test_bad_platform(hass): with assert_setup_component(0, device_tracker.DOMAIN): assert await async_setup_component(hass, device_tracker.DOMAIN, config) + assert f"{device_tracker.DOMAIN}.bad_platform" not in hass.config.components + async def test_adding_unknown_device_to_config(mock_device_tracker_conf, hass): """Test the adding of unknown devices to configuration file."""