mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Add diagnostics support to Meater (#146967)
This commit is contained in:
parent
cb21bb6542
commit
589577a04c
55
homeassistant/components/meater/diagnostics.py
Normal file
55
homeassistant/components/meater/diagnostics.py
Normal file
@ -0,0 +1,55 @@
|
||||
"""Diagnostics support for the Meater integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import MeaterConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: MeaterConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = config_entry.runtime_data
|
||||
|
||||
return {
|
||||
identifier: {
|
||||
"id": probe.id,
|
||||
"internal_temperature": probe.internal_temperature,
|
||||
"ambient_temperature": probe.ambient_temperature,
|
||||
"time_updated": probe.time_updated.isoformat(),
|
||||
"cook": (
|
||||
{
|
||||
"id": probe.cook.id,
|
||||
"name": probe.cook.name,
|
||||
"state": probe.cook.state,
|
||||
"target_temperature": (
|
||||
probe.cook.target_temperature
|
||||
if hasattr(probe.cook, "target_temperature")
|
||||
else None
|
||||
),
|
||||
"peak_temperature": (
|
||||
probe.cook.peak_temperature
|
||||
if hasattr(probe.cook, "peak_temperature")
|
||||
else None
|
||||
),
|
||||
"time_remaining": (
|
||||
probe.cook.time_remaining
|
||||
if hasattr(probe.cook, "time_remaining")
|
||||
else None
|
||||
),
|
||||
"time_elapsed": (
|
||||
probe.cook.time_elapsed
|
||||
if hasattr(probe.cook, "time_elapsed")
|
||||
else None
|
||||
),
|
||||
}
|
||||
if probe.cook
|
||||
else None
|
||||
),
|
||||
}
|
||||
for identifier, probe in coordinator.data.items()
|
||||
}
|
20
tests/components/meater/snapshots/test_diagnostics.ambr
Normal file
20
tests/components/meater/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,20 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'40a72384fa80349314dfd97c84b73a5c1c9da57b59e26d67b573d618fe0d6e58': dict({
|
||||
'ambient_temperature': 28.0,
|
||||
'cook': dict({
|
||||
'id': '123123',
|
||||
'name': 'Whole chicken',
|
||||
'peak_temperature': 27.0,
|
||||
'state': 'Started',
|
||||
'target_temperature': 25.0,
|
||||
'time_elapsed': 32,
|
||||
'time_remaining': 32,
|
||||
}),
|
||||
'id': '40a72384fa80349314dfd97c84b73a5c1c9da57b59e26d67b573d618fe0d6e58',
|
||||
'internal_temperature': 26.0,
|
||||
'time_updated': '2025-06-16T13:53:51+00:00',
|
||||
}),
|
||||
})
|
||||
# ---
|
28
tests/components/meater/test_diagnostics.py
Normal file
28
tests/components/meater/test_diagnostics.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""Test Meater diagnostics."""
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import setup_integration
|
||||
|
||||
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,
|
||||
hass_client: ClientSessionGenerator,
|
||||
mock_meater_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, mock_config_entry)
|
||||
== snapshot
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user