ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::speaker::AnnouncementVolume Class Reference

Tracks a separate volume for announcements that start while nothing else is playing. More...

#include <announcement_volume.h>

Public Member Functions

template<typename F >
void set_volume (float volume, F &&apply)
 Stores a new announcement volume and applies it right away if it is in use.
 
float get_volume () const
 
bool is_configured () const
 
bool is_active () const
 
template<typename F >
void begin (bool other_audio_playing, F &&apply)
 Called when an announcement starts.
 
template<typename F >
void end (float media_volume, F &&apply)
 Switches back to the media player volume if the announcement volume is in use.
 
void cancel ()
 The media player volume was set and already sent to the speakers; it applies until the next announcement.
 
template<typename F >
void item_started (bool is_announcement, bool other_audio_playing, float media_volume, F &&apply)
 Called when an item starts on a playlist that holds announcements, and may hold media too.
 
template<typename F >
void playlist_finished (float media_volume, F &&apply)
 Called when the playlist that holds announcements has finished. Switches back to the media volume.
 

Protected Member Functions

void log_begin_ () const
 
void log_end_ (float media_volume) const
 

Protected Attributes

float volume_ {NAN}
 
bool active_ {false}
 
bool last_item_announcement_ {false}
 

Detailed Description

Tracks a separate volume for announcements that start while nothing else is playing.

The methods that change the volume take apply, called with the volume the speakers must switch to.

Definition at line 10 of file announcement_volume.h.

Member Function Documentation

◆ begin()

template<typename F >
void esphome::speaker::AnnouncementVolume::begin ( bool other_audio_playing,
F && apply )
inline

Called when an announcement starts.

Switches to the announcement volume unless other audio is playing.

Parameters
other_audio_playingMedia, or an announcement that does not use the announcement volume, is playing

Definition at line 25 of file announcement_volume.h.

◆ cancel()

void esphome::speaker::AnnouncementVolume::cancel ( )
inline

The media player volume was set and already sent to the speakers; it applies until the next announcement.

Definition at line 45 of file announcement_volume.h.

◆ end()

template<typename F >
void esphome::speaker::AnnouncementVolume::end ( float media_volume,
F && apply )
inline

Switches back to the media player volume if the announcement volume is in use.

Definition at line 35 of file announcement_volume.h.

◆ get_volume()

float esphome::speaker::AnnouncementVolume::get_volume ( ) const
inline

Definition at line 19 of file announcement_volume.h.

◆ is_active()

bool esphome::speaker::AnnouncementVolume::is_active ( ) const
inline

Definition at line 21 of file announcement_volume.h.

◆ is_configured()

bool esphome::speaker::AnnouncementVolume::is_configured ( ) const
inline

Definition at line 20 of file announcement_volume.h.

◆ item_started()

template<typename F >
void esphome::speaker::AnnouncementVolume::item_started ( bool is_announcement,
bool other_audio_playing,
float media_volume,
F && apply )
inline

Called when an item starts on a playlist that holds announcements, and may hold media too.

Media switches back to the media volume. An announcement that follows media, or starts the playlist, switches to the announcement volume unless other audio is playing. One that follows another announcement keeps the volume that one used, including a volume change made while it played.

Definition at line 52 of file announcement_volume.h.

◆ log_begin_()

void esphome::speaker::AnnouncementVolume::log_begin_ ( ) const
protected

Definition at line 9 of file announcement_volume.cpp.

◆ log_end_()

void esphome::speaker::AnnouncementVolume::log_end_ ( float media_volume) const
protected

Definition at line 11 of file announcement_volume.cpp.

◆ playlist_finished()

template<typename F >
void esphome::speaker::AnnouncementVolume::playlist_finished ( float media_volume,
F && apply )
inline

Called when the playlist that holds announcements has finished. Switches back to the media volume.

Definition at line 62 of file announcement_volume.h.

◆ set_volume()

template<typename F >
void esphome::speaker::AnnouncementVolume::set_volume ( float volume,
F && apply )
inline

Stores a new announcement volume and applies it right away if it is in use.

Definition at line 13 of file announcement_volume.h.

Field Documentation

◆ active_

bool esphome::speaker::AnnouncementVolume::active_ {false}
protected

Definition at line 72 of file announcement_volume.h.

◆ last_item_announcement_

bool esphome::speaker::AnnouncementVolume::last_item_announcement_ {false}
protected

Definition at line 73 of file announcement_volume.h.

◆ volume_

float esphome::speaker::AnnouncementVolume::volume_ {NAN}
protected

Definition at line 71 of file announcement_volume.h.


The documentation for this class was generated from the following files: