mirror of
https://github.com/esphome/esphome.git
synced 2025-11-06 01:51:49 +00:00
Compare commits
15 Commits
2024.5.0b2
...
2024.5.0b5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd8afa51cd | ||
|
|
db4aa0b679 | ||
|
|
28a09cc0d0 | ||
|
|
128fad57b3 | ||
|
|
142c4a87d2 | ||
|
|
1e4d6ee344 | ||
|
|
5afe0e5ec2 | ||
|
|
ba3fc4c5d0 | ||
|
|
694f75117e | ||
|
|
4ec2ef27a8 | ||
|
|
448b4f5cb6 | ||
|
|
8ae8cd1168 | ||
|
|
bd776baf8d | ||
|
|
819bb9f8bc | ||
|
|
26048d18ef |
8
.github/workflows/release.yml
vendored
8
.github/workflows/release.yml
vendored
@@ -132,10 +132,16 @@ jobs:
|
|||||||
suffix: lint
|
suffix: lint
|
||||||
version: ${{ needs.init.outputs.tag }}
|
version: ${{ needs.init.outputs.tag }}
|
||||||
|
|
||||||
|
- name: Sanitize platform name
|
||||||
|
id: sanitize
|
||||||
|
run: |
|
||||||
|
echo "${{ matrix.platform }}" | sed 's|/|-|g' > /tmp/platform
|
||||||
|
echo name=$(cat /tmp/platform) >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Upload digests
|
- name: Upload digests
|
||||||
uses: actions/upload-artifact@v4.3.3
|
uses: actions/upload-artifact@v4.3.3
|
||||||
with:
|
with:
|
||||||
name: digests-${{ matrix.platform }}
|
name: digests-${{ steps.sanitize.outputs.name }}
|
||||||
path: /tmp/digests
|
path: /tmp/digests
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
|
|||||||
@@ -1147,6 +1147,9 @@ message MediaPlayerCommandRequest {
|
|||||||
|
|
||||||
bool has_media_url = 6;
|
bool has_media_url = 6;
|
||||||
string media_url = 7;
|
string media_url = 7;
|
||||||
|
|
||||||
|
bool has_announcement = 8;
|
||||||
|
bool announcement = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== BLUETOOTH ====================
|
// ==================== BLUETOOTH ====================
|
||||||
|
|||||||
@@ -1002,7 +1002,11 @@ bool APIConnection::send_media_player_state(media_player::MediaPlayer *media_pla
|
|||||||
|
|
||||||
MediaPlayerStateResponse resp{};
|
MediaPlayerStateResponse resp{};
|
||||||
resp.key = media_player->get_object_id_hash();
|
resp.key = media_player->get_object_id_hash();
|
||||||
resp.state = static_cast<enums::MediaPlayerState>(media_player->state);
|
|
||||||
|
media_player::MediaPlayerState report_state = media_player->state == media_player::MEDIA_PLAYER_STATE_ANNOUNCING
|
||||||
|
? media_player::MEDIA_PLAYER_STATE_PLAYING
|
||||||
|
: media_player->state;
|
||||||
|
resp.state = static_cast<enums::MediaPlayerState>(report_state);
|
||||||
resp.volume = media_player->volume;
|
resp.volume = media_player->volume;
|
||||||
resp.muted = media_player->is_muted();
|
resp.muted = media_player->is_muted();
|
||||||
return this->send_media_player_state_response(resp);
|
return this->send_media_player_state_response(resp);
|
||||||
@@ -1038,6 +1042,9 @@ void APIConnection::media_player_command(const MediaPlayerCommandRequest &msg) {
|
|||||||
if (msg.has_media_url) {
|
if (msg.has_media_url) {
|
||||||
call.set_media_url(msg.media_url);
|
call.set_media_url(msg.media_url);
|
||||||
}
|
}
|
||||||
|
if (msg.has_announcement) {
|
||||||
|
call.set_announcement(msg.announcement);
|
||||||
|
}
|
||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5253,6 +5253,14 @@ bool MediaPlayerCommandRequest::decode_varint(uint32_t field_id, ProtoVarInt val
|
|||||||
this->has_media_url = value.as_bool();
|
this->has_media_url = value.as_bool();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case 8: {
|
||||||
|
this->has_announcement = value.as_bool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case 9: {
|
||||||
|
this->announcement = value.as_bool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -5289,6 +5297,8 @@ void MediaPlayerCommandRequest::encode(ProtoWriteBuffer buffer) const {
|
|||||||
buffer.encode_float(5, this->volume);
|
buffer.encode_float(5, this->volume);
|
||||||
buffer.encode_bool(6, this->has_media_url);
|
buffer.encode_bool(6, this->has_media_url);
|
||||||
buffer.encode_string(7, this->media_url);
|
buffer.encode_string(7, this->media_url);
|
||||||
|
buffer.encode_bool(8, this->has_announcement);
|
||||||
|
buffer.encode_bool(9, this->announcement);
|
||||||
}
|
}
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
void MediaPlayerCommandRequest::dump_to(std::string &out) const {
|
void MediaPlayerCommandRequest::dump_to(std::string &out) const {
|
||||||
@@ -5323,6 +5333,14 @@ void MediaPlayerCommandRequest::dump_to(std::string &out) const {
|
|||||||
out.append(" media_url: ");
|
out.append(" media_url: ");
|
||||||
out.append("'").append(this->media_url).append("'");
|
out.append("'").append(this->media_url).append("'");
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
|
|
||||||
|
out.append(" has_announcement: ");
|
||||||
|
out.append(YESNO(this->has_announcement));
|
||||||
|
out.append("\n");
|
||||||
|
|
||||||
|
out.append(" announcement: ");
|
||||||
|
out.append(YESNO(this->announcement));
|
||||||
|
out.append("\n");
|
||||||
out.append("}");
|
out.append("}");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1298,6 +1298,8 @@ class MediaPlayerCommandRequest : public ProtoMessage {
|
|||||||
float volume{0.0f};
|
float volume{0.0f};
|
||||||
bool has_media_url{false};
|
bool has_media_url{false};
|
||||||
std::string media_url{};
|
std::string media_url{};
|
||||||
|
bool has_announcement{false};
|
||||||
|
bool announcement{false};
|
||||||
void encode(ProtoWriteBuffer buffer) const override;
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
void dump_to(std::string &out) const override;
|
void dump_to(std::string &out) const override;
|
||||||
|
|||||||
@@ -14,15 +14,41 @@ CONF_HEX = "hex"
|
|||||||
|
|
||||||
|
|
||||||
def hex_color(value):
|
def hex_color(value):
|
||||||
|
if isinstance(value, int):
|
||||||
|
value = str(value)
|
||||||
|
if not isinstance(value, str):
|
||||||
|
raise cv.Invalid("Invalid value for hex color")
|
||||||
if len(value) != 6:
|
if len(value) != 6:
|
||||||
raise cv.Invalid("Color must have six digits")
|
raise cv.Invalid("Hex color must have six digits")
|
||||||
try:
|
try:
|
||||||
return (int(value[0:2], 16), int(value[2:4], 16), int(value[4:6], 16))
|
return int(value[0:2], 16), int(value[2:4], 16), int(value[4:6], 16)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
raise cv.Invalid("Color must be hexadecimal") from exc
|
raise cv.Invalid("Color must be hexadecimal") from exc
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.Any(
|
components = {
|
||||||
|
CONF_RED,
|
||||||
|
CONF_RED_INT,
|
||||||
|
CONF_GREEN,
|
||||||
|
CONF_GREEN_INT,
|
||||||
|
CONF_BLUE,
|
||||||
|
CONF_BLUE_INT,
|
||||||
|
CONF_WHITE,
|
||||||
|
CONF_WHITE_INT,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def validate_color(config):
|
||||||
|
has_components = set(config) & components
|
||||||
|
has_hex = CONF_HEX in config
|
||||||
|
if has_hex and has_components:
|
||||||
|
raise cv.Invalid("Hex color value may not be combined with component values")
|
||||||
|
if not has_hex and not has_components:
|
||||||
|
raise cv.Invalid("Must provide at least one color option")
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = cv.All(
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
{
|
{
|
||||||
cv.Required(CONF_ID): cv.declare_id(ColorStruct),
|
cv.Required(CONF_ID): cv.declare_id(ColorStruct),
|
||||||
@@ -34,14 +60,10 @@ CONFIG_SCHEMA = cv.Any(
|
|||||||
cv.Exclusive(CONF_BLUE_INT, "blue"): cv.uint8_t,
|
cv.Exclusive(CONF_BLUE_INT, "blue"): cv.uint8_t,
|
||||||
cv.Exclusive(CONF_WHITE, "white"): cv.percentage,
|
cv.Exclusive(CONF_WHITE, "white"): cv.percentage,
|
||||||
cv.Exclusive(CONF_WHITE_INT, "white"): cv.uint8_t,
|
cv.Exclusive(CONF_WHITE_INT, "white"): cv.uint8_t,
|
||||||
|
cv.Optional(CONF_HEX): hex_color,
|
||||||
}
|
}
|
||||||
).extend(cv.COMPONENT_SCHEMA),
|
).extend(cv.COMPONENT_SCHEMA),
|
||||||
cv.Schema(
|
validate_color,
|
||||||
{
|
|
||||||
cv.Required(CONF_ID): cv.declare_id(ColorStruct),
|
|
||||||
cv.Required(CONF_HEX): hex_color,
|
|
||||||
}
|
|
||||||
).extend(cv.COMPONENT_SCHEMA),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ namespace i2s_audio {
|
|||||||
static const char *const TAG = "audio";
|
static const char *const TAG = "audio";
|
||||||
|
|
||||||
void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
||||||
|
media_player::MediaPlayerState play_state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
|
if (call.get_announcement().has_value()) {
|
||||||
|
play_state = call.get_announcement().value() ? media_player::MEDIA_PLAYER_STATE_ANNOUNCING
|
||||||
|
: media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
|
}
|
||||||
if (call.get_media_url().has_value()) {
|
if (call.get_media_url().has_value()) {
|
||||||
this->current_url_ = call.get_media_url();
|
this->current_url_ = call.get_media_url();
|
||||||
if (this->i2s_state_ != I2S_STATE_STOPPED && this->audio_ != nullptr) {
|
if (this->i2s_state_ != I2S_STATE_STOPPED && this->audio_ != nullptr) {
|
||||||
@@ -17,7 +22,7 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
|||||||
this->audio_->stopSong();
|
this->audio_->stopSong();
|
||||||
}
|
}
|
||||||
this->audio_->connecttohost(this->current_url_.value().c_str());
|
this->audio_->connecttohost(this->current_url_.value().c_str());
|
||||||
this->state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
this->state = play_state;
|
||||||
} else {
|
} else {
|
||||||
this->start();
|
this->start();
|
||||||
}
|
}
|
||||||
@@ -35,7 +40,7 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
|||||||
case media_player::MEDIA_PLAYER_COMMAND_PLAY:
|
case media_player::MEDIA_PLAYER_COMMAND_PLAY:
|
||||||
if (!this->audio_->isRunning())
|
if (!this->audio_->isRunning())
|
||||||
this->audio_->pauseResume();
|
this->audio_->pauseResume();
|
||||||
this->state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
this->state = play_state;
|
||||||
break;
|
break;
|
||||||
case media_player::MEDIA_PLAYER_COMMAND_PAUSE:
|
case media_player::MEDIA_PLAYER_COMMAND_PAUSE:
|
||||||
if (this->audio_->isRunning())
|
if (this->audio_->isRunning())
|
||||||
@@ -126,7 +131,9 @@ void I2SAudioMediaPlayer::loop() {
|
|||||||
|
|
||||||
void I2SAudioMediaPlayer::play_() {
|
void I2SAudioMediaPlayer::play_() {
|
||||||
this->audio_->loop();
|
this->audio_->loop();
|
||||||
if (this->state == media_player::MEDIA_PLAYER_STATE_PLAYING && !this->audio_->isRunning()) {
|
if ((this->state == media_player::MEDIA_PLAYER_STATE_PLAYING ||
|
||||||
|
this->state == media_player::MEDIA_PLAYER_STATE_ANNOUNCING) &&
|
||||||
|
!this->audio_->isRunning()) {
|
||||||
this->stop();
|
this->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,6 +171,10 @@ void I2SAudioMediaPlayer::start_() {
|
|||||||
if (this->current_url_.has_value()) {
|
if (this->current_url_.has_value()) {
|
||||||
this->audio_->connecttohost(this->current_url_.value().c_str());
|
this->audio_->connecttohost(this->current_url_.value().c_str());
|
||||||
this->state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
this->state = media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
|
if (this->is_announcement_.has_value()) {
|
||||||
|
this->state = this->is_announcement_.value() ? media_player::MEDIA_PLAYER_STATE_ANNOUNCING
|
||||||
|
: media_player::MEDIA_PLAYER_STATE_PLAYING;
|
||||||
|
}
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ class I2SAudioMediaPlayer : public Component, public media_player::MediaPlayer,
|
|||||||
HighFrequencyLoopRequester high_freq_;
|
HighFrequencyLoopRequester high_freq_;
|
||||||
|
|
||||||
optional<std::string> current_url_{};
|
optional<std::string> current_url_{};
|
||||||
|
optional<bool> is_announcement_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace i2s_audio
|
} // namespace i2s_audio
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ namespace ltr390 {
|
|||||||
|
|
||||||
static const char *const TAG = "ltr390";
|
static const char *const TAG = "ltr390";
|
||||||
|
|
||||||
|
static const uint8_t LTR390_WAKEUP_TIME = 10;
|
||||||
|
static const uint8_t LTR390_SETTLE_TIME = 5;
|
||||||
|
|
||||||
static const uint8_t LTR390_MAIN_CTRL = 0x00;
|
static const uint8_t LTR390_MAIN_CTRL = 0x00;
|
||||||
static const uint8_t LTR390_MEAS_RATE = 0x04;
|
static const uint8_t LTR390_MEAS_RATE = 0x04;
|
||||||
static const uint8_t LTR390_GAIN = 0x05;
|
static const uint8_t LTR390_GAIN = 0x05;
|
||||||
@@ -101,21 +104,27 @@ void LTR390Component::read_mode_(int mode_index) {
|
|||||||
|
|
||||||
std::bitset<8> ctrl = this->reg(LTR390_MAIN_CTRL).get();
|
std::bitset<8> ctrl = this->reg(LTR390_MAIN_CTRL).get();
|
||||||
ctrl[LTR390_CTRL_MODE] = mode;
|
ctrl[LTR390_CTRL_MODE] = mode;
|
||||||
|
ctrl[LTR390_CTRL_EN] = true;
|
||||||
this->reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
|
this->reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
|
||||||
|
|
||||||
// After the sensor integration time do the following
|
// After the sensor integration time do the following
|
||||||
this->set_timeout(((uint32_t) RESOLUTIONVALUE[this->res_]) * 100, [this, mode_index]() {
|
this->set_timeout(((uint32_t) RESOLUTIONVALUE[this->res_]) * 100 + LTR390_WAKEUP_TIME + LTR390_SETTLE_TIME,
|
||||||
// Read from the sensor
|
[this, mode_index]() {
|
||||||
std::get<1>(this->mode_funcs_[mode_index])();
|
// Read from the sensor
|
||||||
|
std::get<1>(this->mode_funcs_[mode_index])();
|
||||||
|
|
||||||
// If there are more modes to read then begin the next
|
// If there are more modes to read then begin the next
|
||||||
// otherwise stop
|
// otherwise stop
|
||||||
if (mode_index + 1 < (int) this->mode_funcs_.size()) {
|
if (mode_index + 1 < (int) this->mode_funcs_.size()) {
|
||||||
this->read_mode_(mode_index + 1);
|
this->read_mode_(mode_index + 1);
|
||||||
} else {
|
} else {
|
||||||
this->reading_ = false;
|
// put sensor in standby
|
||||||
}
|
std::bitset<8> ctrl = this->reg(LTR390_MAIN_CTRL).get();
|
||||||
});
|
ctrl[LTR390_CTRL_EN] = false;
|
||||||
|
this->reg(LTR390_MAIN_CTRL) = ctrl.to_ulong();
|
||||||
|
this->reading_ = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void LTR390Component::setup() {
|
void LTR390Component::setup() {
|
||||||
|
|||||||
@@ -51,12 +51,16 @@ VolumeSetAction = media_player_ns.class_(
|
|||||||
|
|
||||||
CONF_ON_PLAY = "on_play"
|
CONF_ON_PLAY = "on_play"
|
||||||
CONF_ON_PAUSE = "on_pause"
|
CONF_ON_PAUSE = "on_pause"
|
||||||
|
CONF_ON_ANNOUNCEMENT = "on_announcement"
|
||||||
CONF_MEDIA_URL = "media_url"
|
CONF_MEDIA_URL = "media_url"
|
||||||
|
|
||||||
StateTrigger = media_player_ns.class_("StateTrigger", automation.Trigger.template())
|
StateTrigger = media_player_ns.class_("StateTrigger", automation.Trigger.template())
|
||||||
IdleTrigger = media_player_ns.class_("IdleTrigger", automation.Trigger.template())
|
IdleTrigger = media_player_ns.class_("IdleTrigger", automation.Trigger.template())
|
||||||
PlayTrigger = media_player_ns.class_("PlayTrigger", automation.Trigger.template())
|
PlayTrigger = media_player_ns.class_("PlayTrigger", automation.Trigger.template())
|
||||||
PauseTrigger = media_player_ns.class_("PauseTrigger", automation.Trigger.template())
|
PauseTrigger = media_player_ns.class_("PauseTrigger", automation.Trigger.template())
|
||||||
|
AnnoucementTrigger = media_player_ns.class_(
|
||||||
|
"AnnouncementTrigger", automation.Trigger.template()
|
||||||
|
)
|
||||||
IsIdleCondition = media_player_ns.class_("IsIdleCondition", automation.Condition)
|
IsIdleCondition = media_player_ns.class_("IsIdleCondition", automation.Condition)
|
||||||
IsPlayingCondition = media_player_ns.class_("IsPlayingCondition", automation.Condition)
|
IsPlayingCondition = media_player_ns.class_("IsPlayingCondition", automation.Condition)
|
||||||
|
|
||||||
@@ -75,6 +79,9 @@ async def setup_media_player_core_(var, config):
|
|||||||
for conf in config.get(CONF_ON_PAUSE, []):
|
for conf in config.get(CONF_ON_PAUSE, []):
|
||||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
await automation.build_automation(trigger, [], conf)
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
for conf in config.get(CONF_ON_ANNOUNCEMENT, []):
|
||||||
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
await automation.build_automation(trigger, [], conf)
|
||||||
|
|
||||||
|
|
||||||
async def register_media_player(var, config):
|
async def register_media_player(var, config):
|
||||||
@@ -106,6 +113,11 @@ MEDIA_PLAYER_SCHEMA = cv.ENTITY_BASE_SCHEMA.extend(
|
|||||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PauseTrigger),
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(PauseTrigger),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_ON_ANNOUNCEMENT): automation.validate_automation(
|
||||||
|
{
|
||||||
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(AnnoucementTrigger),
|
||||||
|
}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class StateTrigger : public Trigger<> {
|
|||||||
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(IdleTrigger, IDLE)
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(IdleTrigger, IDLE)
|
||||||
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PlayTrigger, PLAYING)
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PlayTrigger, PLAYING)
|
||||||
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PauseTrigger, PAUSED)
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(PauseTrigger, PAUSED)
|
||||||
|
MEDIA_PLAYER_SIMPLE_STATE_TRIGGER(AnnouncementTrigger, ANNOUNCING)
|
||||||
|
|
||||||
template<typename... Ts> class IsIdleCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
|
template<typename... Ts> class IsIdleCondition : public Condition<Ts...>, public Parented<MediaPlayer> {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ const char *media_player_state_to_string(MediaPlayerState state) {
|
|||||||
return "PLAYING";
|
return "PLAYING";
|
||||||
case MEDIA_PLAYER_STATE_PAUSED:
|
case MEDIA_PLAYER_STATE_PAUSED:
|
||||||
return "PAUSED";
|
return "PAUSED";
|
||||||
|
case MEDIA_PLAYER_STATE_ANNOUNCING:
|
||||||
|
return "ANNOUNCING";
|
||||||
case MEDIA_PLAYER_STATE_NONE:
|
case MEDIA_PLAYER_STATE_NONE:
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
@@ -68,6 +70,9 @@ void MediaPlayerCall::perform() {
|
|||||||
if (this->volume_.has_value()) {
|
if (this->volume_.has_value()) {
|
||||||
ESP_LOGD(TAG, " Volume: %.2f", this->volume_.value());
|
ESP_LOGD(TAG, " Volume: %.2f", this->volume_.value());
|
||||||
}
|
}
|
||||||
|
if (this->announcement_.has_value()) {
|
||||||
|
ESP_LOGD(TAG, " Announcement: %s", this->announcement_.value() ? "yes" : "no");
|
||||||
|
}
|
||||||
this->parent_->control(*this);
|
this->parent_->control(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +113,11 @@ MediaPlayerCall &MediaPlayerCall::set_volume(float volume) {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MediaPlayerCall &MediaPlayerCall::set_announcement(bool announce) {
|
||||||
|
this->announcement_ = announce;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void MediaPlayer::add_on_state_callback(std::function<void()> &&callback) {
|
void MediaPlayer::add_on_state_callback(std::function<void()> &&callback) {
|
||||||
this->state_callback_.add(std::move(callback));
|
this->state_callback_.add(std::move(callback));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ enum MediaPlayerState : uint8_t {
|
|||||||
MEDIA_PLAYER_STATE_NONE = 0,
|
MEDIA_PLAYER_STATE_NONE = 0,
|
||||||
MEDIA_PLAYER_STATE_IDLE = 1,
|
MEDIA_PLAYER_STATE_IDLE = 1,
|
||||||
MEDIA_PLAYER_STATE_PLAYING = 2,
|
MEDIA_PLAYER_STATE_PLAYING = 2,
|
||||||
MEDIA_PLAYER_STATE_PAUSED = 3
|
MEDIA_PLAYER_STATE_PAUSED = 3,
|
||||||
|
MEDIA_PLAYER_STATE_ANNOUNCING = 4
|
||||||
};
|
};
|
||||||
const char *media_player_state_to_string(MediaPlayerState state);
|
const char *media_player_state_to_string(MediaPlayerState state);
|
||||||
|
|
||||||
@@ -51,12 +52,14 @@ class MediaPlayerCall {
|
|||||||
MediaPlayerCall &set_media_url(const std::string &url);
|
MediaPlayerCall &set_media_url(const std::string &url);
|
||||||
|
|
||||||
MediaPlayerCall &set_volume(float volume);
|
MediaPlayerCall &set_volume(float volume);
|
||||||
|
MediaPlayerCall &set_announcement(bool announce);
|
||||||
|
|
||||||
void perform();
|
void perform();
|
||||||
|
|
||||||
const optional<MediaPlayerCommand> &get_command() const { return command_; }
|
const optional<MediaPlayerCommand> &get_command() const { return command_; }
|
||||||
const optional<std::string> &get_media_url() const { return media_url_; }
|
const optional<std::string> &get_media_url() const { return media_url_; }
|
||||||
const optional<float> &get_volume() const { return volume_; }
|
const optional<float> &get_volume() const { return volume_; }
|
||||||
|
const optional<bool> &get_announcement() const { return announcement_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void validate_();
|
void validate_();
|
||||||
@@ -64,6 +67,7 @@ class MediaPlayerCall {
|
|||||||
optional<MediaPlayerCommand> command_;
|
optional<MediaPlayerCommand> command_;
|
||||||
optional<std::string> media_url_;
|
optional<std::string> media_url_;
|
||||||
optional<float> volume_;
|
optional<float> volume_;
|
||||||
|
optional<bool> announcement_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MediaPlayer : public EntityBase {
|
class MediaPlayer : public EntityBase {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ void VoiceAssistant::loop() {
|
|||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
this->set_state_(State::START_PIPELINE, State::START_MICROPHONE);
|
this->set_state_(State::START_MICROPHONE, State::START_PIPELINE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this->high_freq_.stop();
|
this->high_freq_.stop();
|
||||||
@@ -318,7 +318,7 @@ void VoiceAssistant::loop() {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
if (this->media_player_ != nullptr) {
|
if (this->media_player_ != nullptr) {
|
||||||
playing = (this->media_player_->state == media_player::MediaPlayerState::MEDIA_PLAYER_STATE_PLAYING);
|
playing = (this->media_player_->state == media_player::MediaPlayerState::MEDIA_PLAYER_STATE_ANNOUNCING);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (playing) {
|
if (playing) {
|
||||||
@@ -514,7 +514,7 @@ void VoiceAssistant::request_start(bool continuous, bool silence_detection) {
|
|||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
this->set_state_(State::START_PIPELINE, State::START_MICROPHONE);
|
this->set_state_(State::START_MICROPHONE, State::START_PIPELINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -640,7 +640,7 @@ void VoiceAssistant::on_event(const api::VoiceAssistantEventResponse &msg) {
|
|||||||
this->defer([this, url]() {
|
this->defer([this, url]() {
|
||||||
#ifdef USE_MEDIA_PLAYER
|
#ifdef USE_MEDIA_PLAYER
|
||||||
if (this->media_player_ != nullptr) {
|
if (this->media_player_ != nullptr) {
|
||||||
this->media_player_->make_call().set_media_url(url).perform();
|
this->media_player_->make_call().set_media_url(url).set_announcement(true).perform();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this->tts_end_trigger_->trigger(url);
|
this->tts_end_trigger_->trigger(url);
|
||||||
|
|||||||
@@ -94,10 +94,10 @@ class VoiceAssistant : public Component {
|
|||||||
uint32_t get_feature_flags() const {
|
uint32_t get_feature_flags() const {
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
flags |= VoiceAssistantFeature::FEATURE_VOICE_ASSISTANT;
|
flags |= VoiceAssistantFeature::FEATURE_VOICE_ASSISTANT;
|
||||||
|
flags |= VoiceAssistantFeature::FEATURE_API_AUDIO;
|
||||||
#ifdef USE_SPEAKER
|
#ifdef USE_SPEAKER
|
||||||
if (this->speaker_ != nullptr) {
|
if (this->speaker_ != nullptr) {
|
||||||
flags |= VoiceAssistantFeature::FEATURE_SPEAKER;
|
flags |= VoiceAssistantFeature::FEATURE_SPEAKER;
|
||||||
flags |= VoiceAssistantFeature::FEATURE_API_AUDIO;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return flags;
|
return flags;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2024.5.0b2"
|
__version__ = "2024.5.0b5"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
VALID_SUBSTITUTIONS_CHARACTERS = (
|
VALID_SUBSTITUTIONS_CHARACTERS = (
|
||||||
|
|||||||
@@ -340,6 +340,8 @@ class ID:
|
|||||||
|
|
||||||
if self.id is None:
|
if self.id is None:
|
||||||
base = str(self.type).replace("::", "_").lower()
|
base = str(self.type).replace("::", "_").lower()
|
||||||
|
if base == self.type:
|
||||||
|
base = base + "_id"
|
||||||
name = "".join(c for c in base if c.isalnum() or c == "_")
|
name = "".join(c for c in base if c.isalnum() or c == "_")
|
||||||
used = set(registered_ids) | set(RESERVED_IDS) | CORE.loaded_integrations
|
used = set(registered_ids) | set(RESERVED_IDS) | CORE.loaded_integrations
|
||||||
self.id = ensure_unique_string(name, used)
|
self.id = ensure_unique_string(name, used)
|
||||||
|
|||||||
@@ -394,7 +394,7 @@ async def to_code(config):
|
|||||||
if project_conf := config.get(CONF_PROJECT):
|
if project_conf := config.get(CONF_PROJECT):
|
||||||
cg.add_define("ESPHOME_PROJECT_NAME", project_conf[CONF_NAME])
|
cg.add_define("ESPHOME_PROJECT_NAME", project_conf[CONF_NAME])
|
||||||
cg.add_define("ESPHOME_PROJECT_VERSION", project_conf[CONF_VERSION])
|
cg.add_define("ESPHOME_PROJECT_VERSION", project_conf[CONF_VERSION])
|
||||||
cg.add_define("ESPHOME_PROJECT_VERSION_30", project_conf[CONF_VERSION][:30])
|
cg.add_define("ESPHOME_PROJECT_VERSION_30", project_conf[CONF_VERSION][:29])
|
||||||
for conf in project_conf.get(CONF_ON_UPDATE, []):
|
for conf in project_conf.get(CONF_ON_UPDATE, []):
|
||||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
||||||
await cg.register_component(trigger, conf)
|
await cg.register_component(trigger, conf)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ tornado==6.4
|
|||||||
tzlocal==5.2 # from time
|
tzlocal==5.2 # from time
|
||||||
tzdata>=2021.1 # from time
|
tzdata>=2021.1 # from time
|
||||||
pyserial==3.5
|
pyserial==3.5
|
||||||
platformio==6.1.13 # When updating platformio, also update Dockerfile
|
platformio==6.1.15 # When updating platformio, also update Dockerfile
|
||||||
esptool==4.7.0
|
esptool==4.7.0
|
||||||
click==8.1.7
|
click==8.1.7
|
||||||
esphome-dashboard==20240412.0
|
esphome-dashboard==20240412.0
|
||||||
|
|||||||
@@ -9,3 +9,12 @@ color:
|
|||||||
blue: 100%
|
blue: 100%
|
||||||
- id: kbx_green
|
- id: kbx_green
|
||||||
hex: "3DEC55"
|
hex: "3DEC55"
|
||||||
|
- id: kbx_green_1
|
||||||
|
hex: 3DEC55
|
||||||
|
- id: cps_red
|
||||||
|
hex: 800000
|
||||||
|
- id: cps_green
|
||||||
|
hex: 008000
|
||||||
|
- id: cps_blue
|
||||||
|
hex: 000080
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user