Support toggling debug logging for custom components (#90340)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Jonas Bergler 2023-03-28 08:40:58 +13:00 committed by GitHub
parent 71b5ccee23
commit 9f04c23414
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 5 deletions

View file

@ -1,6 +1,8 @@
"""Tests for Logger Websocket API commands."""
import logging
from unittest.mock import patch
from homeassistant import loader
from homeassistant.components.logger.helpers import async_get_domain_config
from homeassistant.components.websocket_api import const
from homeassistant.core import HomeAssistant
@ -79,6 +81,55 @@ async def test_integration_log_level(
}
async def test_custom_integration_log_level(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, hass_admin_user: MockUser
) -> None:
"""Test setting integration log level."""
websocket_client = await hass_ws_client()
assert await async_setup_component(hass, "logger", {})
integration = loader.Integration(
hass,
"custom_components.hue",
None,
{
"name": "Hue",
"dependencies": [],
"requirements": [],
"domain": "hue",
"loggers": ["some_other_logger"],
},
)
with patch(
"homeassistant.components.logger.helpers.async_get_integration",
return_value=integration,
), patch(
"homeassistant.components.logger.websocket_api.async_get_integration",
return_value=integration,
):
await websocket_client.send_json(
{
"id": 7,
"type": "logger/integration_log_level",
"integration": "hue",
"level": "DEBUG",
"persistence": "none",
}
)
msg = await websocket_client.receive_json()
assert msg["id"] == 7
assert msg["type"] == const.TYPE_RESULT
assert msg["success"]
assert async_get_domain_config(hass).overrides == {
"homeassistant.components.hue": logging.DEBUG,
"custom_components.hue": logging.DEBUG,
"some_other_logger": logging.DEBUG,
}
async def test_integration_log_level_unknown_integration(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, hass_admin_user: MockUser
) -> None: