File tree Expand file tree Collapse file tree 4 files changed +79
-1
lines changed
homeassistant/components/telegram_bot
tests/components/telegram_bot Expand file tree Collapse file tree 4 files changed +79
-1
lines changed Original file line number Diff line number Diff line change 1+ """Diagnostics platform for Telegram bot integration."""
2+
3+ from __future__ import annotations
4+
5+ from typing import Any
6+
7+ from yarl import URL
8+
9+ from homeassistant .components .diagnostics import REDACTED , async_redact_data
10+ from homeassistant .const import CONF_API_KEY , CONF_URL
11+ from homeassistant .core import HomeAssistant
12+
13+ from . import TelegramBotConfigEntry
14+ from .const import CONF_CHAT_ID
15+
16+ TO_REDACT = [CONF_API_KEY , CONF_CHAT_ID ]
17+
18+
19+ async def async_get_config_entry_diagnostics (
20+ hass : HomeAssistant , config_entry : TelegramBotConfigEntry
21+ ) -> dict [str , Any ]:
22+ """Return diagnostics for a config entry."""
23+
24+ data = async_redact_data (config_entry .data , TO_REDACT )
25+ if config_entry .data .get (CONF_URL ):
26+ url = URL (config_entry .data [CONF_URL ])
27+ data [CONF_URL ] = url .with_host (REDACTED ).human_repr ()
28+
29+ return {
30+ "data" : data ,
31+ "options" : async_redact_data (config_entry .options , TO_REDACT ),
32+ "subentries_count" : len (config_entry .subentries .values ()),
33+ }
Original file line number Diff line number Diff line change 4545
4646 # Gold
4747 devices : todo
48- diagnostics : todo
48+ diagnostics : done
4949 discovery-update-info : todo
5050 discovery : todo
5151 docs-data-update : todo
Original file line number Diff line number Diff line change 1+ # serializer version: 1
2+ # name: test_diagnostics
3+ dict({
4+ 'data': dict({
5+ 'api_key': '**REDACTED**',
6+ 'platform': 'webhooks',
7+ 'proxy_url': None,
8+ 'trusted_networks': list([
9+ '127.0.0.1/32',
10+ ]),
11+ 'url': 'https://**redacted**/',
12+ }),
13+ 'options': dict({
14+ 'parse_mode': 'markdown',
15+ }),
16+ 'subentries_count': 2,
17+ })
18+ # ---
Original file line number Diff line number Diff line change 1+ """Tests for Telegram bot diagnostics."""
2+
3+ from syrupy .assertion import SnapshotAssertion
4+
5+ from homeassistant .components .telegram_bot .const import DOMAIN
6+ from homeassistant .core import HomeAssistant
7+
8+ from tests .components .diagnostics import get_diagnostics_for_config_entry
9+ from tests .typing import ClientSessionGenerator
10+
11+
12+ async def test_diagnostics (
13+ hass : HomeAssistant ,
14+ hass_client : ClientSessionGenerator ,
15+ webhook_platform ,
16+ mock_external_calls : None ,
17+ mock_generate_secret_token ,
18+ snapshot : SnapshotAssertion ,
19+ ) -> None :
20+ """Test diagnostics."""
21+
22+ config_entry = hass .config_entries .async_entries (DOMAIN )[0 ]
23+
24+ diagnostics = await get_diagnostics_for_config_entry (
25+ hass , hass_client , config_entry
26+ )
27+ assert diagnostics == snapshot
You can’t perform that action at this time.
0 commit comments