Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential Volume Fixes and on_pause condition #18

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions esphome/components/media_player/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"AnnouncementTrigger", automation.Trigger.template()
)
IsIdleCondition = media_player_ns.class_("IsIdleCondition", automation.Condition)
IsPausedCondition = media_player_ns.class_("IsPausedCondition", automation.Condition)
IsPlayingCondition = media_player_ns.class_("IsPlayingCondition", automation.Condition)


Expand Down Expand Up @@ -193,6 +194,9 @@ async def media_player_play_media_action(config, action_id, template_arg, args):
@automation.register_condition(
"media_player.is_idle", IsIdleCondition, MEDIA_PLAYER_ACTION_SCHEMA
)
@automation.register_condition(
"media_player.is_paused", IsPausedCondition, MEDIA_PLAYER_ACTION_SCHEMA
)
@automation.register_condition(
"media_player.is_playing", IsPlayingCondition, MEDIA_PLAYER_ACTION_SCHEMA
)
Expand Down
5 changes: 5 additions & 0 deletions esphome/components/media_player/automation.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ template<typename... Ts> class IsPlayingCondition : public Condition<Ts...>, pub
bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_PLAYING; }
};

template<typename... Ts> class IsPausedCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
public:
bool check(Ts... x) override { return this->parent_->state == MediaPlayerState::MEDIA_PLAYER_STATE_PAUSED; }
};

} // namespace media_player
} // namespace esphome
4 changes: 4 additions & 0 deletions esphome/components/media_player/media_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const char *media_player_command_to_string(MediaPlayerCommand command) {
return "UNMUTE";
case MEDIA_PLAYER_COMMAND_TOGGLE:
return "TOGGLE";
case MEDIA_PLAYER_COMMAND_VOLUME_UP:
return "VOLUME_UP";
case MEDIA_PLAYER_COMMAND_VOLUME_DOWN:
return "VOLUME_DOWN";
default:
return "UNKNOWN";
}
Expand Down
8 changes: 6 additions & 2 deletions esphome/components/nabu/nabu_media_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,17 @@ void NabuMediaPlayer::control(const media_player::MediaPlayerCall &call) {

if (call.get_volume().has_value()) {
media_command.volume = call.get_volume().value();
xQueueSend(this->media_control_command_queue_, &media_command, portMAX_DELAY);
xQueueSend(this->media_control_command_queue_, &media_command, 0); // Wait 0 ticks for queue to be free, volume sets aren't that important!
return;
}

if (call.get_command().has_value()) {
media_command.command = call.get_command().value();
xQueueSend(this->media_control_command_queue_, &media_command, portMAX_DELAY);
TickType_t ticks_to_wait = portMAX_DELAY;
if ((call.get_command().value() == media_player::MEDIA_PLAYER_COMMAND_VOLUME_UP) || (call.get_command().value() == media_player::MEDIA_PLAYER_COMMAND_VOLUME_DOWN)) {
ticks_to_wait = 0; // Wait 0 ticks for queue to be free, volume sets aren't that important!
}
xQueueSend(this->media_control_command_queue_, &media_command, ticks_to_wait);
return;
}
}
Expand Down