-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add diagnostics for Cookidoo integration (#136770)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
- Loading branch information
Showing
7 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"data": { | ||
"username": "username_1234", | ||
"description": null, | ||
"picture": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}), | ||
}) | ||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |