Add 'voice_assistant.connected' condition (#5845)

This commit is contained in:
Jesse Hills 2023-11-28 09:57:40 +13:00 committed by GitHub
parent f63f722afb
commit 3b77f05cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -57,6 +57,9 @@ StopAction = voice_assistant_ns.class_(
IsRunningCondition = voice_assistant_ns.class_( IsRunningCondition = voice_assistant_ns.class_(
"IsRunningCondition", automation.Condition, cg.Parented.template(VoiceAssistant) "IsRunningCondition", automation.Condition, cg.Parented.template(VoiceAssistant)
) )
ConnectedCondition = voice_assistant_ns.class_(
"ConnectedCondition", automation.Condition, cg.Parented.template(VoiceAssistant)
)
def tts_stream_validate(config): 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) var = cg.new_Pvariable(condition_id, template_arg)
await cg.register_parented(var, config[CONF_ID]) await cg.register_parented(var, config[CONF_ID])
return var 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

View File

@ -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(); } 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) extern VoiceAssistant *global_voice_assistant; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace voice_assistant } // namespace voice_assistant