mirror of
https://github.com/esphome/esphome.git
synced 2024-11-08 09:40:53 +01:00
Add 'voice_assistant.connected' condition (#5845)
This commit is contained in:
parent
ff97639f79
commit
687f5ca633
@ -57,6 +57,9 @@ StopAction = voice_assistant_ns.class_(
|
||||
IsRunningCondition = voice_assistant_ns.class_(
|
||||
"IsRunningCondition", automation.Condition, cg.Parented.template(VoiceAssistant)
|
||||
)
|
||||
ConnectedCondition = voice_assistant_ns.class_(
|
||||
"ConnectedCondition", automation.Condition, cg.Parented.template(VoiceAssistant)
|
||||
)
|
||||
|
||||
|
||||
def tts_stream_validate(config):
|
||||
@ -298,3 +301,12 @@ async def voice_assistant_is_running_to_code(config, condition_id, template_arg,
|
||||
var = cg.new_Pvariable(condition_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@register_condition(
|
||||
"voice_assistant.connected", ConnectedCondition, VOICE_ASSISTANT_ACTION_SCHEMA
|
||||
)
|
||||
async def voice_assistant_connected_to_code(config, condition_id, template_arg, args):
|
||||
var = cg.new_Pvariable(condition_id, template_arg)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
@ -222,6 +222,11 @@ template<typename... Ts> class IsRunningCondition : public Condition<Ts...>, pub
|
||||
bool check(Ts... x) override { return this->parent_->is_running() || this->parent_->is_continuous(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class ConnectedCondition : public Condition<Ts...>, public Parented<VoiceAssistant> {
|
||||
public:
|
||||
bool check(Ts... x) override { return this->parent_->get_api_connection() != nullptr; }
|
||||
};
|
||||
|
||||
extern VoiceAssistant *global_voice_assistant; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
} // namespace voice_assistant
|
||||
|
Loading…
Reference in New Issue
Block a user