mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Add diagnostics to Palazzetti (#131608)
This commit is contained in:
parent
1ddc8a35c2
commit
1fc3194613
20
homeassistant/components/palazzetti/diagnostics.py
Normal file
20
homeassistant/components/palazzetti/diagnostics.py
Normal file
@ -0,0 +1,20 @@
|
||||
"""Provides diagnostics for Palazzetti."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import PalazzettiConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: PalazzettiConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
client = entry.runtime_data.client
|
||||
|
||||
return {
|
||||
"api_data": client.to_dict(redact=True),
|
||||
}
|
@ -47,7 +47,7 @@ rules:
|
||||
test-coverage: todo
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info: done
|
||||
discovery: done
|
||||
docs-data-update: todo
|
||||
|
@ -1,13 +1,14 @@
|
||||
"""Fixtures for Palazzetti integration tests."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from pypalazzetti.temperature import TemperatureDefinition, TemperatureDescriptionKey
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.palazzetti.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@ -51,6 +52,12 @@ def mock_palazzetti_client() -> Generator[AsyncMock]:
|
||||
mock_client.name = "Stove"
|
||||
mock_client.sw_version = "0.0.0"
|
||||
mock_client.hw_version = "1.1.1"
|
||||
mock_client.to_dict.return_value = {
|
||||
"host": "XXXXXXXXXX",
|
||||
"connected": True,
|
||||
"properties": {},
|
||||
"attributes": {},
|
||||
}
|
||||
mock_client.fan_speed_min = 1
|
||||
mock_client.fan_speed_max = 5
|
||||
mock_client.has_fan_silent = True
|
||||
@ -111,3 +118,17 @@ def mock_palazzetti_client() -> Generator[AsyncMock]:
|
||||
),
|
||||
]
|
||||
yield mock_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def init_integration(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_palazzetti_client: MagicMock,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the Palazzetti integration for testing."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return mock_config_entry
|
||||
|
13
tests/components/palazzetti/snapshots/test_diagnostics.ambr
Normal file
13
tests/components/palazzetti/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,13 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'api_data': dict({
|
||||
'attributes': dict({
|
||||
}),
|
||||
'connected': True,
|
||||
'host': 'XXXXXXXXXX',
|
||||
'properties': dict({
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
22
tests/components/palazzetti/test_diagnostics.py
Normal file
22
tests/components/palazzetti/test_diagnostics.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""Test Palazzetti diagnostics."""
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
||||
== snapshot
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user