Jewish Calendar: Implement diagnostics (#145180)

* Implement diagnostics

* Add testing

* Remove implicitly tested code
This commit is contained in:
Tsvi Mostovicz 2025-05-19 21:41:00 +03:00 committed by GitHub
parent 7e895f7d10
commit 1f6faaacab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 138 additions and 1 deletions

View File

@ -6,6 +6,7 @@ ATTR_AFTER_SUNSET = "after_sunset"
ATTR_DATE = "date"
ATTR_NUSACH = "nusach"
CONF_ALTITUDE = "altitude" # The name used by the hdate library for elevation
CONF_DIASPORA = "diaspora"
CONF_CANDLE_LIGHT_MINUTES = "candle_lighting_minutes_before_sunset"
CONF_HAVDALAH_OFFSET_MINUTES = "havdalah_minutes_after_sunset"

View File

@ -0,0 +1,28 @@
"""Diagnostics support for Jewish Calendar integration."""
from dataclasses import asdict
from typing import Any
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
from homeassistant.core import HomeAssistant
from .const import CONF_ALTITUDE
from .entity import JewishCalendarConfigEntry
TO_REDACT = [
CONF_ALTITUDE,
CONF_LATITUDE,
CONF_LONGITUDE,
]
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: JewishCalendarConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
return {
"entry_data": async_redact_data(entry.data, TO_REDACT),
"data": async_redact_data(asdict(entry.runtime_data), TO_REDACT),
}

View File

@ -49,7 +49,7 @@ def mock_setup_entry() -> Generator[AsyncMock]:
@pytest.fixture
def location_data(request: pytest.FixtureRequest) -> _LocationData | None:
"""Return data based on location name."""
if not hasattr(request, "param"):
if not hasattr(request, "param") or request.param is None:
return None
return LOCATIONS[request.param]

View File

@ -0,0 +1,77 @@
# serializer version: 1
# name: test_diagnostics[Jerusalem]
dict({
'data': dict({
'candle_lighting_offset': 40,
'diaspora': False,
'havdalah_offset': 0,
'language': 'en',
'location': dict({
'altitude': '**REDACTED**',
'diaspora': False,
'latitude': '**REDACTED**',
'longitude': '**REDACTED**',
'name': 'test home',
'timezone': dict({
'__type': "<class 'zoneinfo.ZoneInfo'>",
'repr': "zoneinfo.ZoneInfo(key='Asia/Jerusalem')",
}),
}),
}),
'entry_data': dict({
'diaspora': False,
'language': 'en',
'time_zone': 'Asia/Jerusalem',
}),
})
# ---
# name: test_diagnostics[New York]
dict({
'data': dict({
'candle_lighting_offset': 18,
'diaspora': True,
'havdalah_offset': 0,
'language': 'en',
'location': dict({
'altitude': '**REDACTED**',
'diaspora': True,
'latitude': '**REDACTED**',
'longitude': '**REDACTED**',
'name': 'test home',
'timezone': dict({
'__type': "<class 'zoneinfo.ZoneInfo'>",
'repr': "zoneinfo.ZoneInfo(key='America/New_York')",
}),
}),
}),
'entry_data': dict({
'diaspora': True,
'language': 'en',
'time_zone': 'America/New_York',
}),
})
# ---
# name: test_diagnostics[None]
dict({
'data': dict({
'candle_lighting_offset': 18,
'diaspora': False,
'havdalah_offset': 0,
'language': 'en',
'location': dict({
'altitude': '**REDACTED**',
'diaspora': False,
'latitude': '**REDACTED**',
'longitude': '**REDACTED**',
'name': 'test home',
'timezone': dict({
'__type': "<class 'zoneinfo.ZoneInfo'>",
'repr': "zoneinfo.ZoneInfo(key='US/Pacific')",
}),
}),
}),
'entry_data': dict({
'language': 'en',
}),
})
# ---

View File

@ -0,0 +1,31 @@
"""Tests for the diagnostics data provided by the Jewish Calendar integration."""
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.parametrize(
("location_data"), ["Jerusalem", "New York", None], indirect=True
)
async def test_diagnostics(
hass: HomeAssistant,
config_entry: MockConfigEntry,
hass_client: ClientSessionGenerator,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics with different locations."""
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
diagnostics_data = await get_diagnostics_for_config_entry(
hass, hass_client, config_entry
)
assert diagnostics_data == snapshot