diff --git a/homeassistant/components/deconz/config_flow.py b/homeassistant/components/deconz/config_flow.py index acbf5089f96..8eda93c2d46 100644 --- a/homeassistant/components/deconz/config_flow.py +++ b/homeassistant/components/deconz/config_flow.py @@ -4,6 +4,7 @@ from __future__ import annotations import asyncio from collections.abc import Mapping +import logging from pprint import pformat from typing import Any, cast from urllib.parse import urlparse @@ -106,7 +107,8 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN): except (asyncio.TimeoutError, ResponseError): self.bridges = [] - LOGGER.debug("Discovered deCONZ gateways %s", pformat(self.bridges)) + if LOGGER.isEnabledFor(logging.DEBUG): + LOGGER.debug("Discovered deCONZ gateways %s", pformat(self.bridges)) if self.bridges: hosts = [] @@ -215,7 +217,8 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN): async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult: """Handle a discovered deCONZ bridge.""" - LOGGER.debug("deCONZ SSDP discovery %s", pformat(discovery_info)) + if LOGGER.isEnabledFor(logging.DEBUG): + LOGGER.debug("deCONZ SSDP discovery %s", pformat(discovery_info)) self.bridge_id = normalize_bridge_id(discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL]) parsed_url = urlparse(discovery_info.ssdp_location) @@ -248,7 +251,8 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN): This flow is triggered by the discovery component. """ - LOGGER.debug("deCONZ HASSIO discovery %s", pformat(discovery_info.config)) + if LOGGER.isEnabledFor(logging.DEBUG): + LOGGER.debug("deCONZ HASSIO discovery %s", pformat(discovery_info.config)) self.bridge_id = normalize_bridge_id(discovery_info.config[CONF_SERIAL]) await self.async_set_unique_id(self.bridge_id) diff --git a/homeassistant/components/dlna_dmr/config_flow.py b/homeassistant/components/dlna_dmr/config_flow.py index bcd402e6a63..1ad29c72c26 100644 --- a/homeassistant/components/dlna_dmr/config_flow.py +++ b/homeassistant/components/dlna_dmr/config_flow.py @@ -126,7 +126,8 @@ class DlnaDmrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult: """Handle a flow initialized by SSDP discovery.""" - LOGGER.debug("async_step_ssdp: discovery_info %s", pformat(discovery_info)) + if LOGGER.isEnabledFor(logging.DEBUG): + LOGGER.debug("async_step_ssdp: discovery_info %s", pformat(discovery_info)) await self._async_set_info_from_discovery(discovery_info) diff --git a/homeassistant/components/dlna_dms/config_flow.py b/homeassistant/components/dlna_dms/config_flow.py index 8cb34be927f..e147055df05 100644 --- a/homeassistant/components/dlna_dms/config_flow.py +++ b/homeassistant/components/dlna_dms/config_flow.py @@ -67,7 +67,8 @@ class DlnaDmsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult: """Handle a flow initialized by SSDP discovery.""" - LOGGER.debug("async_step_ssdp: discovery_info %s", pformat(discovery_info)) + if LOGGER.isEnabledFor(logging.DEBUG): + LOGGER.debug("async_step_ssdp: discovery_info %s", pformat(discovery_info)) await self._async_parse_discovery(discovery_info) diff --git a/homeassistant/components/onvif/config_flow.py b/homeassistant/components/onvif/config_flow.py index 842fe4298cf..e0342c5f0d4 100644 --- a/homeassistant/components/onvif/config_flow.py +++ b/homeassistant/components/onvif/config_flow.py @@ -2,6 +2,7 @@ from __future__ import annotations from collections.abc import Mapping +import logging from pprint import pformat from typing import Any from urllib.parse import urlparse @@ -218,7 +219,8 @@ class OnvifFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): if not configured: self.devices.append(device) - LOGGER.debug("Discovered ONVIF devices %s", pformat(self.devices)) + if LOGGER.isEnabledFor(logging.DEBUG): + LOGGER.debug("Discovered ONVIF devices %s", pformat(self.devices)) if self.devices: devices = {CONF_MANUAL_INPUT: CONF_MANUAL_INPUT} @@ -274,9 +276,10 @@ class OnvifFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self, configure_unique_id: bool = True ) -> tuple[dict[str, str], dict[str, str]]: """Fetch ONVIF device profiles.""" - LOGGER.debug( - "Fetching profiles from ONVIF device %s", pformat(self.onvif_config) - ) + if LOGGER.isEnabledFor(logging.DEBUG): + LOGGER.debug( + "Fetching profiles from ONVIF device %s", pformat(self.onvif_config) + ) device = get_device( self.hass, diff --git a/tests/components/deconz/test_config_flow.py b/tests/components/deconz/test_config_flow.py index d0c51e39987..1211d4dfa46 100644 --- a/tests/components/deconz/test_config_flow.py +++ b/tests/components/deconz/test_config_flow.py @@ -1,5 +1,6 @@ """Tests for deCONZ config flow.""" import asyncio +import logging from unittest.mock import patch import pydeconz @@ -42,6 +43,7 @@ async def test_flow_discovered_bridges( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test that config flow works for discovered bridges.""" + logging.getLogger("homeassistant.components.deconz").setLevel(logging.DEBUG) aioclient_mock.get( pydeconz.utils.URL_DISCOVER, json=[ @@ -142,6 +144,7 @@ async def test_flow_manual_configuration( hass: HomeAssistant, aioclient_mock: AiohttpClientMocker ) -> None: """Test that config flow works with manual configuration after no discovered bridges.""" + logging.getLogger("homeassistant.components.deconz").setLevel(logging.DEBUG) aioclient_mock.get( pydeconz.utils.URL_DISCOVER, json=[], diff --git a/tests/components/dlna_dmr/test_config_flow.py b/tests/components/dlna_dmr/test_config_flow.py index c3251cd31a2..43e60638ba9 100644 --- a/tests/components/dlna_dmr/test_config_flow.py +++ b/tests/components/dlna_dmr/test_config_flow.py @@ -3,6 +3,7 @@ from __future__ import annotations from collections.abc import Iterable import dataclasses +import logging from unittest.mock import Mock, patch from async_upnp_client.client import UpnpDevice @@ -286,6 +287,9 @@ async def test_user_flow_wrong_st(hass: HomeAssistant, domain_data_mock: Mock) - async def test_ssdp_flow_success(hass: HomeAssistant) -> None: """Test that SSDP discovery with an available device works.""" + logging.getLogger("homeassistant.components.dlna_dmr.config_flow").setLevel( + logging.DEBUG + ) result = await hass.config_entries.flow.async_init( DLNA_DOMAIN, context={"source": config_entries.SOURCE_SSDP}, diff --git a/tests/components/dlna_dms/test_config_flow.py b/tests/components/dlna_dms/test_config_flow.py index 1d6ac0eaf80..c8c2998458f 100644 --- a/tests/components/dlna_dms/test_config_flow.py +++ b/tests/components/dlna_dms/test_config_flow.py @@ -3,6 +3,7 @@ from __future__ import annotations from collections.abc import Iterable import dataclasses +import logging from typing import Final from unittest.mock import Mock, patch @@ -125,6 +126,9 @@ async def test_user_flow_no_devices( async def test_ssdp_flow_success(hass: HomeAssistant) -> None: """Test that SSDP discovery with an available device works.""" + logging.getLogger("homeassistant.components.dlna_dms.config_flow").setLevel( + logging.DEBUG + ) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_SSDP}, diff --git a/tests/components/onvif/test_config_flow.py b/tests/components/onvif/test_config_flow.py index 00fc77076e8..6133a382855 100644 --- a/tests/components/onvif/test_config_flow.py +++ b/tests/components/onvif/test_config_flow.py @@ -1,4 +1,5 @@ """Test ONVIF config flow.""" +import logging from unittest.mock import MagicMock, patch import pytest @@ -103,6 +104,7 @@ def setup_mock_discovery( async def test_flow_discovered_devices(hass: HomeAssistant) -> None: """Test that config flow works for discovered devices.""" + logging.getLogger("homeassistant.components.onvif").setLevel(logging.DEBUG) result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER} @@ -172,6 +174,7 @@ async def test_flow_discovered_devices_ignore_configured_manual_input( hass: HomeAssistant, ) -> None: """Test that config flow discovery ignores configured devices.""" + logging.getLogger("homeassistant.components.onvif").setLevel(logging.DEBUG) await setup_onvif_integration(hass) result = await hass.config_entries.flow.async_init( @@ -241,6 +244,7 @@ async def test_flow_discovered_no_device(hass: HomeAssistant) -> None: async def test_flow_discovery_ignore_existing_and_abort(hass: HomeAssistant) -> None: """Test that config flow discovery ignores setup devices.""" + logging.getLogger("homeassistant.components.onvif").setLevel(logging.DEBUG) await setup_onvif_integration(hass) await setup_onvif_integration( hass, @@ -298,6 +302,7 @@ async def test_flow_discovery_ignore_existing_and_abort(hass: HomeAssistant) -> async def test_flow_manual_entry(hass: HomeAssistant) -> None: """Test that config flow works for discovered devices.""" + logging.getLogger("homeassistant.components.onvif").setLevel(logging.DEBUG) result = await hass.config_entries.flow.async_init( config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER} )