mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 21:47:08 +00:00
Add diagnostics for Telegram bot (#154016)
This commit is contained in:
33
homeassistant/components/telegram_bot/diagnostics.py
Normal file
33
homeassistant/components/telegram_bot/diagnostics.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Diagnostics platform for Telegram bot integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from yarl import URL
|
||||
|
||||
from homeassistant.components.diagnostics import REDACTED, async_redact_data
|
||||
from homeassistant.const import CONF_API_KEY, CONF_URL
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import TelegramBotConfigEntry
|
||||
from .const import CONF_CHAT_ID
|
||||
|
||||
TO_REDACT = [CONF_API_KEY, CONF_CHAT_ID]
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, config_entry: TelegramBotConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
|
||||
data = async_redact_data(config_entry.data, TO_REDACT)
|
||||
if config_entry.data.get(CONF_URL):
|
||||
url = URL(config_entry.data[CONF_URL])
|
||||
data[CONF_URL] = url.with_host(REDACTED).human_repr()
|
||||
|
||||
return {
|
||||
"data": data,
|
||||
"options": async_redact_data(config_entry.options, TO_REDACT),
|
||||
"subentries_count": len(config_entry.subentries.values()),
|
||||
}
|
||||
@@ -45,7 +45,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: todo
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info: todo
|
||||
discovery: todo
|
||||
docs-data-update: todo
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'api_key': '**REDACTED**',
|
||||
'platform': 'webhooks',
|
||||
'proxy_url': None,
|
||||
'trusted_networks': list([
|
||||
'127.0.0.1/32',
|
||||
]),
|
||||
'url': 'https://**redacted**/',
|
||||
}),
|
||||
'options': dict({
|
||||
'parse_mode': 'markdown',
|
||||
}),
|
||||
'subentries_count': 2,
|
||||
})
|
||||
# ---
|
||||
27
tests/components/telegram_bot/test_diagnostics.py
Normal file
27
tests/components/telegram_bot/test_diagnostics.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Tests for Telegram bot diagnostics."""
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.telegram_bot.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
webhook_platform,
|
||||
mock_external_calls: None,
|
||||
mock_generate_secret_token,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
|
||||
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||
|
||||
diagnostics = await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, config_entry
|
||||
)
|
||||
assert diagnostics == snapshot
|
||||
Reference in New Issue
Block a user