Skip to content

Commit

Permalink
add is_paused condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kahrendt committed Jul 24, 2024
1 parent 4073df3 commit 8aa87c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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

0 comments on commit 8aa87c5

Please sign in to comment.