mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 17:05:21 +01:00
commit
71b28be3c8
6 changed files with 52 additions and 27 deletions
|
@ -22,14 +22,14 @@ void I2SAudioMediaPlayer::control(const media_player::MediaPlayerCall &call) {
|
||||||
this->start();
|
this->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->i2s_state_ != I2S_STATE_RUNNING) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (call.get_volume().has_value()) {
|
if (call.get_volume().has_value()) {
|
||||||
this->volume = call.get_volume().value();
|
this->volume = call.get_volume().value();
|
||||||
this->set_volume_(volume);
|
this->set_volume_(volume);
|
||||||
this->unmute_();
|
this->unmute_();
|
||||||
}
|
}
|
||||||
|
if (this->i2s_state_ != I2S_STATE_RUNNING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (call.get_command().has_value()) {
|
if (call.get_command().has_value()) {
|
||||||
switch (call.get_command().value()) {
|
switch (call.get_command().value()) {
|
||||||
case media_player::MEDIA_PLAYER_COMMAND_PLAY:
|
case media_player::MEDIA_PLAYER_COMMAND_PLAY:
|
||||||
|
@ -97,7 +97,8 @@ void I2SAudioMediaPlayer::unmute_() {
|
||||||
this->muted_ = false;
|
this->muted_ = false;
|
||||||
}
|
}
|
||||||
void I2SAudioMediaPlayer::set_volume_(float volume, bool publish) {
|
void I2SAudioMediaPlayer::set_volume_(float volume, bool publish) {
|
||||||
this->audio_->setVolume(remap<uint8_t, float>(volume, 0.0f, 1.0f, 0, 21));
|
if (this->audio_ != nullptr)
|
||||||
|
this->audio_->setVolume(remap<uint8_t, float>(volume, 0.0f, 1.0f, 0, 21));
|
||||||
if (publish)
|
if (publish)
|
||||||
this->volume = volume;
|
this->volume = volume;
|
||||||
}
|
}
|
||||||
|
@ -157,13 +158,23 @@ void I2SAudioMediaPlayer::start_() {
|
||||||
#endif
|
#endif
|
||||||
this->i2s_state_ = I2S_STATE_RUNNING;
|
this->i2s_state_ = I2S_STATE_RUNNING;
|
||||||
this->high_freq_.start();
|
this->high_freq_.start();
|
||||||
|
this->audio_->setVolume(remap<uint8_t, float>(this->volume, 0.0f, 1.0f, 0, 21));
|
||||||
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;
|
||||||
this->publish_state();
|
this->publish_state();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void I2SAudioMediaPlayer::stop() { this->i2s_state_ = I2S_STATE_STOPPING; }
|
void I2SAudioMediaPlayer::stop() {
|
||||||
|
if (this->i2s_state_ == I2S_STATE_STOPPED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this->i2s_state_ == I2S_STATE_STARTING) {
|
||||||
|
this->i2s_state_ = I2S_STATE_STOPPED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->i2s_state_ = I2S_STATE_STOPPING;
|
||||||
|
}
|
||||||
void I2SAudioMediaPlayer::stop_() {
|
void I2SAudioMediaPlayer::stop_() {
|
||||||
if (this->audio_->isRunning()) {
|
if (this->audio_->isRunning()) {
|
||||||
this->audio_->stopSong();
|
this->audio_->stopSong();
|
||||||
|
|
|
@ -89,6 +89,10 @@ void I2SAudioMicrophone::start_() {
|
||||||
void I2SAudioMicrophone::stop() {
|
void I2SAudioMicrophone::stop() {
|
||||||
if (this->state_ == microphone::STATE_STOPPED || this->is_failed())
|
if (this->state_ == microphone::STATE_STOPPED || this->is_failed())
|
||||||
return;
|
return;
|
||||||
|
if (this->state_ == microphone::STATE_STARTING) {
|
||||||
|
this->state_ = microphone::STATE_STOPPED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
this->state_ = microphone::STATE_STOPPING;
|
this->state_ = microphone::STATE_STOPPING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,10 @@ void I2SAudioSpeaker::player_task(void *params) {
|
||||||
void I2SAudioSpeaker::stop() {
|
void I2SAudioSpeaker::stop() {
|
||||||
if (this->state_ == speaker::STATE_STOPPED)
|
if (this->state_ == speaker::STATE_STOPPED)
|
||||||
return;
|
return;
|
||||||
|
if (this->state_ == speaker::STATE_STARTING) {
|
||||||
|
this->state_ = speaker::STATE_STOPPED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
this->state_ = speaker::STATE_STOPPING;
|
this->state_ = speaker::STATE_STOPPING;
|
||||||
DataEvent data;
|
DataEvent data;
|
||||||
data.stop = true;
|
data.stop = true;
|
||||||
|
|
|
@ -252,7 +252,7 @@ void SEN5XComponent::dump_config() {
|
||||||
ESP_LOGCONFIG(TAG, " Firmware version: %d", this->firmware_version_);
|
ESP_LOGCONFIG(TAG, " Firmware version: %d", this->firmware_version_);
|
||||||
ESP_LOGCONFIG(TAG, " Serial number %02d.%02d.%02d", serial_number_[0], serial_number_[1], serial_number_[2]);
|
ESP_LOGCONFIG(TAG, " Serial number %02d.%02d.%02d", serial_number_[0], serial_number_[1], serial_number_[2]);
|
||||||
if (this->auto_cleaning_interval_.has_value()) {
|
if (this->auto_cleaning_interval_.has_value()) {
|
||||||
ESP_LOGCONFIG(TAG, " Auto auto cleaning interval %d seconds", auto_cleaning_interval_.value());
|
ESP_LOGCONFIG(TAG, " Auto cleaning interval %d seconds", auto_cleaning_interval_.value());
|
||||||
}
|
}
|
||||||
if (this->acceleration_mode_.has_value()) {
|
if (this->acceleration_mode_.has_value()) {
|
||||||
switch (this->acceleration_mode_.value()) {
|
switch (this->acceleration_mode_.value()) {
|
||||||
|
|
|
@ -57,37 +57,43 @@ void TuyaLight::setup() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float red, green, blue;
|
||||||
switch (*this->color_type_) {
|
switch (*this->color_type_) {
|
||||||
case TuyaColorType::RGBHSV:
|
case TuyaColorType::RGBHSV:
|
||||||
case TuyaColorType::RGB: {
|
case TuyaColorType::RGB: {
|
||||||
auto red = parse_hex<uint8_t>(datapoint.value_string.substr(0, 2));
|
auto rgb = parse_hex<uint32_t>(datapoint.value_string.substr(0, 6));
|
||||||
auto green = parse_hex<uint8_t>(datapoint.value_string.substr(2, 2));
|
if (!rgb.has_value())
|
||||||
auto blue = parse_hex<uint8_t>(datapoint.value_string.substr(4, 2));
|
return;
|
||||||
if (red.has_value() && green.has_value() && blue.has_value()) {
|
|
||||||
auto rgb_call = this->state_->make_call();
|
red = (*rgb >> 16) / 255.0f;
|
||||||
rgb_call.set_rgb(float(*red) / 255, float(*green) / 255, float(*blue) / 255);
|
green = ((*rgb >> 8) & 0xff) / 255.0f;
|
||||||
rgb_call.perform();
|
blue = (*rgb & 0xff) / 255.0f;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TuyaColorType::HSV: {
|
case TuyaColorType::HSV: {
|
||||||
auto hue = parse_hex<uint16_t>(datapoint.value_string.substr(0, 4));
|
auto hue = parse_hex<uint16_t>(datapoint.value_string.substr(0, 4));
|
||||||
auto saturation = parse_hex<uint16_t>(datapoint.value_string.substr(4, 4));
|
auto saturation = parse_hex<uint16_t>(datapoint.value_string.substr(4, 4));
|
||||||
auto value = parse_hex<uint16_t>(datapoint.value_string.substr(8, 4));
|
auto value = parse_hex<uint16_t>(datapoint.value_string.substr(8, 4));
|
||||||
if (hue.has_value() && saturation.has_value() && value.has_value()) {
|
if (!hue.has_value() || !saturation.has_value() || !value.has_value())
|
||||||
float red, green, blue;
|
return;
|
||||||
hsv_to_rgb(*hue, float(*saturation) / 1000, float(*value) / 1000, red, green, blue);
|
|
||||||
auto rgb_call = this->state_->make_call();
|
hsv_to_rgb(*hue, float(*saturation) / 1000, float(*value) / 1000, red, green, blue);
|
||||||
rgb_call.set_rgb(red, green, blue);
|
|
||||||
rgb_call.perform();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float current_red, current_green, current_blue;
|
||||||
|
this->state_->current_values_as_rgb(¤t_red, ¤t_green, ¤t_blue);
|
||||||
|
if (red == current_red && green == current_green && blue == current_blue)
|
||||||
|
return;
|
||||||
|
auto rgb_call = this->state_->make_call();
|
||||||
|
rgb_call.set_rgb(red, green, blue);
|
||||||
|
rgb_call.perform();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min_value_datapoint_id_.has_value()) {
|
if (min_value_datapoint_id_.has_value()) {
|
||||||
parent_->set_integer_datapoint_value(*this->min_value_datapoint_id_, this->min_value_);
|
this->parent_->set_integer_datapoint_value(*this->min_value_datapoint_id_, this->min_value_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +162,7 @@ void TuyaLight::write_state(light::LightState *state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state->current_values.is_on() && this->switch_id_.has_value()) {
|
if (!state->current_values.is_on() && this->switch_id_.has_value()) {
|
||||||
parent_->set_boolean_datapoint_value(*this->switch_id_, false);
|
this->parent_->set_boolean_datapoint_value(*this->switch_id_, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,14 +172,14 @@ void TuyaLight::write_state(light::LightState *state) {
|
||||||
if (this->color_temperature_invert_) {
|
if (this->color_temperature_invert_) {
|
||||||
color_temp_int = this->color_temperature_max_value_ - color_temp_int;
|
color_temp_int = this->color_temperature_max_value_ - color_temp_int;
|
||||||
}
|
}
|
||||||
parent_->set_integer_datapoint_value(*this->color_temperature_id_, color_temp_int);
|
this->parent_->set_integer_datapoint_value(*this->color_temperature_id_, color_temp_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->dimmer_id_.has_value()) {
|
if (this->dimmer_id_.has_value()) {
|
||||||
auto brightness_int = static_cast<uint32_t>(brightness * this->max_value_);
|
auto brightness_int = static_cast<uint32_t>(brightness * this->max_value_);
|
||||||
brightness_int = std::max(brightness_int, this->min_value_);
|
brightness_int = std::max(brightness_int, this->min_value_);
|
||||||
|
|
||||||
parent_->set_integer_datapoint_value(*this->dimmer_id_, brightness_int);
|
this->parent_->set_integer_datapoint_value(*this->dimmer_id_, brightness_int);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +216,7 @@ void TuyaLight::write_state(light::LightState *state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->switch_id_.has_value()) {
|
if (this->switch_id_.has_value()) {
|
||||||
parent_->set_boolean_datapoint_value(*this->switch_id_, true);
|
this->parent_->set_boolean_datapoint_value(*this->switch_id_, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2023.5.0b2"
|
__version__ = "2023.5.0b3"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue