Skip to content

Commit f0f329d

Browse files
JohannJohann
authored andcommitted
feat: open sensor volume + multilingual services
1 parent c3b651a commit f0f329d

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
22
**/.DS_Store
3+
**/.DS_Store

custom_components/nida/__init__.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,12 @@ async def _get_media_url(hass, local_path: str) -> str:
147147
return f"{base_url}{local_path}"
148148

149149

150-
def _get_volume(options, base_vol_key, base_default):
151-
"""Geef het juiste volume terug op basis van dag/nacht instelling."""
150+
def _get_volume(options, base_vol_key, base_default, hass=None):
151+
"""Geef het juiste volume terug op basis van dag/nacht en open ramen/deuren."""
152152
raw = options.get(base_vol_key, base_default)
153153
volume = raw / 100 if raw > 1 else raw
154154

155+
# Nacht volume
155156
night_enabled = options.get("night_volume_enabled", False)
156157
if night_enabled:
157158
night_start = int(options.get("night_start_hour", 22))
@@ -160,6 +161,17 @@ def _get_volume(options, base_vol_key, base_default):
160161
raw_night = options.get("night_volume", 10)
161162
volume = raw_night / 100 if raw_night > 1 else raw_night
162163

164+
# Open ramen/deuren volume
165+
open_sensor_enabled = options.get("open_sensor_enabled", False)
166+
if open_sensor_enabled and hass is not None:
167+
sensor = options.get("open_sensor_entity", "")
168+
if sensor:
169+
state = hass.states.get(sensor)
170+
if state and state.state == "on":
171+
raw_open = options.get("open_sensor_volume", 5)
172+
volume = raw_open / 100 if raw_open > 1 else raw_open
173+
_LOGGER.debug(f"Open sensor active, using reduced volume: {volume}")
174+
163175
return volume
164176

165177

@@ -170,17 +182,17 @@ async def play_adhan(hass: HomeAssistant, entry: ConfigEntry, prayer_type: str):
170182
if prayer_type == "fajr":
171183
speaker = options.get(CONF_FAJR_SPEAKER, ["media_player.adhan_speakers"])
172184
if isinstance(speaker, str): speaker = [speaker]
173-
volume = _get_volume(options, CONF_FAJR_VOLUME, 10)
185+
volume = _get_volume(options, CONF_FAJR_VOLUME, 10, hass)
174186
sound = options.get(CONF_FAJR_SOUND, "01-adhan-fajr.mp3")
175187
elif prayer_type == "jumat":
176188
speaker = options.get("jumat_speaker", options.get(CONF_DAY_SPEAKER, ["media_player.adhan_speakers"]))
177189
if isinstance(speaker, str): speaker = [speaker]
178-
volume = _get_volume(options, "jumat_volume", options.get(CONF_DAY_VOLUME, 50))
190+
volume = _get_volume(options, "jumat_volume", options.get(CONF_DAY_VOLUME, 50), hass)
179191
sound = options.get("jumat_sound", options.get(CONF_DAY_SOUND, "01-adhan.mp3"))
180192
else:
181193
speaker = options.get(CONF_DAY_SPEAKER, ["media_player.adhan_speakers"])
182194
if isinstance(speaker, str): speaker = [speaker]
183-
volume = _get_volume(options, CONF_DAY_VOLUME, 50)
195+
volume = _get_volume(options, CONF_DAY_VOLUME, 50, hass)
184196
sound = options.get(CONF_DAY_SOUND, "01-adhan.mp3")
185197

186198
play_method = options.get(CONF_PLAY_METHOD, "media_player")
@@ -246,7 +258,7 @@ async def check_reminders(hass, entry, coordinator, now_ts, prayers):
246258
lang = options.get(f"reminder_{r_num}_lang", "nl")
247259
speaker = options.get(CONF_DAY_SPEAKER, ["media_player.adhan_speakers"])
248260
if isinstance(speaker, str): speaker = [speaker]
249-
volume = _get_volume(options, CONF_DAY_VOLUME, 50)
261+
volume = _get_volume(options, CONF_DAY_VOLUME, 50, hass)
250262

251263
for prayer_name, time_str in prayers.items():
252264
today = datetime.now().strftime("%Y-%m-%d")
@@ -320,7 +332,7 @@ async def check_tarhim(hass: HomeAssistant, entry: ConfigEntry, coordinator, now
320332
if abs(now_ts - tarhim_ts) < 30:
321333
speaker = options.get(CONF_TARHIM_SPEAKER, ["media_player.adhan_speakers"])
322334
if isinstance(speaker, str): speaker = [speaker]
323-
volume = _get_volume(options, CONF_TARHIM_VOLUME, 10)
335+
volume = _get_volume(options, CONF_TARHIM_VOLUME, 10, hass)
324336
sound = options.get(CONF_TARHIM_SOUND, "01-tarhim.mp3")
325337
media_path = await _get_media_url(hass, f"/local/nida/sounds/{sound}")
326338

@@ -409,7 +421,7 @@ async def handle_test_reminder(call):
409421
text = text.replace("[minutes]", str(int(minutes))).replace("[prayer]", prayer)
410422
speaker = options.get(CONF_DAY_SPEAKER, ["media_player.adhan_speakers"])
411423
if isinstance(speaker, str): speaker = [speaker]
412-
volume = _get_volume(options, CONF_DAY_VOLUME, 50)
424+
volume = _get_volume(options, CONF_DAY_VOLUME, 50, hass)
413425

414426
if sound:
415427
media_path = await _get_media_url(hass, f"/local/nida/sounds/{sound}")

custom_components/nida/config_flow.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ async def async_step_adhan(self, user_input=None):
144144
vol.Optional("night_volume_enabled", default=False): bool,
145145
vol.Optional("night_volume", default=10): _volume_sel(),
146146
vol.Optional("night_start_hour", default=22): selector.selector({"number": {"min": 18, "max": 23, "step": 1, "unit_of_measurement": "h", "mode": "slider"}}),
147+
vol.Optional("open_sensor_enabled", default=False): bool,
148+
vol.Optional("open_sensor_entity", default=""): selector.selector({"entity": {"domain": ["binary_sensor", "group"], "multiple": False}}),
149+
vol.Optional("open_sensor_volume", default=5): _volume_sel(),
147150
}),
148151
)
149152

@@ -267,6 +270,9 @@ async def async_step_adhan(self, user_input=None):
267270
vol.Optional("night_volume_enabled", default=self._get("night_volume_enabled", False)): bool,
268271
vol.Optional("night_volume", default=self._get_vol("night_volume", 20)): _volume_sel(),
269272
vol.Optional("night_start_hour", default=self._get("night_start_hour", 22)): selector.selector({"number": {"min": 18, "max": 23, "step": 1, "unit_of_measurement": "h", "mode": "slider"}}),
273+
vol.Optional("open_sensor_enabled", default=self._get("open_sensor_enabled", False)): bool,
274+
vol.Optional("open_sensor_entity", default=self._get("open_sensor_entity", "")): selector.selector({"entity": {"domain": ["binary_sensor", "group"], "multiple": False}}),
275+
vol.Optional("open_sensor_volume", default=self._get_vol("open_sensor_volume", 5)): _volume_sel(),
270276
}),
271277
)
272278

nida.zip

1.51 KB
Binary file not shown.

0 commit comments

Comments
 (0)