Skip to content

Commit 164ece2

Browse files
committed
update components for 2023.5
1 parent 32c9215 commit 164ece2

19 files changed

+139
-100
lines changed

components/esp8266/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _parse_platform_version(value):
125125
try:
126126
# if platform version is a valid version constraint, prefix the default package
127127
cv.platformio_version_constraint(value)
128-
return f"platformio/espressif8266 @ {value}"
128+
return f"platformio/espressif8266@{value}"
129129
except cv.Invalid:
130130
return value
131131

@@ -183,7 +183,7 @@ async def to_code(config):
183183
cg.add_platformio_option("platform", conf[CONF_PLATFORM_VERSION])
184184
cg.add_platformio_option(
185185
"platform_packages",
186-
[f"platformio/framework-arduinoespressif8266 @ {conf[CONF_SOURCE]}"],
186+
[f"platformio/framework-arduinoespressif8266@{conf[CONF_SOURCE]}"],
187187
)
188188

189189
# Default for platformio is LWIP2_LOW_MEMORY with:

components/light/base_light_effects.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PulseLightEffect : public LightEffect {
2525
return;
2626
}
2727
auto call = this->state_->turn_on();
28-
float out = this->on_ ? 1.0 : 0.0;
28+
float out = this->on_ ? this->max_brightness : this->min_brightness;
2929
call.set_brightness_if_supported(out);
3030
this->on_ = !this->on_;
3131
call.set_transition_length_if_supported(this->transition_length_);
@@ -41,11 +41,18 @@ class PulseLightEffect : public LightEffect {
4141

4242
void set_update_interval(uint32_t update_interval) { this->update_interval_ = update_interval; }
4343

44+
void set_min_max_brightness(float min, float max) {
45+
this->min_brightness = min;
46+
this->max_brightness = max;
47+
}
48+
4449
protected:
4550
bool on_ = false;
4651
uint32_t last_color_change_{0};
4752
uint32_t transition_length_{};
4853
uint32_t update_interval_{};
54+
float min_brightness{0.0};
55+
float max_brightness{1.0};
4956
};
5057

5158
/// Random effect. Sets random colors every 10 seconds and slowly transitions between them.

components/light/effects.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
CONF_NUM_LEDS,
2929
CONF_RANDOM,
3030
CONF_SEQUENCE,
31+
CONF_MAX_BRIGHTNESS,
32+
CONF_MIN_BRIGHTNESS,
3133
)
3234
from esphome.util import Registry
3335
from .types import (
@@ -174,12 +176,19 @@ async def automation_effect_to_code(config, effect_id):
174176
cv.Optional(
175177
CONF_UPDATE_INTERVAL, default="1s"
176178
): cv.positive_time_period_milliseconds,
179+
cv.Optional(CONF_MIN_BRIGHTNESS, default="0%"): cv.percentage,
180+
cv.Optional(CONF_MAX_BRIGHTNESS, default="100%"): cv.percentage,
177181
},
178182
)
179183
async def pulse_effect_to_code(config, effect_id):
180184
effect = cg.new_Pvariable(effect_id, config[CONF_NAME])
181185
cg.add(effect.set_transition_length(config[CONF_TRANSITION_LENGTH]))
182186
cg.add(effect.set_update_interval(config[CONF_UPDATE_INTERVAL]))
187+
cg.add(
188+
effect.set_min_max_brightness(
189+
config[CONF_MIN_BRIGHTNESS], config[CONF_MAX_BRIGHTNESS]
190+
)
191+
)
183192
return effect
184193

185194

components/ota/ota_backend_esp_idf.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include <esp_ota_ops.h>
99
#include "esphome/components/md5/md5.h"
1010

11+
#if ESP_IDF_VERSION_MAJOR >= 5
12+
#include <spi_flash_mmap.h>
13+
#endif
14+
1115
namespace esphome {
1216
namespace ota {
1317

@@ -16,9 +20,28 @@ OTAResponseTypes IDFOTABackend::begin(size_t image_size) {
1620
if (this->partition_ == nullptr) {
1721
return OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION;
1822
}
19-
esp_task_wdt_init(15, false); // The following function takes longer than the 5 seconds timeout of WDT
23+
24+
// The following function takes longer than the 5 seconds timeout of WDT
25+
#if ESP_IDF_VERSION_MAJOR >= 5
26+
esp_task_wdt_config_t wdtc;
27+
wdtc.timeout_ms = 15000;
28+
wdtc.idle_core_mask = 0;
29+
wdtc.trigger_panic = false;
30+
esp_task_wdt_reconfigure(&wdtc);
31+
#else
32+
esp_task_wdt_init(15, false);
33+
#endif
34+
2035
esp_err_t err = esp_ota_begin(this->partition_, image_size, &this->update_handle_);
21-
esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, false); // Set the WDT back to the configured timeout
36+
37+
// Set the WDT back to the configured timeout
38+
#if ESP_IDF_VERSION_MAJOR >= 5
39+
wdtc.timeout_ms = CONFIG_ESP_TASK_WDT_TIMEOUT_S;
40+
esp_task_wdt_reconfigure(&wdtc);
41+
#else
42+
esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S, false);
43+
#endif
44+
2245
if (err != ESP_OK) {
2346
esp_ota_abort(this->update_handle_);
2447
this->update_handle_ = 0;

components/switch/switch.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ void Switch::publish_state(bool state, bool force_save) {
6666
ESP_LOGD(TAG, "'%s': Sending state %s", this->name_.c_str(), ONOFF(this->state));
6767
this->state_callback_.call(this->state);
6868
}
69-
7069
bool Switch::assumed_state() { return false; }
7170

7271
void Switch::add_on_state_callback(std::function<void(bool)> &&callback) {
@@ -75,13 +74,6 @@ void Switch::add_on_state_callback(std::function<void(bool)> &&callback) {
7574
void Switch::set_inverted(bool inverted) { this->inverted_ = inverted; }
7675
bool Switch::is_inverted() const { return this->inverted_; }
7776

78-
std::string Switch::get_device_class() {
79-
if (this->device_class_.has_value())
80-
return *this->device_class_;
81-
return "";
82-
}
83-
void Switch::set_device_class(const std::string &device_class) { this->device_class_ = device_class; }
84-
8577
void log_switch(const char *tag, const char *prefix, const char *type, Switch *obj) {
8678
if (obj != nullptr) {
8779
ESP_LOGCONFIG(tag, "%s%s '%s'", prefix, type, obj->get_name().c_str());

components/switch/switch.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum SwitchRestoreMode {
3131
* A switch is basically just a combination of a binary sensor (for reporting switch values)
3232
* and a write_state method that writes a state to the hardware.
3333
*/
34-
class Switch : public EntityBase {
34+
class Switch : public EntityBase, public EntityBase_DeviceClass {
3535
public:
3636
explicit Switch();
3737

@@ -105,10 +105,6 @@ class Switch : public EntityBase {
105105

106106
bool is_inverted() const;
107107

108-
/// Get the device class for this switch.
109-
std::string get_device_class();
110-
/// Set the Home Assistant device class for this switch.
111-
void set_device_class(const std::string &device_class);
112108
void set_restore_mode(SwitchRestoreMode restore_mode) { this->restore_mode = restore_mode; }
113109

114110
bool has_forced_hash = false;
@@ -145,7 +141,6 @@ class Switch : public EntityBase {
145141
bool inverted_{false};
146142
Deduplicator<bool> publish_dedup_;
147143
ESPPreferenceObject rtc_;
148-
optional<std::string> device_class_;
149144
};
150145

151146
#define LOG_SWITCH(prefix, type, obj) log_switch((TAG), (prefix), LOG_STR_LITERAL(type), (obj))

components/template/cover/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ async def to_code(config):
7373
await automation.build_automation(
7474
var.get_stop_trigger(), [], config[CONF_STOP_ACTION]
7575
)
76+
cg.add(var.set_has_stop(True))
7677
if CONF_TILT_ACTION in config:
7778
await automation.build_automation(
7879
var.get_tilt_trigger(), [(float, "tilt")], config[CONF_TILT_ACTION]

components/template/cover/template_cover.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,15 @@ void TemplateCover::control(const CoverCall &call) {
109109
CoverTraits TemplateCover::get_traits() {
110110
auto traits = CoverTraits();
111111
traits.set_is_assumed_state(this->assumed_state_);
112+
traits.set_supports_stop(this->has_stop_);
112113
traits.set_supports_position(this->has_position_);
113114
traits.set_supports_tilt(this->has_tilt_);
114115
return traits;
115116
}
116117
Trigger<float> *TemplateCover::get_position_trigger() const { return this->position_trigger_; }
117118
Trigger<float> *TemplateCover::get_tilt_trigger() const { return this->tilt_trigger_; }
118119
void TemplateCover::set_tilt_lambda(std::function<optional<float>()> &&tilt_f) { this->tilt_f_ = tilt_f; }
120+
void TemplateCover::set_has_stop(bool has_stop) { this->has_stop_ = has_stop; }
119121
void TemplateCover::set_has_position(bool has_position) { this->has_position_ = has_position; }
120122
void TemplateCover::set_has_tilt(bool has_tilt) { this->has_tilt_ = has_tilt; }
121123
void TemplateCover::stop_prev_trigger_() {

components/template/cover/template_cover.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TemplateCover : public cover::Cover, public Component {
2626
void set_optimistic(bool optimistic);
2727
void set_assumed_state(bool assumed_state);
2828
void set_tilt_lambda(std::function<optional<float>()> &&tilt_f);
29+
void set_has_stop(bool has_stop);
2930
void set_has_position(bool has_position);
3031
void set_has_tilt(bool has_tilt);
3132
void set_restore_mode(TemplateCoverRestoreMode restore_mode) { restore_mode_ = restore_mode; }
@@ -48,6 +49,7 @@ class TemplateCover : public cover::Cover, public Component {
4849
bool optimistic_{false};
4950
Trigger<> *open_trigger_;
5051
Trigger<> *close_trigger_;
52+
bool has_stop_{false};
5153
Trigger<> *stop_trigger_;
5254
Trigger<> *prev_command_trigger_{nullptr};
5355
Trigger<float> *position_trigger_;

components/template/sensor/template_sensor.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ namespace template_ {
88
static const char *const TAG = "template.sensor";
99

1010
void TemplateSensor::update() {
11-
if (this->f_.has_value()) {
12-
auto val = (*this->f_)();
13-
if (val.has_value()) {
14-
this->publish_state(*val);
15-
}
16-
} else if (!std::isnan(this->get_raw_state())) {
17-
this->publish_state(this->get_raw_state());
11+
if (!this->f_.has_value())
12+
return;
13+
14+
auto val = (*this->f_)();
15+
if (val.has_value()) {
16+
this->publish_state(*val);
1817
}
1918
}
2019
float TemplateSensor::get_setup_priority() const { return setup_priority::HARDWARE; }

0 commit comments

Comments
 (0)