mirror of
https://github.com/home-assistant/core.git
synced 2025-08-02 10:08:23 +00:00
Add diagnostics platform to ntfy platform (#143774)
This commit is contained in:
parent
d95c9c496e
commit
c704df004a
29
homeassistant/components/ntfy/diagnostics.py
Normal file
29
homeassistant/components/ntfy/diagnostics.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""Diagnostics platform for ntfy integration."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from yarl import URL
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import REDACTED
|
||||||
|
from homeassistant.const import CONF_URL
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from . import NtfyConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, config_entry: NtfyConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
|
||||||
|
url = URL(config_entry.data[CONF_URL])
|
||||||
|
return {
|
||||||
|
CONF_URL: (
|
||||||
|
url.human_repr()
|
||||||
|
if url.host == "ntfy.sh"
|
||||||
|
else url.with_host(REDACTED).human_repr()
|
||||||
|
),
|
||||||
|
"topics": dict(config_entry.subentries),
|
||||||
|
}
|
@ -49,7 +49,7 @@ rules:
|
|||||||
|
|
||||||
# Gold
|
# Gold
|
||||||
devices: done
|
devices: done
|
||||||
diagnostics: todo
|
diagnostics: done
|
||||||
discovery-update-info: todo
|
discovery-update-info: todo
|
||||||
discovery: todo
|
discovery: todo
|
||||||
docs-data-update: todo
|
docs-data-update: todo
|
||||||
|
24
tests/components/ntfy/snapshots/test_diagnostics.ambr
Normal file
24
tests/components/ntfy/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_diagnostics
|
||||||
|
dict({
|
||||||
|
'topics': dict({
|
||||||
|
'ABCDEF': dict({
|
||||||
|
'data': dict({
|
||||||
|
'topic': 'mytopic',
|
||||||
|
}),
|
||||||
|
'subentry_id': 'ABCDEF',
|
||||||
|
'subentry_type': 'topic',
|
||||||
|
'title': 'mytopic',
|
||||||
|
'unique_id': 'mytopic',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
'url': 'https://ntfy.sh/',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_diagnostics_redacted_url
|
||||||
|
dict({
|
||||||
|
'topics': dict({
|
||||||
|
}),
|
||||||
|
'url': 'http://**redacted**/',
|
||||||
|
})
|
||||||
|
# ---
|
55
tests/components/ntfy/test_diagnostics.py
Normal file
55
tests/components/ntfy/test_diagnostics.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
"""Tests for ntfy diagnostics."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
|
from homeassistant.components.ntfy.const import DOMAIN
|
||||||
|
from homeassistant.const import CONF_URL
|
||||||
|
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("mock_aiontfy")
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_aiontfy")
|
||||||
|
async def test_diagnostics_redacted_url(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
hass_client: ClientSessionGenerator,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test diagnostics redacted URL."""
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
title="mydomain",
|
||||||
|
data={
|
||||||
|
CONF_URL: "http://mydomain/",
|
||||||
|
},
|
||||||
|
entry_id="123456789",
|
||||||
|
subentries_data=[],
|
||||||
|
)
|
||||||
|
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
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user