Fix Islamic prayer times naming (#34784)

This commit is contained in:
Rami Mosleh 2020-04-29 14:38:20 +03:00 committed by GitHub
parent 24fd395d09
commit 6e0d61e5e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 27 deletions

View File

@ -1,12 +1,19 @@
"""Constants for the Islamic Prayer component.""" """Constants for the Islamic Prayer component."""
DOMAIN = "islamic_prayer_times" DOMAIN = "islamic_prayer_times"
NAME = "Islamic Prayer Times" NAME = "Islamic Prayer Times"
SENSOR_SUFFIX = "Prayer"
PRAYER_TIMES_ICON = "mdi:calendar-clock" PRAYER_TIMES_ICON = "mdi:calendar-clock"
SENSOR_TYPES = ["Fajr", "Sunrise", "Dhuhr", "Asr", "Maghrib", "Isha", "Midnight"] SENSOR_TYPES = {
"Fajr": "prayer",
"Sunrise": "time",
"Dhuhr": "prayer",
"Asr": "prayer",
"Maghrib": "prayer",
"Isha": "prayer",
"Midnight": "time",
}
CONF_CALC_METHOD = "calc_method" CONF_CALC_METHOD = "calculation_method"
CALC_METHODS = ["isna", "karachi", "mwl", "makkah"] CALC_METHODS = ["isna", "karachi", "mwl", "makkah"]
DEFAULT_CALC_METHOD = "isna" DEFAULT_CALC_METHOD = "isna"

View File

@ -5,7 +5,7 @@ from homeassistant.const import DEVICE_CLASS_TIMESTAMP
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from .const import DATA_UPDATED, DOMAIN, PRAYER_TIMES_ICON, SENSOR_SUFFIX, SENSOR_TYPES from .const import DATA_UPDATED, DOMAIN, PRAYER_TIMES_ICON, SENSOR_TYPES
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -33,7 +33,7 @@ class IslamicPrayerTimeSensor(Entity):
@property @property
def name(self): def name(self):
"""Return the name of the sensor.""" """Return the name of the sensor."""
return f"{self.sensor_type} {SENSOR_SUFFIX}" return f"{self.sensor_type} {SENSOR_TYPES[self.sensor_type]}"
@property @property
def unique_id(self): def unique_id(self):

View File

@ -15,7 +15,7 @@
"step": { "step": {
"init": { "init": {
"data": { "data": {
"calc_method": "Prayer calculation method" "calculation_method": "Prayer calculation method"
} }
} }
} }

View File

@ -14,7 +14,7 @@
"step": { "step": {
"init": { "init": {
"data": { "data": {
"calc_method": "Prayer calculation method" "calculation_method": "Prayer calculation method"
} }
} }
} }

View File

@ -23,6 +23,8 @@ async def test_islamic_prayer_times_sensors(hass):
for prayer in PRAYER_TIMES: for prayer in PRAYER_TIMES:
assert ( assert (
hass.states.get(f"sensor.{prayer}_prayer").state hass.states.get(
f"sensor.{prayer}_{islamic_prayer_times.const.SENSOR_TYPES[prayer]}"
).state
== PRAYER_TIMES_TIMESTAMPS[prayer].isoformat() == PRAYER_TIMES_TIMESTAMPS[prayer].isoformat()
) )