mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 17:27:59 +01:00
Merge branch 'dev' into hbridge-switch
This commit is contained in:
commit
69c5c7ccb0
15 changed files with 218 additions and 31 deletions
|
@ -1553,6 +1553,23 @@ message VoiceAssistantTimerEventResponse {
|
|||
bool is_active = 6;
|
||||
}
|
||||
|
||||
message VoiceAssistantAnnounceRequest {
|
||||
option (id) = 119;
|
||||
option (source) = SOURCE_CLIENT;
|
||||
option (ifdef) = "USE_VOICE_ASSISTANT";
|
||||
|
||||
string media_id = 1;
|
||||
string text = 2;
|
||||
}
|
||||
|
||||
message VoiceAssistantAnnounceFinished {
|
||||
option (id) = 120;
|
||||
option (source) = SOURCE_SERVER;
|
||||
option (ifdef) = "USE_VOICE_ASSISTANT";
|
||||
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
// ==================== ALARM CONTROL PANEL ====================
|
||||
enum AlarmControlPanelState {
|
||||
ALARM_STATE_DISARMED = 0;
|
||||
|
|
|
@ -1213,6 +1213,16 @@ void APIConnection::on_voice_assistant_timer_event_response(const VoiceAssistant
|
|||
}
|
||||
};
|
||||
|
||||
void APIConnection::on_voice_assistant_announce_request(const VoiceAssistantAnnounceRequest &msg) {
|
||||
if (voice_assistant::global_voice_assistant != nullptr) {
|
||||
if (voice_assistant::global_voice_assistant->get_api_connection() != this) {
|
||||
return;
|
||||
}
|
||||
|
||||
voice_assistant::global_voice_assistant->on_announce(msg);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
|
|
|
@ -151,6 +151,7 @@ class APIConnection : public APIServerConnection {
|
|||
void on_voice_assistant_event_response(const VoiceAssistantEventResponse &msg) override;
|
||||
void on_voice_assistant_audio(const VoiceAssistantAudio &msg) override;
|
||||
void on_voice_assistant_timer_event_response(const VoiceAssistantTimerEventResponse &msg) override;
|
||||
void on_voice_assistant_announce_request(const VoiceAssistantAnnounceRequest &msg) override;
|
||||
#endif
|
||||
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
|
|
|
@ -7061,6 +7061,59 @@ void VoiceAssistantTimerEventResponse::dump_to(std::string &out) const {
|
|||
out.append("}");
|
||||
}
|
||||
#endif
|
||||
bool VoiceAssistantAnnounceRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) {
|
||||
switch (field_id) {
|
||||
case 1: {
|
||||
this->media_id = value.as_string();
|
||||
return true;
|
||||
}
|
||||
case 2: {
|
||||
this->text = value.as_string();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void VoiceAssistantAnnounceRequest::encode(ProtoWriteBuffer buffer) const {
|
||||
buffer.encode_string(1, this->media_id);
|
||||
buffer.encode_string(2, this->text);
|
||||
}
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
void VoiceAssistantAnnounceRequest::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("VoiceAssistantAnnounceRequest {\n");
|
||||
out.append(" media_id: ");
|
||||
out.append("'").append(this->media_id).append("'");
|
||||
out.append("\n");
|
||||
|
||||
out.append(" text: ");
|
||||
out.append("'").append(this->text).append("'");
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
}
|
||||
#endif
|
||||
bool VoiceAssistantAnnounceFinished::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||
switch (field_id) {
|
||||
case 1: {
|
||||
this->success = value.as_bool();
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void VoiceAssistantAnnounceFinished::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->success); }
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
void VoiceAssistantAnnounceFinished::dump_to(std::string &out) const {
|
||||
__attribute__((unused)) char buffer[64];
|
||||
out.append("VoiceAssistantAnnounceFinished {\n");
|
||||
out.append(" success: ");
|
||||
out.append(YESNO(this->success));
|
||||
out.append("\n");
|
||||
out.append("}");
|
||||
}
|
||||
#endif
|
||||
bool ListEntitiesAlarmControlPanelResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||
switch (field_id) {
|
||||
case 6: {
|
||||
|
|
|
@ -1825,6 +1825,29 @@ class VoiceAssistantTimerEventResponse : public ProtoMessage {
|
|||
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||
};
|
||||
class VoiceAssistantAnnounceRequest : public ProtoMessage {
|
||||
public:
|
||||
std::string media_id{};
|
||||
std::string text{};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
void dump_to(std::string &out) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||
};
|
||||
class VoiceAssistantAnnounceFinished : public ProtoMessage {
|
||||
public:
|
||||
bool success{false};
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
void dump_to(std::string &out) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||
};
|
||||
class ListEntitiesAlarmControlPanelResponse : public ProtoMessage {
|
||||
public:
|
||||
std::string object_id{};
|
||||
|
|
|
@ -486,6 +486,16 @@ bool APIServerConnectionBase::send_voice_assistant_audio(const VoiceAssistantAud
|
|||
#endif
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
#endif
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
#endif
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
bool APIServerConnectionBase::send_voice_assistant_announce_finished(const VoiceAssistantAnnounceFinished &msg) {
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
ESP_LOGVV(TAG, "send_voice_assistant_announce_finished: %s", msg.dump().c_str());
|
||||
#endif
|
||||
return this->send_message_<VoiceAssistantAnnounceFinished>(msg, 120);
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
bool APIServerConnectionBase::send_list_entities_alarm_control_panel_response(
|
||||
const ListEntitiesAlarmControlPanelResponse &msg) {
|
||||
|
@ -1135,6 +1145,17 @@ bool APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type,
|
|||
ESP_LOGVV(TAG, "on_update_command_request: %s", msg.dump().c_str());
|
||||
#endif
|
||||
this->on_update_command_request(msg);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case 119: {
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
VoiceAssistantAnnounceRequest msg;
|
||||
msg.decode(msg_data, msg_size);
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
ESP_LOGVV(TAG, "on_voice_assistant_announce_request: %s", msg.dump().c_str());
|
||||
#endif
|
||||
this->on_voice_assistant_announce_request(msg);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -247,6 +247,12 @@ class APIServerConnectionBase : public ProtoService {
|
|||
#ifdef USE_VOICE_ASSISTANT
|
||||
virtual void on_voice_assistant_timer_event_response(const VoiceAssistantTimerEventResponse &value){};
|
||||
#endif
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
virtual void on_voice_assistant_announce_request(const VoiceAssistantAnnounceRequest &value){};
|
||||
#endif
|
||||
#ifdef USE_VOICE_ASSISTANT
|
||||
bool send_voice_assistant_announce_finished(const VoiceAssistantAnnounceFinished &msg);
|
||||
#endif
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
bool send_list_entities_alarm_control_panel_response(const ListEntitiesAlarmControlPanelResponse &msg);
|
||||
#endif
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import json
|
||||
import logging
|
||||
from os.path import (
|
||||
dirname,
|
||||
isfile,
|
||||
join,
|
||||
)
|
||||
from os.path import dirname, isfile, join
|
||||
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
|
@ -176,9 +172,10 @@ def _notify_old_style(config):
|
|||
|
||||
# NOTE: Keep this in mind when updating the recommended version:
|
||||
# * For all constants below, update platformio.ini (in this repo)
|
||||
# The dev and latest branches will be at *least* this version, which is what matters.
|
||||
ARDUINO_VERSIONS = {
|
||||
"dev": (cv.Version(0, 0, 0), "https://github.com/libretiny-eu/libretiny.git"),
|
||||
"latest": (cv.Version(0, 0, 0), None),
|
||||
"dev": (cv.Version(1, 7, 0), "https://github.com/libretiny-eu/libretiny.git"),
|
||||
"latest": (cv.Version(1, 7, 0), "libretiny"),
|
||||
"recommended": (cv.Version(1, 5, 1), None),
|
||||
}
|
||||
|
||||
|
@ -282,10 +279,10 @@ async def component_to_code(config):
|
|||
# if platform version is a valid version constraint, prefix the default package
|
||||
framework = config[CONF_FRAMEWORK]
|
||||
cv.platformio_version_constraint(framework[CONF_VERSION])
|
||||
if str(framework[CONF_VERSION]) != "0.0.0":
|
||||
cg.add_platformio_option("platform", f"libretiny @ {framework[CONF_VERSION]}")
|
||||
elif framework[CONF_SOURCE]:
|
||||
if framework[CONF_SOURCE]:
|
||||
cg.add_platformio_option("platform", framework[CONF_SOURCE])
|
||||
elif str(framework[CONF_VERSION]) != "0.0.0":
|
||||
cg.add_platformio_option("platform", f"libretiny @ {framework[CONF_VERSION]}")
|
||||
else:
|
||||
cg.add_platformio_option("platform", "libretiny")
|
||||
|
||||
|
|
|
@ -229,19 +229,23 @@ async def obj_hide_to_code(config, action_id, template_arg, args):
|
|||
async def do_hide(widget: Widget):
|
||||
widget.add_flag("LV_OBJ_FLAG_HIDDEN")
|
||||
|
||||
return await action_to_code(
|
||||
await get_widgets(config), do_hide, action_id, template_arg, args
|
||||
)
|
||||
widgets = [
|
||||
widget.outer if widget.outer else widget for widget in await get_widgets(config)
|
||||
]
|
||||
return await action_to_code(widgets, do_hide, action_id, template_arg, args)
|
||||
|
||||
|
||||
@automation.register_action("lvgl.widget.show", ObjUpdateAction, LIST_ACTION_SCHEMA)
|
||||
async def obj_show_to_code(config, action_id, template_arg, args):
|
||||
async def do_show(widget: Widget):
|
||||
widget.clear_flag("LV_OBJ_FLAG_HIDDEN")
|
||||
if widget.move_to_foreground:
|
||||
lv_obj.move_foreground(widget.obj)
|
||||
|
||||
return await action_to_code(
|
||||
await get_widgets(config), do_show, action_id, template_arg, args
|
||||
)
|
||||
widgets = [
|
||||
widget.outer if widget.outer else widget for widget in await get_widgets(config)
|
||||
]
|
||||
return await action_to_code(widgets, do_show, action_id, template_arg, args)
|
||||
|
||||
|
||||
def focused_id(value):
|
||||
|
|
|
@ -374,6 +374,7 @@ CONF_ANTIALIAS = "antialias"
|
|||
CONF_ARC_LENGTH = "arc_length"
|
||||
CONF_AUTO_START = "auto_start"
|
||||
CONF_BACKGROUND_STYLE = "background_style"
|
||||
CONF_BUTTON_STYLE = "button_style"
|
||||
CONF_DECIMAL_PLACES = "decimal_places"
|
||||
CONF_COLUMN = "column"
|
||||
CONF_DIGITS = "digits"
|
||||
|
|
|
@ -89,6 +89,8 @@ class Widget:
|
|||
self.obj = MockObj(f"{self.var}->obj")
|
||||
else:
|
||||
self.obj = var
|
||||
self.outer = None
|
||||
self.move_to_foreground = False
|
||||
|
||||
@staticmethod
|
||||
def create(name, var, wtype: WidgetType, config: dict = None):
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from esphome import config_validation as cv
|
||||
from esphome.const import CONF_BUTTON, CONF_ID, CONF_TEXT
|
||||
from esphome.const import CONF_BUTTON, CONF_ID, CONF_ITEMS, CONF_TEXT
|
||||
from esphome.core import ID
|
||||
from esphome.cpp_generator import new_Pvariable, static_const_array
|
||||
from esphome.cpp_types import nullptr
|
||||
|
||||
from ..defines import (
|
||||
CONF_BODY,
|
||||
CONF_BUTTON_STYLE,
|
||||
CONF_BUTTONS,
|
||||
CONF_CLOSE_BUTTON,
|
||||
CONF_MSGBOXES,
|
||||
|
@ -25,7 +26,7 @@ from ..lvcode import (
|
|||
lv_obj,
|
||||
lv_Pvariable,
|
||||
)
|
||||
from ..schemas import STYLE_SCHEMA, STYLED_TEXT_SCHEMA, container_schema
|
||||
from ..schemas import STYLE_SCHEMA, STYLED_TEXT_SCHEMA, container_schema, part_schema
|
||||
from ..styles import TOP_LAYER
|
||||
from ..types import LV_EVENT, char_ptr, lv_obj_t
|
||||
from . import Widget, set_obj_properties
|
||||
|
@ -48,9 +49,10 @@ MSGBOX_SCHEMA = container_schema(
|
|||
{
|
||||
cv.GenerateID(CONF_ID): cv.declare_id(lv_obj_t),
|
||||
cv.Required(CONF_TITLE): STYLED_TEXT_SCHEMA,
|
||||
cv.Optional(CONF_BODY): STYLED_TEXT_SCHEMA,
|
||||
cv.Optional(CONF_BODY, default=""): STYLED_TEXT_SCHEMA,
|
||||
cv.Optional(CONF_BUTTONS): cv.ensure_list(BUTTONMATRIX_BUTTON_SCHEMA),
|
||||
cv.Optional(CONF_CLOSE_BUTTON): lv_bool,
|
||||
cv.Optional(CONF_BUTTON_STYLE): part_schema(buttonmatrix_spec),
|
||||
cv.Optional(CONF_CLOSE_BUTTON, default=True): lv_bool,
|
||||
cv.GenerateID(CONF_BUTTON_TEXT_LIST_ID): cv.declare_id(char_ptr),
|
||||
}
|
||||
),
|
||||
|
@ -74,7 +76,8 @@ async def msgbox_to_code(conf):
|
|||
)
|
||||
lvgl_components_required.add("BUTTONMATRIX")
|
||||
messagebox_id = conf[CONF_ID]
|
||||
outer = lv_Pvariable(lv_obj_t, messagebox_id.id)
|
||||
outer_id = f"{messagebox_id.id}_outer"
|
||||
outer = lv_Pvariable(lv_obj_t, messagebox_id.id + "_outer")
|
||||
buttonmatrix = new_Pvariable(
|
||||
ID(
|
||||
f"{messagebox_id.id}_buttonmatrix_",
|
||||
|
@ -82,8 +85,11 @@ async def msgbox_to_code(conf):
|
|||
type=lv_buttonmatrix_t,
|
||||
)
|
||||
)
|
||||
msgbox = lv_Pvariable(lv_obj_t, f"{messagebox_id.id}_msgbox")
|
||||
outer_widget = Widget.create(messagebox_id, outer, obj_spec, conf)
|
||||
msgbox = lv_Pvariable(lv_obj_t, messagebox_id.id)
|
||||
outer_widget = Widget.create(outer_id, outer, obj_spec, conf)
|
||||
outer_widget.move_to_foreground = True
|
||||
msgbox_widget = Widget.create(messagebox_id, msgbox, obj_spec, conf)
|
||||
msgbox_widget.outer = outer_widget
|
||||
buttonmatrix_widget = Widget.create(
|
||||
str(buttonmatrix), buttonmatrix, buttonmatrix_spec, conf
|
||||
)
|
||||
|
@ -92,10 +98,8 @@ async def msgbox_to_code(conf):
|
|||
)
|
||||
text_id = conf[CONF_BUTTON_TEXT_LIST_ID]
|
||||
text_list = static_const_array(text_id, text_list)
|
||||
if (text := conf.get(CONF_BODY)) is not None:
|
||||
text = await lv_text.process(text.get(CONF_TEXT))
|
||||
if (title := conf.get(CONF_TITLE)) is not None:
|
||||
title = await lv_text.process(title.get(CONF_TEXT))
|
||||
text = await lv_text.process(conf[CONF_BODY].get(CONF_TEXT, ""))
|
||||
title = await lv_text.process(conf[CONF_TITLE].get(CONF_TEXT, ""))
|
||||
close_button = conf[CONF_CLOSE_BUTTON]
|
||||
lv_assign(outer, lv_expr.obj_create(TOP_LAYER))
|
||||
lv_obj.set_width(outer, lv_pct(100))
|
||||
|
@ -111,20 +115,27 @@ async def msgbox_to_code(conf):
|
|||
)
|
||||
lv_obj.set_style_align(msgbox, literal("LV_ALIGN_CENTER"), 0)
|
||||
lv_add(buttonmatrix.set_obj(lv_expr.msgbox_get_btns(msgbox)))
|
||||
await set_obj_properties(outer_widget, conf)
|
||||
if button_style := conf.get(CONF_BUTTON_STYLE):
|
||||
button_style = {CONF_ITEMS: button_style}
|
||||
await set_obj_properties(buttonmatrix_widget, button_style)
|
||||
await set_obj_properties(msgbox_widget, conf)
|
||||
async with LambdaContext(EVENT_ARG, where=messagebox_id) as close_action:
|
||||
outer_widget.add_flag("LV_OBJ_FLAG_HIDDEN")
|
||||
if close_button:
|
||||
async with LambdaContext(EVENT_ARG, where=messagebox_id) as context:
|
||||
outer_widget.add_flag("LV_OBJ_FLAG_HIDDEN")
|
||||
with LocalVariable(
|
||||
"close_btn_", lv_obj_t, lv_expr.msgbox_get_close_btn(msgbox)
|
||||
) as close_btn:
|
||||
lv_obj.remove_event_cb(close_btn, nullptr)
|
||||
lv_obj.add_event_cb(
|
||||
close_btn,
|
||||
await context.get_lambda(),
|
||||
await close_action.get_lambda(),
|
||||
LV_EVENT.CLICKED,
|
||||
nullptr,
|
||||
)
|
||||
else:
|
||||
lv_obj.add_event_cb(
|
||||
outer, await close_action.get_lambda(), LV_EVENT.CLICKED, nullptr
|
||||
)
|
||||
|
||||
if len(ctrl_list) != 0 or len(width_list) != 0:
|
||||
set_btn_data(buttonmatrix.obj, ctrl_list, width_list)
|
||||
|
|
|
@ -396,6 +396,10 @@ void VoiceAssistant::loop() {
|
|||
this->set_timeout("playing", 2000, [this]() {
|
||||
this->cancel_timeout("speaker-timeout");
|
||||
this->set_state_(State::IDLE, State::IDLE);
|
||||
|
||||
api::VoiceAssistantAnnounceFinished msg;
|
||||
msg.success = true;
|
||||
this->api_client_->send_voice_assistant_announce_finished(msg);
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
@ -866,6 +870,18 @@ void VoiceAssistant::timer_tick_() {
|
|||
this->timer_tick_trigger_->trigger(res);
|
||||
}
|
||||
|
||||
void VoiceAssistant::on_announce(const api::VoiceAssistantAnnounceRequest &msg) {
|
||||
#ifdef USE_MEDIA_PLAYER
|
||||
if (this->media_player_ != nullptr) {
|
||||
this->tts_start_trigger_->trigger(msg.text);
|
||||
this->media_player_->make_call().set_media_url(msg.media_id).set_announcement(true).perform();
|
||||
this->set_state_(State::STREAMING_RESPONSE, State::STREAMING_RESPONSE);
|
||||
this->tts_end_trigger_->trigger(msg.media_id);
|
||||
this->end_trigger_->trigger();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
VoiceAssistant *global_voice_assistant = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
} // namespace voice_assistant
|
||||
|
|
|
@ -132,6 +132,7 @@ class VoiceAssistant : public Component {
|
|||
void on_event(const api::VoiceAssistantEventResponse &msg);
|
||||
void on_audio(const api::VoiceAssistantAudio &msg);
|
||||
void on_timer_event(const api::VoiceAssistantTimerEventResponse &msg);
|
||||
void on_announce(const api::VoiceAssistantAnnounceRequest &msg);
|
||||
|
||||
bool is_running() const { return this->state_ != State::IDLE; }
|
||||
void set_continuous(bool continuous) { this->continuous_ = continuous; }
|
||||
|
|
|
@ -52,6 +52,29 @@ lvgl:
|
|||
- touchscreen_id: tft_touch
|
||||
long_press_repeat_time: 200ms
|
||||
long_press_time: 500ms
|
||||
|
||||
msgboxes:
|
||||
- id: message_box
|
||||
close_button: true
|
||||
title: Messagebox
|
||||
bg_color: 0xffff
|
||||
body:
|
||||
text: This is a sample messagebox
|
||||
bg_color: 0x808080
|
||||
button_style:
|
||||
bg_color: 0xff00
|
||||
border_width: 4
|
||||
buttons:
|
||||
- id: msgbox_button
|
||||
text: Button
|
||||
- id: msgbox_apply
|
||||
text: "Close"
|
||||
on_click:
|
||||
then:
|
||||
- lvgl.widget.hide: message_box
|
||||
- id: simple_msgbox
|
||||
title: Simple
|
||||
|
||||
pages:
|
||||
- id: page1
|
||||
on_load:
|
||||
|
@ -98,6 +121,7 @@ lvgl:
|
|||
- lvgl.update:
|
||||
disp_bg_color: 0xffff00
|
||||
disp_bg_image: cat_image
|
||||
- lvgl.widget.show: message_box
|
||||
- label:
|
||||
text: "Hello shiny day"
|
||||
text_color: 0xFFFFFF
|
||||
|
|
Loading…
Reference in a new issue