From 9f4c7739636bbb4d9d66c92d1b5b5c6511ea1d72 Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Wed, 18 Mar 2026 17:34:16 -0500 Subject: [PATCH] [media_source] Add request helpers for smart sources (#14936) --- .../components/media_source/media_source.h | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/esphome/components/media_source/media_source.h b/esphome/components/media_source/media_source.h index f21ba486b..ec2fcbc44 100644 --- a/esphome/components/media_source/media_source.h +++ b/esphome/components/media_source/media_source.h @@ -153,6 +153,31 @@ class MediaSource { } } + // === Listener request helpers for smart sources === + // Smart sources (those with internal playlists or external control) use these to request + // the orchestrator to take actions. Simple sources never call these. + + /// @brief Request the orchestrator to play a new URI + void request_play_uri_(const std::string &uri) { + if (this->listener_ != nullptr) { + this->listener_->request_play_uri(uri); + } + } + + /// @brief Request the orchestrator to change volume + void request_volume_(float volume) { + if (this->listener_ != nullptr) { + this->listener_->request_volume(volume); + } + } + + /// @brief Request the orchestrator to change mute state + void request_mute_(bool is_muted) { + if (this->listener_ != nullptr) { + this->listener_->request_mute(is_muted); + } + } + private: // Private to enforce the invariant that listener notifications always fire on state changes. // All state transitions must go through set_state_() which couples the update with notification.