From 8e22041ee96c65137034a78c36fc748f8c389fb6 Mon Sep 17 00:00:00 2001 From: Rami Mosleh Date: Sun, 3 Sep 2023 17:12:37 +0300 Subject: [PATCH] Change calculation methods to a fixed list (#99535) --- .../islamic_prayer_times/config_flow.py | 13 ++++++++++- .../components/islamic_prayer_times/const.py | 21 +++++++++++++++--- .../islamic_prayer_times/strings.json | 22 +++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/islamic_prayer_times/config_flow.py b/homeassistant/components/islamic_prayer_times/config_flow.py index d0d314fe67d..597d67c19f4 100644 --- a/homeassistant/components/islamic_prayer_times/config_flow.py +++ b/homeassistant/components/islamic_prayer_times/config_flow.py @@ -8,6 +8,11 @@ import voluptuous as vol from homeassistant import config_entries from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult +from homeassistant.helpers.selector import ( + SelectSelector, + SelectSelectorConfig, + SelectSelectorMode, +) from .const import CALC_METHODS, CONF_CALC_METHOD, DEFAULT_CALC_METHOD, DOMAIN, NAME @@ -58,7 +63,13 @@ class IslamicPrayerOptionsFlowHandler(config_entries.OptionsFlow): default=self.config_entry.options.get( CONF_CALC_METHOD, DEFAULT_CALC_METHOD ), - ): vol.In(CALC_METHODS) + ): SelectSelector( + SelectSelectorConfig( + options=CALC_METHODS, + mode=SelectSelectorMode.DROPDOWN, + translation_key=CONF_CALC_METHOD, + ) + ), } return self.async_show_form(step_id="init", data_schema=vol.Schema(options)) diff --git a/homeassistant/components/islamic_prayer_times/const.py b/homeassistant/components/islamic_prayer_times/const.py index 2a73a33bef8..67fac6c9261 100644 --- a/homeassistant/components/islamic_prayer_times/const.py +++ b/homeassistant/components/islamic_prayer_times/const.py @@ -1,12 +1,27 @@ """Constants for the Islamic Prayer component.""" from typing import Final -from prayer_times_calculator import PrayerTimesCalculator - DOMAIN: Final = "islamic_prayer_times" NAME: Final = "Islamic Prayer Times" CONF_CALC_METHOD: Final = "calculation_method" -CALC_METHODS: list[str] = list(PrayerTimesCalculator.CALCULATION_METHODS) +CALC_METHODS: Final = [ + "jafari", + "karachi", + "isna", + "mwl", + "makkah", + "egypt", + "tehran", + "gulf", + "kuwait", + "qatar", + "singapore", + "france", + "turkey", + "russia", + "moonsighting", + "custom", +] DEFAULT_CALC_METHOD: Final = "isna" diff --git a/homeassistant/components/islamic_prayer_times/strings.json b/homeassistant/components/islamic_prayer_times/strings.json index 7c09cc605bd..d02b26ec533 100644 --- a/homeassistant/components/islamic_prayer_times/strings.json +++ b/homeassistant/components/islamic_prayer_times/strings.json @@ -20,6 +20,28 @@ } } }, + "selector": { + "calculation_method": { + "options": { + "jafari": "Shia Ithna-Ansari", + "karachi": "University of Islamic Sciences, Karachi", + "isna": "Islamic Society of North America", + "mwl": "Muslim World League", + "makkah": "Umm Al-Qura University, Makkah", + "egypt": "Egyptian General Authority of Survey", + "tehran": "Institute of Geophysics, University of Tehran", + "gulf": "Gulf Region", + "kuwait": "Kuwait", + "qatar": "Qatar", + "singapore": "Majlis Ugama Islam Singapura, Singapore", + "france": "Union Organization islamic de France", + "turkey": "Diyanet İşleri Başkanlığı, Turkey", + "russia": "Spiritual Administration of Muslims of Russia", + "moonsighting": "Moonsighting Committee Worldwide", + "custom": "Custom" + } + } + }, "entity": { "sensor": { "fajr": {