2022-02-08 21:05:33 +00:00
|
|
|
"""Tests for Tradfri diagnostics."""
|
2023-02-13 14:40:21 +00:00
|
|
|
from unittest.mock import MagicMock, Mock, PropertyMock, patch
|
|
|
|
|
|
|
|
import pytest
|
2022-02-08 21:05:33 +00:00
|
|
|
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
|
|
from .common import setup_integration
|
2023-02-13 14:40:21 +00:00
|
|
|
from .test_sensor import mock_fan
|
2022-02-08 21:05:33 +00:00
|
|
|
|
|
|
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
2023-02-02 21:29:57 +00:00
|
|
|
from tests.typing import ClientSessionGenerator
|
2022-02-08 21:05:33 +00:00
|
|
|
|
|
|
|
|
2023-02-13 14:40:21 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def setup(request):
|
|
|
|
"""Set up patches for pytradfri methods for the fan platform.
|
|
|
|
|
|
|
|
This is used in test_fan as well as in test_sensor.
|
|
|
|
"""
|
|
|
|
with patch(
|
|
|
|
"pytradfri.device.AirPurifierControl.raw",
|
|
|
|
new_callable=PropertyMock,
|
|
|
|
return_value=[{"mock": "mock"}],
|
|
|
|
), patch(
|
|
|
|
"pytradfri.device.AirPurifierControl.air_purifiers",
|
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2022-02-08 21:05:33 +00:00
|
|
|
async def test_diagnostics(
|
|
|
|
hass: HomeAssistant,
|
2023-02-02 21:29:57 +00:00
|
|
|
hass_client: ClientSessionGenerator,
|
2022-02-08 21:05:33 +00:00
|
|
|
mock_gateway: Mock,
|
|
|
|
mock_api_factory: MagicMock,
|
|
|
|
) -> None:
|
|
|
|
"""Test diagnostics for config entry."""
|
|
|
|
mock_gateway.mock_devices.append(
|
|
|
|
# Add a fan
|
|
|
|
mock_fan(
|
|
|
|
test_state={
|
|
|
|
"fan_speed": 10,
|
|
|
|
"air_quality": 42,
|
|
|
|
"filter_lifetime_remaining": 120,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
init_integration = await setup_integration(hass)
|
|
|
|
|
|
|
|
result = await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
|
|
|
|
|
|
|
assert isinstance(result, dict)
|
|
|
|
assert result["gateway_version"] == "1.2.1234"
|
2023-02-13 14:40:21 +00:00
|
|
|
assert result["device_data"] == ["model"]
|