mirror of
https://github.com/home-assistant/core.git
synced 2026-10-09 15:56:23 -04:00
Add diagnostics platform to SMTP (#184091)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""Diagnostics platform for SMTP integration."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import (
|
||||
CONF_PASSWORD,
|
||||
CONF_RECIPIENT,
|
||||
CONF_SENDER,
|
||||
CONF_USERNAME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import SmtpConfigEntry
|
||||
from .const import CONF_REPLY_TO, CONF_REPLY_TO_NAME, CONF_SENDER_NAME, CONF_SERVER
|
||||
|
||||
TO_REDACT = {
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
CONF_SENDER,
|
||||
CONF_SENDER_NAME,
|
||||
CONF_REPLY_TO,
|
||||
CONF_REPLY_TO_NAME,
|
||||
CONF_SERVER,
|
||||
CONF_RECIPIENT,
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: SmtpConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
|
||||
return {
|
||||
"data": async_redact_data(data=config_entry.data, to_redact=TO_REDACT),
|
||||
"options": async_redact_data(data=config_entry.options, to_redact=TO_REDACT),
|
||||
"subentries": len(config_entry.subentries),
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'encryption': 'starttls',
|
||||
'password': '**REDACTED**',
|
||||
'port': 587,
|
||||
'sender': '**REDACTED**',
|
||||
'sender_name': '**REDACTED**',
|
||||
'server': '**REDACTED**',
|
||||
'username': '**REDACTED**',
|
||||
'verify_ssl': True,
|
||||
}),
|
||||
'options': dict({
|
||||
'reply_to': '**REDACTED**',
|
||||
'reply_to_name': '**REDACTED**',
|
||||
'timeout': 1312,
|
||||
}),
|
||||
'subentries': 1,
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Tests for SMTP diagnostics."""
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion 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
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("smtp", "aiosmtplib")
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
== snapshot
|
||||
)
|
||||
Reference in New Issue
Block a user