Add sensors to ntfy integration (#145262)

* Add sensors

* small changes

* test coverage

* changes

* update snapshot
This commit is contained in:
Manu
2025-06-23 23:17:43 +02:00
committed by GitHub
parent 95abd69cc6
commit 646ddf9c2d
9 changed files with 1603 additions and 8 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -65,3 +65,37 @@ async def test_config_entry_not_ready(
await hass.async_block_till_done()
assert config_entry.state is state
@pytest.mark.parametrize(
("exception", "state"),
[
(
NtfyUnauthorizedAuthenticationError(
40101,
401,
"unauthorized",
"https://ntfy.sh/docs/publish/#authentication",
),
ConfigEntryState.SETUP_ERROR,
),
(NtfyHTTPError(418001, 418, "I'm a teapot", ""), ConfigEntryState.SETUP_RETRY),
(NtfyConnectionError, ConfigEntryState.SETUP_RETRY),
(NtfyTimeoutError, ConfigEntryState.SETUP_RETRY),
],
)
async def test_coordinator_update_exceptions(
hass: HomeAssistant,
config_entry: MockConfigEntry,
mock_aiontfy: AsyncMock,
exception: Exception,
state: ConfigEntryState,
) -> None:
"""Test config entry not ready from update failed in _async_update_data."""
mock_aiontfy.account.side_effect = [None, exception]
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is state

View File

@@ -0,0 +1,42 @@
"""Tests for the ntfy sensor platform."""
from collections.abc import Generator
from unittest.mock import patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from tests.common import MockConfigEntry, snapshot_platform
@pytest.fixture(autouse=True)
def sensor_only() -> Generator[None]:
"""Enable only the sensor platform."""
with patch(
"homeassistant.components.ntfy.PLATFORMS",
[Platform.SENSOR],
):
yield
@pytest.mark.usefixtures("mock_aiontfy", "entity_registry_enabled_by_default")
async def test_setup(
hass: HomeAssistant,
config_entry: MockConfigEntry,
snapshot: SnapshotAssertion,
entity_registry: er.EntityRegistry,
) -> None:
"""Snapshot test states of sensor platform."""
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)