mirror of
https://github.com/home-assistant/core.git
synced 2025-08-08 07:05:07 +02:00
Add description and strings. Expect string from user
This commit is contained in:
7
homeassistant/components/jewish_calendar/icons.json
Normal file
7
homeassistant/components/jewish_calendar/icons.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"services": {
|
||||
"count_omer": {
|
||||
"service": "mdi:counter"
|
||||
}
|
||||
}
|
||||
}
|
@@ -19,7 +19,7 @@ from .const import DOMAIN
|
||||
OMER_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required("date", default=datetime.date.today): datetime.date,
|
||||
vol.Required("nusach", default=Nusach.SFARAD): Nusach,
|
||||
vol.Required("nusach", default="sfarad"): str,
|
||||
vol.Required("language"): str,
|
||||
}
|
||||
)
|
||||
@@ -30,19 +30,24 @@ def async_setup_services(
|
||||
) -> None:
|
||||
"""Set up the Jewish Calendar services."""
|
||||
|
||||
async def get_omer_blessing(call: ServiceCall) -> ServiceResponse:
|
||||
async def get_omer_count(call: ServiceCall) -> ServiceResponse:
|
||||
"""Return the Omer blessing for a given date."""
|
||||
value = Omer(
|
||||
date=HebrewDate.from_gdate(call.data["date"]),
|
||||
nusach=call.data["nusach"],
|
||||
language=call.data.get("language", config_entry.runtime_data.language),
|
||||
).count_str()
|
||||
return {"message": str(value)}
|
||||
hebrew_date = HebrewDate.from_gdate(call.data["date"])
|
||||
nusach = Nusach[call.data["nusach"].upper()]
|
||||
language = call.data.get("language", config_entry.runtime_data.language)
|
||||
omer = Omer(date=hebrew_date, nusach=nusach, language=language)
|
||||
return {
|
||||
"message": str(omer.count_str()),
|
||||
"hebrew_date": str(hebrew_date),
|
||||
"weeks": omer.week,
|
||||
"days": omer.day,
|
||||
"total_days": omer.total_days,
|
||||
}
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
"get_omer_blessing",
|
||||
get_omer_blessing,
|
||||
"count_omer",
|
||||
get_omer_count,
|
||||
schema=OMER_SCHEMA,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
|
@@ -0,0 +1,29 @@
|
||||
count_omer:
|
||||
fields:
|
||||
date:
|
||||
required: true
|
||||
example: "2025-04-14"
|
||||
selector:
|
||||
date:
|
||||
nusach:
|
||||
example: "sfarad"
|
||||
default: "sfarad"
|
||||
selector:
|
||||
select:
|
||||
translation_key: "nusach"
|
||||
options:
|
||||
- "sfarad"
|
||||
- "ashkenaz"
|
||||
- "adot_mizrah"
|
||||
- "italian"
|
||||
language:
|
||||
required: true
|
||||
default: "hebrew"
|
||||
example: "hebrew"
|
||||
selector:
|
||||
select:
|
||||
translation_key: "language"
|
||||
options:
|
||||
- "english"
|
||||
- "hebrew"
|
||||
- "french"
|
||||
|
@@ -45,5 +45,42 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"selector": {
|
||||
"nusach": {
|
||||
"options": {
|
||||
"sfarad": "Sfarad",
|
||||
"ashkenaz": "Ashkenaz",
|
||||
"adot_mizrah": "Adot Mizrah",
|
||||
"italian": "Italian"
|
||||
}
|
||||
},
|
||||
"language": {
|
||||
"options": {
|
||||
"hebrew": "Hebrew",
|
||||
"english": "English",
|
||||
"french": "French"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"count_omer": {
|
||||
"name": "Count the Omer",
|
||||
"description": "Return the phrase for counting the Omer on a given date.",
|
||||
"fields": {
|
||||
"date": {
|
||||
"name": "Date",
|
||||
"description": "Date to count the Omer for."
|
||||
},
|
||||
"nusach": {
|
||||
"name": "Nusach",
|
||||
"description": "Nusach to count the Omer in."
|
||||
},
|
||||
"language": {
|
||||
"name": "Language",
|
||||
"description": "Language to count the Omer in."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
import datetime as dt
|
||||
|
||||
from hdate.omer import Nusach
|
||||
from hdate.translator import Language
|
||||
import pytest
|
||||
|
||||
@@ -17,21 +16,21 @@ from tests.common import MockConfigEntry
|
||||
[
|
||||
pytest.param(
|
||||
dt.date(2025, 3, 20),
|
||||
Nusach.SFARAD,
|
||||
"sfarad",
|
||||
"hebrew",
|
||||
"",
|
||||
id="no_blessing",
|
||||
),
|
||||
pytest.param(
|
||||
dt.date(2025, 5, 20),
|
||||
Nusach.ASHKENAZ,
|
||||
"ashkenaz",
|
||||
"hebrew",
|
||||
"היום שבעה ושלושים יום שהם חמישה שבועות ושני ימים בעומר",
|
||||
id="ahskenaz-hebrew",
|
||||
),
|
||||
pytest.param(
|
||||
dt.date(2025, 5, 20),
|
||||
Nusach.SFARAD,
|
||||
"sfarad",
|
||||
"english",
|
||||
"Today is the thirty-seventh day, which are five weeks and two days of the Omer",
|
||||
id="sefarad-english",
|
||||
@@ -42,7 +41,7 @@ async def test_get_omer_blessing(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
test_date: dt.date,
|
||||
nusach: Nusach,
|
||||
nusach: str,
|
||||
language: Language,
|
||||
expected: str,
|
||||
) -> None:
|
||||
@@ -53,7 +52,7 @@ async def test_get_omer_blessing(
|
||||
|
||||
result = await hass.services.async_call(
|
||||
DOMAIN,
|
||||
"get_omer_blessing",
|
||||
"count_omer",
|
||||
{"date": test_date, "nusach": nusach, "language": language},
|
||||
blocking=True,
|
||||
return_response=True,
|
||||
|
Reference in New Issue
Block a user