mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Guard expensive debug formatting with calls with isEnabledFor (#97073)
This commit is contained in:
parent
61532475f9
commit
d4cdb0453f
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
|
import logging
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
@ -106,7 +107,8 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
except (asyncio.TimeoutError, ResponseError):
|
except (asyncio.TimeoutError, ResponseError):
|
||||||
self.bridges = []
|
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:
|
if self.bridges:
|
||||||
hosts = []
|
hosts = []
|
||||||
@ -215,7 +217,8 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||||
"""Handle a discovered deCONZ bridge."""
|
"""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])
|
self.bridge_id = normalize_bridge_id(discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL])
|
||||||
parsed_url = urlparse(discovery_info.ssdp_location)
|
parsed_url = urlparse(discovery_info.ssdp_location)
|
||||||
@ -248,7 +251,8 @@ class DeconzFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
This flow is triggered by the discovery component.
|
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])
|
self.bridge_id = normalize_bridge_id(discovery_info.config[CONF_SERIAL])
|
||||||
await self.async_set_unique_id(self.bridge_id)
|
await self.async_set_unique_id(self.bridge_id)
|
||||||
|
@ -126,7 +126,8 @@ class DlnaDmrFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||||
"""Handle a flow initialized by SSDP discovery."""
|
"""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)
|
await self._async_set_info_from_discovery(discovery_info)
|
||||||
|
|
||||||
|
@ -67,7 +67,8 @@ class DlnaDmsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||||
"""Handle a flow initialized by SSDP discovery."""
|
"""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)
|
await self._async_parse_discovery(discovery_info)
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
|
import logging
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
@ -218,7 +219,8 @@ class OnvifFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
if not configured:
|
if not configured:
|
||||||
self.devices.append(device)
|
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:
|
if self.devices:
|
||||||
devices = {CONF_MANUAL_INPUT: CONF_MANUAL_INPUT}
|
devices = {CONF_MANUAL_INPUT: CONF_MANUAL_INPUT}
|
||||||
@ -274,9 +276,10 @@ class OnvifFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self, configure_unique_id: bool = True
|
self, configure_unique_id: bool = True
|
||||||
) -> tuple[dict[str, str], dict[str, str]]:
|
) -> tuple[dict[str, str], dict[str, str]]:
|
||||||
"""Fetch ONVIF device profiles."""
|
"""Fetch ONVIF device profiles."""
|
||||||
LOGGER.debug(
|
if LOGGER.isEnabledFor(logging.DEBUG):
|
||||||
"Fetching profiles from ONVIF device %s", pformat(self.onvif_config)
|
LOGGER.debug(
|
||||||
)
|
"Fetching profiles from ONVIF device %s", pformat(self.onvif_config)
|
||||||
|
)
|
||||||
|
|
||||||
device = get_device(
|
device = get_device(
|
||||||
self.hass,
|
self.hass,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
"""Tests for deCONZ config flow."""
|
"""Tests for deCONZ config flow."""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pydeconz
|
import pydeconz
|
||||||
@ -42,6 +43,7 @@ async def test_flow_discovered_bridges(
|
|||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that config flow works for discovered bridges."""
|
"""Test that config flow works for discovered bridges."""
|
||||||
|
logging.getLogger("homeassistant.components.deconz").setLevel(logging.DEBUG)
|
||||||
aioclient_mock.get(
|
aioclient_mock.get(
|
||||||
pydeconz.utils.URL_DISCOVER,
|
pydeconz.utils.URL_DISCOVER,
|
||||||
json=[
|
json=[
|
||||||
@ -142,6 +144,7 @@ async def test_flow_manual_configuration(
|
|||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that config flow works with manual configuration after no discovered bridges."""
|
"""Test that config flow works with manual configuration after no discovered bridges."""
|
||||||
|
logging.getLogger("homeassistant.components.deconz").setLevel(logging.DEBUG)
|
||||||
aioclient_mock.get(
|
aioclient_mock.get(
|
||||||
pydeconz.utils.URL_DISCOVER,
|
pydeconz.utils.URL_DISCOVER,
|
||||||
json=[],
|
json=[],
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
import dataclasses
|
import dataclasses
|
||||||
|
import logging
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from async_upnp_client.client import UpnpDevice
|
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:
|
async def test_ssdp_flow_success(hass: HomeAssistant) -> None:
|
||||||
"""Test that SSDP discovery with an available device works."""
|
"""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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DLNA_DOMAIN,
|
DLNA_DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_SSDP},
|
context={"source": config_entries.SOURCE_SSDP},
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
import dataclasses
|
import dataclasses
|
||||||
|
import logging
|
||||||
from typing import Final
|
from typing import Final
|
||||||
from unittest.mock import Mock, patch
|
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:
|
async def test_ssdp_flow_success(hass: HomeAssistant) -> None:
|
||||||
"""Test that SSDP discovery with an available device works."""
|
"""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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_SSDP},
|
context={"source": config_entries.SOURCE_SSDP},
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
"""Test ONVIF config flow."""
|
"""Test ONVIF config flow."""
|
||||||
|
import logging
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -103,6 +104,7 @@ def setup_mock_discovery(
|
|||||||
|
|
||||||
async def test_flow_discovered_devices(hass: HomeAssistant) -> None:
|
async def test_flow_discovered_devices(hass: HomeAssistant) -> None:
|
||||||
"""Test that config flow works for discovered devices."""
|
"""Test that config flow works for discovered devices."""
|
||||||
|
logging.getLogger("homeassistant.components.onvif").setLevel(logging.DEBUG)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
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,
|
hass: HomeAssistant,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that config flow discovery ignores configured devices."""
|
"""Test that config flow discovery ignores configured devices."""
|
||||||
|
logging.getLogger("homeassistant.components.onvif").setLevel(logging.DEBUG)
|
||||||
await setup_onvif_integration(hass)
|
await setup_onvif_integration(hass)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
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:
|
async def test_flow_discovery_ignore_existing_and_abort(hass: HomeAssistant) -> None:
|
||||||
"""Test that config flow discovery ignores setup devices."""
|
"""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)
|
||||||
await setup_onvif_integration(
|
await setup_onvif_integration(
|
||||||
hass,
|
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:
|
async def test_flow_manual_entry(hass: HomeAssistant) -> None:
|
||||||
"""Test that config flow works for discovered devices."""
|
"""Test that config flow works for discovered devices."""
|
||||||
|
logging.getLogger("homeassistant.components.onvif").setLevel(logging.DEBUG)
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
config_flow.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user