1
0
mirror of https://github.com/esphome/esphome.git synced 2024-10-06 10:50:58 +01:00

Merge pull request #6374 from esphome/bump-2024.3.0b2

2024.3.0b2
This commit is contained in:
Jesse Hills 2024-03-15 17:06:14 +13:00 committed by GitHub
commit 4180eae68f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 54 additions and 53 deletions

View File

@ -19,13 +19,28 @@ void Servo::dump_config() {
ESP_LOGCONFIG(TAG, " run duration: %" PRIu32 " ms", this->transition_length_); ESP_LOGCONFIG(TAG, " run duration: %" PRIu32 " ms", this->transition_length_);
} }
void Servo::setup() {
float v;
if (this->restore_) {
this->rtc_ = global_preferences->make_preference<float>(global_servo_id);
global_servo_id++;
if (this->rtc_.load(&v)) {
this->target_value_ = v;
this->internal_write(v);
this->state_ = STATE_ATTACHED;
this->start_millis_ = millis();
return;
}
}
this->detach();
}
void Servo::loop() { void Servo::loop() {
// check if auto_detach_time_ is set and servo reached target // check if auto_detach_time_ is set and servo reached target
if (this->auto_detach_time_ && this->state_ == STATE_TARGET_REACHED) { if (this->auto_detach_time_ && this->state_ == STATE_TARGET_REACHED) {
if (millis() - this->start_millis_ > this->auto_detach_time_) { if (millis() - this->start_millis_ > this->auto_detach_time_) {
this->detach(); this->detach();
this->start_millis_ = 0; this->start_millis_ = 0;
this->state_ = STATE_DETACHED;
ESP_LOGD(TAG, "Servo detached on auto_detach_time"); ESP_LOGD(TAG, "Servo detached on auto_detach_time");
} }
} }
@ -54,8 +69,11 @@ void Servo::loop() {
void Servo::write(float value) { void Servo::write(float value) {
value = clamp(value, -1.0f, 1.0f); value = clamp(value, -1.0f, 1.0f);
if (this->target_value_ == value) if ((this->state_ == STATE_DETACHED) && (this->target_value_ == value)) {
this->internal_write(value); this->internal_write(value);
} else {
this->save_level_(value);
}
this->target_value_ = value; this->target_value_ = value;
this->source_value_ = this->current_value_; this->source_value_ = this->current_value_;
this->state_ = STATE_ATTACHED; this->state_ = STATE_ATTACHED;
@ -72,11 +90,18 @@ void Servo::internal_write(float value) {
level = lerp(value, this->idle_level_, this->max_level_); level = lerp(value, this->idle_level_, this->max_level_);
} }
this->output_->set_level(level); this->output_->set_level(level);
if (this->target_value_ == this->current_value_) {
this->save_level_(level);
}
this->current_value_ = value; this->current_value_ = value;
} }
void Servo::detach() {
this->state_ = STATE_DETACHED;
this->output_->set_level(0.0f);
}
void Servo::save_level_(float v) {
if (this->restore_)
this->rtc_.save(&v);
}
} // namespace servo } // namespace servo
} // namespace esphome } // namespace esphome

View File

@ -17,22 +17,8 @@ class Servo : public Component {
void loop() override; void loop() override;
void write(float value); void write(float value);
void internal_write(float value); void internal_write(float value);
void detach() { void detach();
this->output_->set_level(0.0f); void setup() override;
this->save_level_(0.0f);
}
void setup() override {
float v;
if (this->restore_) {
this->rtc_ = global_preferences->make_preference<float>(global_servo_id);
global_servo_id++;
if (this->rtc_.load(&v)) {
this->output_->set_level(v);
return;
}
}
this->detach();
}
void dump_config() override; void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; } float get_setup_priority() const override { return setup_priority::DATA; }
void set_min_level(float min_level) { min_level_ = min_level; } void set_min_level(float min_level) { min_level_ = min_level; }
@ -42,8 +28,10 @@ class Servo : public Component {
void set_auto_detach_time(uint32_t auto_detach_time) { auto_detach_time_ = auto_detach_time; } void set_auto_detach_time(uint32_t auto_detach_time) { auto_detach_time_ = auto_detach_time; }
void set_transition_length(uint32_t transition_length) { transition_length_ = transition_length; } void set_transition_length(uint32_t transition_length) { transition_length_ = transition_length; }
bool has_reached_target() { return this->current_value_ == this->target_value_; }
protected: protected:
void save_level_(float v) { this->rtc_.save(&v); } void save_level_(float v);
output::FloatOutput *output_; output::FloatOutput *output_;
float min_level_ = 0.0300f; float min_level_ = 0.0300f;

View File

@ -29,7 +29,6 @@ from esphome.const import (
PLATFORM_ESP32, PLATFORM_ESP32,
PLATFORM_ESP8266, PLATFORM_ESP8266,
PLATFORM_RP2040, PLATFORM_RP2040,
CONF_ALLOW_OTHER_USES,
CONF_DATA_PINS, CONF_DATA_PINS,
) )
from esphome.core import ( from esphome.core import (
@ -199,8 +198,6 @@ def get_hw_spi(config, available):
def validate_spi_config(config): def validate_spi_config(config):
available = list(range(len(get_hw_interface_list()))) available = list(range(len(get_hw_interface_list())))
for spi in config: for spi in config:
# map pin number to schema
spi[CONF_CLK_PIN] = pins.gpio_output_pin_schema(spi[CONF_CLK_PIN])
interface = spi[CONF_INTERFACE] interface = spi[CONF_INTERFACE]
if interface == "software": if interface == "software":
pass pass
@ -257,21 +254,11 @@ def get_spi_interface(index):
return "new SPIClass(HSPI)" return "new SPIClass(HSPI)"
# Do not use a pin schema for the number, as that will trigger a pin reuse error due to duplication of the
# clock pin in the standard and quad schemas.
clk_pin_validator = cv.maybe_simple_value(
{
cv.Required(CONF_NUMBER): cv.Any(cv.int_, cv.string),
cv.Optional(CONF_ALLOW_OTHER_USES): cv.boolean,
},
key=CONF_NUMBER,
)
SPI_SCHEMA = cv.All( SPI_SCHEMA = cv.All(
cv.Schema( cv.Schema(
{ {
cv.GenerateID(): cv.declare_id(SPIComponent), cv.GenerateID(): cv.declare_id(SPIComponent),
cv.Required(CONF_CLK_PIN): clk_pin_validator, cv.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema,
cv.Optional(CONF_MISO_PIN): pins.gpio_input_pin_schema, cv.Optional(CONF_MISO_PIN): pins.gpio_input_pin_schema,
cv.Optional(CONF_MOSI_PIN): pins.gpio_output_pin_schema, cv.Optional(CONF_MOSI_PIN): pins.gpio_output_pin_schema,
cv.Optional(CONF_FORCE_SW): cv.invalid( cv.Optional(CONF_FORCE_SW): cv.invalid(
@ -291,7 +278,7 @@ SPI_QUAD_SCHEMA = cv.All(
cv.Schema( cv.Schema(
{ {
cv.GenerateID(): cv.declare_id(QuadSPIComponent), cv.GenerateID(): cv.declare_id(QuadSPIComponent),
cv.Required(CONF_CLK_PIN): clk_pin_validator, cv.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema,
cv.Required(CONF_DATA_PINS): cv.All( cv.Required(CONF_DATA_PINS): cv.All(
cv.ensure_list(pins.internal_gpio_output_pin_number), cv.ensure_list(pins.internal_gpio_output_pin_number),
cv.Length(min=4, max=4), cv.Length(min=4, max=4),

View File

@ -486,7 +486,7 @@ void WebServer::handle_switch_request(AsyncWebServerRequest *request, const UrlM
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
std::string data = this->switch_json(obj, obj->state, DETAIL_STATE); std::string data = this->switch_json(obj, obj->state, DETAIL_STATE);
request->send(200, "application/json", data.c_str()); request->send(200, "application/json", data.c_str());
} else if (match.method == "toggle") { } else if (match.method == "toggle") {
@ -517,7 +517,7 @@ void WebServer::handle_button_request(AsyncWebServerRequest *request, const UrlM
for (button::Button *obj : App.get_buttons()) { for (button::Button *obj : App.get_buttons()) {
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_POST && match.method == "press") { if (match.method == "press") {
this->schedule_([obj]() { obj->press(); }); this->schedule_([obj]() { obj->press(); });
request->send(200); request->send(200);
return; return;
@ -572,7 +572,7 @@ void WebServer::handle_fan_request(AsyncWebServerRequest *request, const UrlMatc
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
std::string data = this->fan_json(obj, DETAIL_STATE); std::string data = this->fan_json(obj, DETAIL_STATE);
request->send(200, "application/json", data.c_str()); request->send(200, "application/json", data.c_str());
} else if (match.method == "toggle") { } else if (match.method == "toggle") {
@ -630,7 +630,7 @@ void WebServer::handle_light_request(AsyncWebServerRequest *request, const UrlMa
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
std::string data = this->light_json(obj, DETAIL_STATE); std::string data = this->light_json(obj, DETAIL_STATE);
request->send(200, "application/json", data.c_str()); request->send(200, "application/json", data.c_str());
} else if (match.method == "toggle") { } else if (match.method == "toggle") {
@ -736,7 +736,7 @@ void WebServer::handle_cover_request(AsyncWebServerRequest *request, const UrlMa
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
std::string data = this->cover_json(obj, DETAIL_STATE); std::string data = this->cover_json(obj, DETAIL_STATE);
request->send(200, "application/json", data.c_str()); request->send(200, "application/json", data.c_str());
continue; continue;
@ -805,7 +805,7 @@ void WebServer::handle_number_request(AsyncWebServerRequest *request, const UrlM
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
std::string data = this->number_json(obj, obj->state, DETAIL_STATE); std::string data = this->number_json(obj, obj->state, DETAIL_STATE);
request->send(200, "application/json", data.c_str()); request->send(200, "application/json", data.c_str());
return; return;
@ -910,7 +910,7 @@ void WebServer::handle_text_request(AsyncWebServerRequest *request, const UrlMat
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
std::string data = this->text_json(obj, obj->state, DETAIL_STATE); std::string data = this->text_json(obj, obj->state, DETAIL_STATE);
request->send(200, "text/json", data.c_str()); request->send(200, "text/json", data.c_str());
return; return;
@ -961,7 +961,7 @@ void WebServer::handle_select_request(AsyncWebServerRequest *request, const UrlM
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
auto detail = DETAIL_STATE; auto detail = DETAIL_STATE;
auto *param = request->getParam("detail"); auto *param = request->getParam("detail");
if (param && param->value() == "all") { if (param && param->value() == "all") {
@ -1016,7 +1016,7 @@ void WebServer::handle_climate_request(AsyncWebServerRequest *request, const Url
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
std::string data = this->climate_json(obj, DETAIL_STATE); std::string data = this->climate_json(obj, DETAIL_STATE);
request->send(200, "application/json", data.c_str()); request->send(200, "application/json", data.c_str());
return; return;
@ -1162,7 +1162,7 @@ void WebServer::handle_lock_request(AsyncWebServerRequest *request, const UrlMat
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
std::string data = this->lock_json(obj, obj->state, DETAIL_STATE); std::string data = this->lock_json(obj, obj->state, DETAIL_STATE);
request->send(200, "application/json", data.c_str()); request->send(200, "application/json", data.c_str());
} else if (match.method == "lock") { } else if (match.method == "lock") {
@ -1201,7 +1201,7 @@ void WebServer::handle_alarm_control_panel_request(AsyncWebServerRequest *reques
if (obj->get_object_id() != match.id) if (obj->get_object_id() != match.id)
continue; continue;
if (request->method() == HTTP_GET) { if (request->method() == HTTP_GET && match.method.empty()) {
std::string data = this->alarm_control_panel_json(obj, obj->get_state(), DETAIL_STATE); std::string data = this->alarm_control_panel_json(obj, obj->get_state(), DETAIL_STATE);
request->send(200, "application/json", data.c_str()); request->send(200, "application/json", data.c_str());
return; return;
@ -1251,7 +1251,7 @@ bool WebServer::canHandle(AsyncWebServerRequest *request) {
#endif #endif
#ifdef USE_BUTTON #ifdef USE_BUTTON
if (request->method() == HTTP_POST && match.domain == "button") if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.domain == "button")
return true; return true;
#endif #endif

View File

@ -157,7 +157,7 @@ network::IPAddresses WiFiComponent::wifi_sta_ip_addresses() {
} else { } else {
addresses[0] = network::IPAddress(&ip.ip); addresses[0] = network::IPAddress(&ip.ip);
} }
#if LWIP_IPV6 #if USE_NETWORK_IPV6
ip6_addr_t ipv6; ip6_addr_t ipv6;
err = tcpip_adapter_get_ip6_global(TCPIP_ADAPTER_IF_STA, &ipv6); err = tcpip_adapter_get_ip6_global(TCPIP_ADAPTER_IF_STA, &ipv6);
if (err != ESP_OK) { if (err != ESP_OK) {
@ -171,7 +171,7 @@ network::IPAddresses WiFiComponent::wifi_sta_ip_addresses() {
} else { } else {
addresses[2] = network::IPAddress(&ipv6); addresses[2] = network::IPAddress(&ipv6);
} }
#endif /* LWIP_IPV6 */ #endif /* USE_NETWORK_IPV6 */
return addresses; return addresses;
} }

View File

@ -1,6 +1,6 @@
"""Constants used by esphome.""" """Constants used by esphome."""
__version__ = "2024.3.0b1" __version__ = "2024.3.0b2"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_" ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
VALID_SUBSTITUTIONS_CHARACTERS = ( VALID_SUBSTITUTIONS_CHARACTERS = (

View File

@ -2,7 +2,8 @@ spi:
- id: spi_id_1 - id: spi_id_1
type: single type: single
clk_pin: clk_pin:
number: GPIO7 number: GPIO0
ignore_strapping_warning: true
allow_other_uses: false allow_other_uses: false
mosi_pin: GPIO6 mosi_pin: GPIO6
interface: hardware interface: hardware