[speaker] Use register_apply_condition for speaker.is_playing and speaker.is_stopped (#19562)

This commit is contained in:
J. Nick Koston
2026-09-24 09:10:09 -04:00
committed by GitHub
parent 2ce2b7b25c
commit cbd985826c
2 changed files with 6 additions and 27 deletions
+6 -17
View File
@@ -20,10 +20,6 @@ PlayAction = speaker_ns.class_(
)
IsPlayingCondition = speaker_ns.class_("IsPlayingCondition", automation.Condition)
IsStoppedCondition = speaker_ns.class_("IsStoppedCondition", automation.Condition)
async def setup_speaker_core_(var, config):
if audio_dac_config := config.get(CONF_AUDIO_DAC):
aud_dac = await cg.get_variable(audio_dac_config)
@@ -47,12 +43,6 @@ SPEAKER_AUTOMATION_SCHEMA = automation.maybe_simple_id(
)
async def speaker_action(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
await cg.register_parented(var, config[CONF_ID])
return var
@automation.register_action(
"speaker.play",
PlayAction,
@@ -91,13 +81,12 @@ for _name, _call in (
_name, SPEAKER_AUTOMATION_SCHEMA, automation.ApplyCall(_call)
)
automation.register_condition(
"speaker.is_playing", IsPlayingCondition, SPEAKER_AUTOMATION_SCHEMA
)(speaker_action)
automation.register_condition(
"speaker.is_stopped", IsStoppedCondition, SPEAKER_AUTOMATION_SCHEMA
)(speaker_action)
automation.register_apply_condition(
"speaker.is_playing", SPEAKER_AUTOMATION_SCHEMA, "is_running()"
)
automation.register_apply_condition(
"speaker.is_stopped", SPEAKER_AUTOMATION_SCHEMA, "is_stopped()"
)
automation.register_apply_action(
-10
View File
@@ -38,14 +38,4 @@ template<typename... Ts> class PlayAction final : public Action<Ts...>, public P
} data_;
};
template<typename... Ts> class IsPlayingCondition final : public Condition<Ts...>, public Parented<Speaker> {
public:
bool check(const Ts &...x) override { return this->parent_->is_running(); }
};
template<typename... Ts> class IsStoppedCondition final : public Condition<Ts...>, public Parented<Speaker> {
public:
bool check(const Ts &...x) override { return this->parent_->is_stopped(); }
};
} // namespace esphome::speaker