mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Add diagnostics for Cookidoo integration (#136770)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
ce432555f0
commit
04d1d80917
@ -14,6 +14,7 @@ from cookidoo_api import (
|
|||||||
CookidooIngredientItem,
|
CookidooIngredientItem,
|
||||||
CookidooRequestException,
|
CookidooRequestException,
|
||||||
CookidooSubscription,
|
CookidooSubscription,
|
||||||
|
CookidooUserInfo,
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -42,6 +43,7 @@ class CookidooDataUpdateCoordinator(DataUpdateCoordinator[CookidooData]):
|
|||||||
"""A Cookidoo Data Update Coordinator."""
|
"""A Cookidoo Data Update Coordinator."""
|
||||||
|
|
||||||
config_entry: CookidooConfigEntry
|
config_entry: CookidooConfigEntry
|
||||||
|
user: CookidooUserInfo
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, cookidoo: Cookidoo, entry: CookidooConfigEntry
|
self, hass: HomeAssistant, cookidoo: Cookidoo, entry: CookidooConfigEntry
|
||||||
@ -59,6 +61,7 @@ class CookidooDataUpdateCoordinator(DataUpdateCoordinator[CookidooData]):
|
|||||||
async def _async_setup(self) -> None:
|
async def _async_setup(self) -> None:
|
||||||
try:
|
try:
|
||||||
await self.cookidoo.login()
|
await self.cookidoo.login()
|
||||||
|
self.user = await self.cookidoo.get_user_info()
|
||||||
except CookidooRequestException as e:
|
except CookidooRequestException as e:
|
||||||
raise UpdateFailed(
|
raise UpdateFailed(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
|
26
homeassistant/components/cookidoo/diagnostics.py
Normal file
26
homeassistant/components/cookidoo/diagnostics.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
"""Diagnostics for the Cookidoo integration."""
|
||||||
|
|
||||||
|
from dataclasses import asdict
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.const import CONF_PASSWORD
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .coordinator import CookidooConfigEntry
|
||||||
|
|
||||||
|
TO_REDACT = [
|
||||||
|
CONF_PASSWORD,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: CookidooConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
|
||||||
|
return {
|
||||||
|
"entry_data": async_redact_data(entry.data, TO_REDACT),
|
||||||
|
"data": asdict(entry.runtime_data.data),
|
||||||
|
"user": asdict(entry.runtime_data.user),
|
||||||
|
}
|
@ -63,7 +63,7 @@ rules:
|
|||||||
stale-devices:
|
stale-devices:
|
||||||
status: exempt
|
status: exempt
|
||||||
comment: No stale entities possible
|
comment: No stale entities possible
|
||||||
diagnostics: todo
|
diagnostics: done
|
||||||
exception-translations: done
|
exception-translations: done
|
||||||
icon-translations: done
|
icon-translations: done
|
||||||
reconfiguration-flow: done
|
reconfiguration-flow: done
|
||||||
|
@ -9,6 +9,7 @@ from cookidoo_api import (
|
|||||||
CookidooAuthResponse,
|
CookidooAuthResponse,
|
||||||
CookidooIngredientItem,
|
CookidooIngredientItem,
|
||||||
CookidooSubscription,
|
CookidooSubscription,
|
||||||
|
CookidooUserInfo,
|
||||||
)
|
)
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -58,7 +59,9 @@ def mock_cookidoo_client() -> Generator[AsyncMock]:
|
|||||||
client.get_active_subscription.return_value = CookidooSubscription(
|
client.get_active_subscription.return_value = CookidooSubscription(
|
||||||
**load_json_object_fixture("subscriptions.json", DOMAIN)["data"]
|
**load_json_object_fixture("subscriptions.json", DOMAIN)["data"]
|
||||||
)
|
)
|
||||||
|
client.get_user_info.return_value = CookidooUserInfo(
|
||||||
|
**load_json_object_fixture("user_info.json", DOMAIN)["data"]
|
||||||
|
)
|
||||||
client.login.return_value = CookidooAuthResponse(
|
client.login.return_value = CookidooAuthResponse(
|
||||||
**load_json_object_fixture("login.json", DOMAIN)
|
**load_json_object_fixture("login.json", DOMAIN)
|
||||||
)
|
)
|
||||||
|
7
tests/components/cookidoo/fixtures/user_info.json
Normal file
7
tests/components/cookidoo/fixtures/user_info.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"username": "username_1234",
|
||||||
|
"description": null,
|
||||||
|
"picture": null
|
||||||
|
}
|
||||||
|
}
|
43
tests/components/cookidoo/snapshots/test_diagnostics.ambr
Normal file
43
tests/components/cookidoo/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_diagnostics
|
||||||
|
dict({
|
||||||
|
'data': dict({
|
||||||
|
'additional_items': list([
|
||||||
|
dict({
|
||||||
|
'id': 'unique_id_tomaten',
|
||||||
|
'is_owned': False,
|
||||||
|
'name': 'Tomaten',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'ingredient_items': list([
|
||||||
|
dict({
|
||||||
|
'description': '200 g',
|
||||||
|
'id': 'unique_id_mehl',
|
||||||
|
'is_owned': False,
|
||||||
|
'name': 'Mehl',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'subscription': dict({
|
||||||
|
'active': True,
|
||||||
|
'expires': '2025-12-16T23:59:00Z',
|
||||||
|
'extended_type': 'REGULAR',
|
||||||
|
'start_date': '2024-12-16T00:00:00Z',
|
||||||
|
'status': 'ACTIVE',
|
||||||
|
'subscription_level': 'FULL',
|
||||||
|
'subscription_source': 'COMMERCE',
|
||||||
|
'type': 'REGULAR',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'entry_data': dict({
|
||||||
|
'country': 'CH',
|
||||||
|
'email': 'test-email',
|
||||||
|
'language': 'de-CH',
|
||||||
|
'password': '**REDACTED**',
|
||||||
|
}),
|
||||||
|
'user': dict({
|
||||||
|
'description': None,
|
||||||
|
'picture': None,
|
||||||
|
'username': 'username_1234',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
# ---
|
29
tests/components/cookidoo/test_diagnostics.py
Normal file
29
tests/components/cookidoo/test_diagnostics.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""Tests for the diagnostics data provided by the Cookidoo integration."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from syrupy 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_diagnostics(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
mock_cookidoo_client: AsyncMock,
|
||||||
|
cookidoo_config_entry: MockConfigEntry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test diagnostics."""
|
||||||
|
await setup_integration(hass, cookidoo_config_entry)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
await get_diagnostics_for_config_entry(hass, hass_client, cookidoo_config_entry)
|
||||||
|
== snapshot
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user