mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Enable RFDEBUG on RFLink "Enable debug logging" (#138571)
* Enable RFDEBUG on "Enable debug logging" * fix checks * fix checks * one more lap * fix test * wait to init rflink In my dev env this is not needed * use hass.async_create_task(handle_logging_changed()) instead async_at_started(hass, handle_logging_changed) * revert unneeded async_block_till_done * Remove the startup management There's a race condition at startup that can't be managed nicely
This commit is contained in:
parent
3ecde49dca
commit
3d83c6299b
@ -16,8 +16,16 @@ from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PORT,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
EVENT_LOGGING_CHANGED,
|
||||
)
|
||||
from homeassistant.core import (
|
||||
CoreState,
|
||||
Event,
|
||||
HassJob,
|
||||
HomeAssistant,
|
||||
ServiceCall,
|
||||
callback,
|
||||
)
|
||||
from homeassistant.core import CoreState, HassJob, HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
@ -41,6 +49,7 @@ from .entity import RflinkCommand
|
||||
from .utils import identify_event_type
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
LIB_LOGGER = logging.getLogger("rflink")
|
||||
|
||||
CONF_IGNORE_DEVICES = "ignore_devices"
|
||||
CONF_RECONNECT_INTERVAL = "reconnect_interval"
|
||||
@ -277,4 +286,17 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
|
||||
hass.async_create_task(connect(), eager_start=False)
|
||||
async_dispatcher_connect(hass, SIGNAL_EVENT, event_callback)
|
||||
|
||||
async def handle_logging_changed(_: Event) -> None:
|
||||
"""Handle logging changed event."""
|
||||
if LIB_LOGGER.isEnabledFor(logging.DEBUG):
|
||||
await RflinkCommand.send_command("rfdebug", "on")
|
||||
_LOGGER.info("RFDEBUG enabled")
|
||||
else:
|
||||
await RflinkCommand.send_command("rfdebug", "off")
|
||||
_LOGGER.info("RFDEBUG disabled")
|
||||
|
||||
# Listen to EVENT_LOGGING_CHANGED to manage the RFDEBUG
|
||||
hass.bus.async_listen(EVENT_LOGGING_CHANGED, handle_logging_changed)
|
||||
|
||||
return True
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Common functions for RFLink component tests and generic platform tests."""
|
||||
|
||||
import logging
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
@ -21,6 +22,7 @@ from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_HOST,
|
||||
CONF_PORT,
|
||||
EVENT_LOGGING_CHANGED,
|
||||
SERVICE_STOP_COVER,
|
||||
SERVICE_TURN_OFF,
|
||||
)
|
||||
@ -556,3 +558,30 @@ async def test_unique_id(
|
||||
temperature_entry = entity_registry.async_get("sensor.temperature_device")
|
||||
assert temperature_entry
|
||||
assert temperature_entry.unique_id == "my_temperature_device_unique_id"
|
||||
|
||||
|
||||
async def test_enable_debug_logs(
|
||||
hass: HomeAssistant,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test that changing debug level enables RFDEBUG."""
|
||||
|
||||
domain = RFLINK_DOMAIN
|
||||
config = {RFLINK_DOMAIN: {CONF_HOST: "10.10.0.1", CONF_PORT: 1234}}
|
||||
|
||||
# setup mocking rflink module
|
||||
_, mock_create, _, _ = await mock_rflink(hass, config, domain, monkeypatch)
|
||||
|
||||
logging.getLogger("rflink").setLevel(logging.DEBUG)
|
||||
hass.bus.async_fire(EVENT_LOGGING_CHANGED)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "RFDEBUG enabled" in caplog.text
|
||||
assert "RFDEBUG disabled" not in caplog.text
|
||||
|
||||
logging.getLogger("rflink").setLevel(logging.INFO)
|
||||
hass.bus.async_fire(EVENT_LOGGING_CHANGED)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert "RFDEBUG disabled" in caplog.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user