@@ -40,9 +40,47 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
4040 await async_setup_adhan_scheduler (hass , entry , coordinator )
4141 await async_update_services_yaml (hass )
4242 await async_setup_services (hass , entry )
43+ await async_ensure_helpers (hass )
4344 return True
4445
4546
47+ async def async_ensure_helpers (hass : HomeAssistant ):
48+ """Maak benodigde helper entities aan als ze nog niet bestaan."""
49+ entity_id = "input_boolean.nida_skip_suhoor"
50+ if hass .states .get (entity_id ) is None :
51+ try :
52+ await hass .services .async_call (
53+ "input_boolean" , "create" ,
54+ {"name" : "Nida Skip Suhoor" , "icon" : "mdi:sleep" },
55+ blocking = True ,
56+ )
57+ _LOGGER .info ("Helper aangemaakt: %s" , entity_id )
58+ except Exception as e :
59+ _LOGGER .warning (
60+ "Kon helper %s niet aanmaken: %s — maak hem handmatig aan via Instellingen → Hulpapparaten" ,
61+ entity_id , e
62+ )
63+
64+
65+ async def check_reset_skip_suhoor (hass : HomeAssistant , coordinator , now_ts : float ):
66+ """Reset input_boolean.nida_skip_suhoor na Fajr zodat volgende nacht suhoor weer actief is."""
67+ try :
68+ timings = coordinator .data ["data" ]["timings" ]
69+ today = datetime .now ().strftime ("%Y-%m-%d" )
70+ fajr_ts = datetime .strptime (f"{ today } { timings ['Fajr' ]} " , "%Y-%m-%d %H:%M" ).timestamp ()
71+ if abs (now_ts - fajr_ts ) < 30 :
72+ skip_state = hass .states .get ("input_boolean.nida_skip_suhoor" )
73+ if skip_state and skip_state .state == "on" :
74+ await hass .services .async_call (
75+ "input_boolean" , "turn_off" ,
76+ {"entity_id" : "input_boolean.nida_skip_suhoor" },
77+ blocking = True ,
78+ )
79+ _LOGGER .info ("input_boolean.nida_skip_suhoor gereset na Fajr" )
80+ except Exception as e :
81+ _LOGGER .debug ("Reset skip suhoor mislukt: %s" , e )
82+
83+
4684async def async_copy_sounds (hass : HomeAssistant ):
4785 """Kopieer sounds van integration naar /config/www/nida/sounds/ bij install/update."""
4886
@@ -124,6 +162,7 @@ def check_prayer_time(now):
124162 hass .async_create_task (check_tarhim (hass , entry , coordinator , now_ts ))
125163 hass .async_create_task (check_suhoor (hass , entry , coordinator , now_ts ))
126164 hass .async_create_task (check_reminders (hass , entry , coordinator , now_ts , prayers ))
165+ hass .async_create_task (check_reset_skip_suhoor (hass , coordinator , now_ts ))
127166
128167 entry .async_on_unload (
129168 async_track_time_change (hass , check_prayer_time , second = 0 )
@@ -451,6 +490,26 @@ async def check_reminders(hass, entry, coordinator, now_ts, prayers):
451490 continue
452491 reminder_ts = prayer_ts - (minutes * 60 )
453492 if abs (now_ts - reminder_ts ) < 30 :
493+ # Sla Fajr reminder over als tarhim actief is tijdens Ramadan
494+ if prayer_name .lower () in ("fajr" , "jumat" ) and options .get (CONF_TARHIM_ENABLED , True ):
495+ try :
496+ hijri_month = coordinator .data ["data" ]["date" ]["hijri" ]["month" ]["en" ]
497+ if "Rama" in hijri_month :
498+ tarhim_sound = options .get (CONF_TARHIM_SOUND , "" )
499+ if tarhim_sound :
500+ sounds_path = hass .config .path ("www/nida/sounds" )
501+ mp3_path = os .path .join (sounds_path , tarhim_sound )
502+ duration = await hass .async_add_executor_job (_get_mp3_duration , mp3_path )
503+ tarhim_start_ts = prayer_ts - duration - 5
504+ if reminder_ts >= tarhim_start_ts - 30 :
505+ _LOGGER .info (
506+ "Reminder %d voor Fajr overgeslagen — tarhim window actief" ,
507+ r_num
508+ )
509+ continue
510+ except Exception as e :
511+ _LOGGER .debug ("Tarhim window check mislukt: %s" , e )
512+
454513 _LOGGER .info ("Reminder %d for %s in %d min" , r_num , prayer_name , minutes )
455514
456515 if sound :
@@ -507,6 +566,12 @@ async def check_tarhim(hass: HomeAssistant, entry: ConfigEntry, coordinator, now
507566 if not options .get (CONF_TARHIM_ENABLED , True ):
508567 return
509568
569+ # Sla tarhim over als suhoor geskipt is via de card
570+ skip_state = hass .states .get ("input_boolean.nida_skip_suhoor" )
571+ if skip_state and skip_state .state == "on" :
572+ _LOGGER .info ("Tarhim overgeslagen — input_boolean.nida_skip_suhoor is aan" )
573+ return
574+
510575 try :
511576 hijri_month = coordinator .data ["data" ]["date" ]["hijri" ]["month" ]["en" ]
512577 if "Rama" not in hijri_month :
@@ -536,7 +601,7 @@ async def check_tarhim(hass: HomeAssistant, entry: ConfigEntry, coordinator, now
536601 )
537602 return
538603
539- BUFFER_SECONDS = 5
604+ BUFFER_SECONDS = 10
540605 tarhim_ts = fajr_ts - duration - BUFFER_SECONDS
541606
542607 _LOGGER .debug (
@@ -545,6 +610,15 @@ async def check_tarhim(hass: HomeAssistant, entry: ConfigEntry, coordinator, now
545610 datetime .fromtimestamp (tarhim_ts ).strftime ("%H:%M:%S" ),
546611 )
547612
613+ # Sla tarhim tijd op als sensor zodat de card hem kan tonen
614+ tarhim_dt = datetime .fromtimestamp (tarhim_ts )
615+ tarhim_readable = tarhim_dt .strftime ("%H:%M" )
616+ hass .states .async_set (
617+ "sensor.nida_tarhim_readable" ,
618+ tarhim_readable ,
619+ {"friendly_name" : "Nida Tarhim Time" , "icon" : "mdi:music" },
620+ )
621+
548622 if abs (now_ts - tarhim_ts ) < 30 :
549623 speaker = options .get (CONF_TARHIM_SPEAKER , ["media_player.adhan_speakers" ])
550624 if isinstance (speaker , str ):
@@ -579,6 +653,12 @@ async def check_suhoor(hass: HomeAssistant, entry: ConfigEntry, coordinator, now
579653 if not options .get ("suhoor_enabled" , True ):
580654 return
581655
656+ # Sla suhoor over als geskipt via de card (input_boolean.nida_skip_suhoor)
657+ skip_state = hass .states .get ("input_boolean.nida_skip_suhoor" )
658+ if skip_state and skip_state .state == "on" :
659+ _LOGGER .info ("Suhoor overgeslagen — input_boolean.nida_skip_suhoor is aan" )
660+ return
661+
582662 try :
583663 hijri_month = coordinator .data ["data" ]["date" ]["hijri" ]["month" ]["en" ]
584664 if "Rama" not in hijri_month :
0 commit comments