mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add diagnostics to acaia (#131153)
This commit is contained in:
parent
deb82cf072
commit
f1a4baa1b5
31
homeassistant/components/acaia/diagnostics.py
Normal file
31
homeassistant/components/acaia/diagnostics.py
Normal file
@ -0,0 +1,31 @@
|
||||
"""Diagnostics support for Acaia."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import AcaiaConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
entry: AcaiaConfigEntry,
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
scale = coordinator.scale
|
||||
|
||||
# collect all data sources
|
||||
return {
|
||||
"model": scale.model,
|
||||
"device_state": (
|
||||
asdict(scale.device_state) if scale.device_state is not None else ""
|
||||
),
|
||||
"mac": scale.mac,
|
||||
"last_disconnect_time": scale.last_disconnect_time,
|
||||
"timer": scale.timer,
|
||||
"weight": scale.weight,
|
||||
}
|
@ -52,9 +52,10 @@ def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
|
||||
@pytest.fixture
|
||||
async def init_integration(
|
||||
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_scale: MagicMock
|
||||
) -> None:
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the acaia integration for testing."""
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
return mock_config_entry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -70,6 +71,7 @@ def mock_scale() -> Generator[MagicMock]:
|
||||
scale.connected = True
|
||||
scale.mac = "aa:bb:cc:dd:ee:ff"
|
||||
scale.model = "Lunar"
|
||||
scale.last_disconnect_time = "1732181388.1895587"
|
||||
scale.timer_running = True
|
||||
scale.heartbeat_task = None
|
||||
scale.process_queue_task = None
|
||||
@ -77,4 +79,5 @@ def mock_scale() -> Generator[MagicMock]:
|
||||
battery_level=42, units=AcaiaUnitOfMass.OUNCES
|
||||
)
|
||||
scale.weight = 123.45
|
||||
scale.timer = 23
|
||||
yield scale
|
||||
|
16
tests/components/acaia/snapshots/test_diagnostics.ambr
Normal file
16
tests/components/acaia/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,16 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'device_state': dict({
|
||||
'auto_off_time': 0,
|
||||
'battery_level': 42,
|
||||
'beeps': True,
|
||||
'units': 'ounces',
|
||||
}),
|
||||
'last_disconnect_time': '1732181388.1895587',
|
||||
'mac': 'aa:bb:cc:dd:ee:ff',
|
||||
'model': 'Lunar',
|
||||
'timer': 23,
|
||||
'weight': 123.45,
|
||||
})
|
||||
# ---
|
22
tests/components/acaia/test_diagnostics.py
Normal file
22
tests/components/acaia/test_diagnostics.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""Tests for the diagnostics data provided by the Acaia integration."""
|
||||
|
||||
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_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
init_integration: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
||||
== snapshot
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user