mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-30 09:48:27 +02:00
b60c08dd28
* Add push to talk voice assistant * Refactor most code into voice_assistant * Make voice_assistant the component and remove push_to_talk (can be done in yaml) * Fix component setup * Always AF_INET to match serverside * Fix microphone and media player co-existence * Format * Update codeowners * Update test file * Fix endifs * nullptr not NULL * clang-tidy * Format * fixup: Add VA event data * Generate proto * Parse and log events * Add default to switch * Fix * Add mic/va to test5
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
import esphome.config_validation as cv
|
|
import esphome.codegen as cg
|
|
|
|
from esphome.const import CONF_ID, CONF_MICROPHONE
|
|
from esphome import automation
|
|
from esphome.automation import register_action
|
|
from esphome.components import microphone
|
|
|
|
AUTO_LOAD = ["socket"]
|
|
DEPENDENCIES = ["api", "microphone"]
|
|
|
|
CODEOWNERS = ["@jesserockz"]
|
|
|
|
voice_assistant_ns = cg.esphome_ns.namespace("voice_assistant")
|
|
VoiceAssistant = voice_assistant_ns.class_("VoiceAssistant", cg.Component)
|
|
|
|
StartAction = voice_assistant_ns.class_(
|
|
"StartAction", automation.Action, cg.Parented.template(VoiceAssistant)
|
|
)
|
|
StopAction = voice_assistant_ns.class_(
|
|
"StopAction", automation.Action, cg.Parented.template(VoiceAssistant)
|
|
)
|
|
|
|
|
|
CONFIG_SCHEMA = cv.Schema(
|
|
{
|
|
cv.GenerateID(): cv.declare_id(VoiceAssistant),
|
|
cv.GenerateID(CONF_MICROPHONE): cv.use_id(microphone.Microphone),
|
|
}
|
|
).extend(cv.COMPONENT_SCHEMA)
|
|
|
|
|
|
async def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
await cg.register_component(var, config)
|
|
|
|
mic = await cg.get_variable(config[CONF_MICROPHONE])
|
|
cg.add(var.set_microphone(mic))
|
|
|
|
cg.add_define("USE_VOICE_ASSISTANT")
|
|
|
|
|
|
VOICE_ASSISTANT_ACTION_SCHEMA = cv.Schema({cv.GenerateID(): cv.use_id(VoiceAssistant)})
|
|
|
|
|
|
@register_action("voice_assistant.start", StartAction, VOICE_ASSISTANT_ACTION_SCHEMA)
|
|
async def voice_assistant_listen_to_code(config, action_id, template_arg, args):
|
|
var = cg.new_Pvariable(action_id, template_arg)
|
|
await cg.register_parented(var, config[CONF_ID])
|
|
return var
|
|
|
|
|
|
@register_action("voice_assistant.stop", StopAction, VOICE_ASSISTANT_ACTION_SCHEMA)
|
|
async def voice_assistant_stop_to_code(config, action_id, template_arg, args):
|
|
var = cg.new_Pvariable(action_id, template_arg)
|
|
await cg.register_parented(var, config[CONF_ID])
|
|
return var
|