Skip to content

Commit

Permalink
- Moved audio pause/resume transition duration to constant
Browse files Browse the repository at this point in the history
- Comment cleanup
  • Loading branch information
nimroddolev committed Feb 20, 2024
1 parent f3d0623 commit 163c822
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions custom_components/chime_tts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
LOCAL_PATH_KEY,
PUBLIC_PATH_KEY,
AUDIO_DURATION_KEY,
FADE_TRANSITION_S,
ROOT_PATH_KEY,
DEFAULT_TEMP_CHIMES_PATH_KEY,
TEMP_CHIMES_PATH_KEY,
Expand Down Expand Up @@ -346,7 +347,7 @@ async def async_post_playback_actions(
entity_id,
initial_volume_level,
(0 if should_fade_in else volume_level),
(1.5 if should_fade_in else 0)
(FADE_TRANSITION_S if should_fade_in else 0)
)

# Unjoin entity_ids
Expand Down Expand Up @@ -987,6 +988,8 @@ async def async_set_volume_level(
fade_duration_s: float = 0
):
"""Set the volume_level for a given media player entity."""
if target_volume_level == -1:
return
target_volume_level = max(float(target_volume_level), 0)
current_volume_level = max(float(current_volume_level), 0)

Expand Down Expand Up @@ -1084,7 +1087,7 @@ async def async_play_media(
_LOGGER.debug(" - Fading out playback on %s...", entity_id)
initial_volume_level = media_player_dict["initial_volume_level"]
if await async_set_volume_level(
hass, entity_id, 0, initial_volume_level, 1.5
hass, entity_id, 0, initial_volume_level, FADE_TRANSITION_S
):
# Wait until volume level updated
await helpers.async_wait_until_media_player_volume_level(hass, entity_id, 0)
Expand Down
1 change: 1 addition & 0 deletions custom_components/chime_tts/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
SERVICE_SAY_URL = "say_url"
SERVICE_CLEAR_CACHE = "clear_cache"
DEFAULT_DELAY_MS = 450
FADE_TRANSITION_S = 1.5
DATA_STORAGE_KEY = "chime_tts_integration_data"
AUDIO_PATH_KEY = "audio_path" # <-- Deprecated
LOCAL_PATH_KEY = "local_path"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/chime_tts/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ async def async_wait_until_media_player_state(self, hass: HomeAssistant, entity_
media_player_state = hass.states.get(entity_id).state
if media_player_state == target_state:
return True
_LOGGER.debug(" - Waiting until %s is = %s...", entity_id, target_state)
_LOGGER.debug(" - Waiting until %s is %s...", entity_id, target_state)
delay = 0.2
while media_player_state != target_state and timeout > 0:
await hass.async_add_executor_job(self.sleep, delay)
Expand All @@ -761,7 +761,7 @@ async def async_wait_until_media_player_volume_level(self, hass: HomeAssistant,
volume = hass.states.get(entity_id).attributes.get(ATTR_MEDIA_VOLUME_LEVEL, -1)
if volume == target_volume:
return True
_LOGGER.debug(" - Waiting until %s's volume_level is = %s...", entity_id, str(target_volume))
_LOGGER.debug(" - Waiting until %s's volume_level = %s...", entity_id, str(target_volume))
delay = 0.2
while volume != target_volume and timeout > 0:
await hass.async_add_executor_job(self.sleep, delay)
Expand Down

0 comments on commit 163c822

Please sign in to comment.