mirror of
https://github.com/esphome/esphome.git
synced 2025-11-03 00:21:56 +00:00
Compare commits
7 Commits
climate_st
...
more_flexi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3636ab68f3 | ||
|
|
b30c4e716f | ||
|
|
658c50e0c6 | ||
|
|
399b86255a | ||
|
|
c38a558df8 | ||
|
|
299c937e67 | ||
|
|
b6516c687d |
48
.github/workflows/ci.yml
vendored
48
.github/workflows/ci.yml
vendored
@@ -180,7 +180,6 @@ jobs:
|
||||
memory_impact: ${{ steps.determine.outputs.memory-impact }}
|
||||
cpp-unit-tests-run-all: ${{ steps.determine.outputs.cpp-unit-tests-run-all }}
|
||||
cpp-unit-tests-components: ${{ steps.determine.outputs.cpp-unit-tests-components }}
|
||||
component-test-batches: ${{ steps.determine.outputs.component-test-batches }}
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
@@ -215,7 +214,6 @@ jobs:
|
||||
echo "memory-impact=$(echo "$output" | jq -c '.memory_impact')" >> $GITHUB_OUTPUT
|
||||
echo "cpp-unit-tests-run-all=$(echo "$output" | jq -r '.cpp_unit_tests_run_all')" >> $GITHUB_OUTPUT
|
||||
echo "cpp-unit-tests-components=$(echo "$output" | jq -c '.cpp_unit_tests_components')" >> $GITHUB_OUTPUT
|
||||
echo "component-test-batches=$(echo "$output" | jq -c '.component_test_batches')" >> $GITHUB_OUTPUT
|
||||
|
||||
integration-tests:
|
||||
name: Run integration tests
|
||||
@@ -460,7 +458,7 @@ jobs:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 2
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
include:
|
||||
- id: clang-tidy
|
||||
@@ -538,18 +536,59 @@ jobs:
|
||||
run: script/ci-suggest-changes
|
||||
if: always()
|
||||
|
||||
test-build-components-splitter:
|
||||
name: Split components for intelligent grouping (40 weighted per batch)
|
||||
runs-on: ubuntu-24.04
|
||||
needs:
|
||||
- common
|
||||
- determine-jobs
|
||||
if: github.event_name == 'pull_request' && fromJSON(needs.determine-jobs.outputs.component-test-count) > 0
|
||||
outputs:
|
||||
matrix: ${{ steps.split.outputs.components }}
|
||||
steps:
|
||||
- name: Check out code from GitHub
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- name: Restore Python
|
||||
uses: ./.github/actions/restore-python
|
||||
with:
|
||||
python-version: ${{ env.DEFAULT_PYTHON }}
|
||||
cache-key: ${{ needs.common.outputs.cache-key }}
|
||||
- name: Split components intelligently based on bus configurations
|
||||
id: split
|
||||
run: |
|
||||
. venv/bin/activate
|
||||
|
||||
# Use intelligent splitter that groups components with same bus configs
|
||||
components='${{ needs.determine-jobs.outputs.changed-components-with-tests }}'
|
||||
|
||||
# Only isolate directly changed components when targeting dev branch
|
||||
# For beta/release branches, group everything for faster CI
|
||||
if [[ "${{ github.base_ref }}" == beta* ]] || [[ "${{ github.base_ref }}" == release* ]]; then
|
||||
directly_changed='[]'
|
||||
echo "Target branch: ${{ github.base_ref }} - grouping all components"
|
||||
else
|
||||
directly_changed='${{ needs.determine-jobs.outputs.directly-changed-components-with-tests }}'
|
||||
echo "Target branch: ${{ github.base_ref }} - isolating directly changed components"
|
||||
fi
|
||||
|
||||
echo "Splitting components intelligently..."
|
||||
output=$(python3 script/split_components_for_ci.py --components "$components" --directly-changed "$directly_changed" --batch-size 40 --output github)
|
||||
|
||||
echo "$output" >> $GITHUB_OUTPUT
|
||||
|
||||
test-build-components-split:
|
||||
name: Test components batch (${{ matrix.components }})
|
||||
runs-on: ubuntu-24.04
|
||||
needs:
|
||||
- common
|
||||
- determine-jobs
|
||||
- test-build-components-splitter
|
||||
if: github.event_name == 'pull_request' && fromJSON(needs.determine-jobs.outputs.component-test-count) > 0
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: ${{ (startsWith(github.base_ref, 'beta') || startsWith(github.base_ref, 'release')) && 8 || 4 }}
|
||||
matrix:
|
||||
components: ${{ fromJson(needs.determine-jobs.outputs.component-test-batches) }}
|
||||
components: ${{ fromJson(needs.test-build-components-splitter.outputs.matrix) }}
|
||||
steps:
|
||||
- name: Show disk space
|
||||
run: |
|
||||
@@ -941,6 +980,7 @@ jobs:
|
||||
- clang-tidy-nosplit
|
||||
- clang-tidy-split
|
||||
- determine-jobs
|
||||
- test-build-components-splitter
|
||||
- test-build-components-split
|
||||
- pre-commit-ci-lite
|
||||
- memory-impact-target-branch
|
||||
|
||||
@@ -1000,9 +1000,9 @@ message ListEntitiesClimateResponse {
|
||||
bool supports_action = 12; // Deprecated: use feature_flags
|
||||
repeated ClimateFanMode supported_fan_modes = 13 [(container_pointer_no_template) = "climate::ClimateFanModeMask"];
|
||||
repeated ClimateSwingMode supported_swing_modes = 14 [(container_pointer_no_template) = "climate::ClimateSwingModeMask"];
|
||||
repeated string supported_custom_fan_modes = 15 [(container_pointer_no_template) = "std::vector<const char *>"];
|
||||
repeated string supported_custom_fan_modes = 15 [(container_pointer) = "std::vector"];
|
||||
repeated ClimatePreset supported_presets = 16 [(container_pointer_no_template) = "climate::ClimatePresetMask"];
|
||||
repeated string supported_custom_presets = 17 [(container_pointer_no_template) = "std::vector<const char *>"];
|
||||
repeated string supported_custom_presets = 17 [(container_pointer) = "std::vector"];
|
||||
bool disabled_by_default = 18;
|
||||
string icon = 19 [(field_ifdef) = "USE_ENTITY_ICON"];
|
||||
EntityCategory entity_category = 20;
|
||||
|
||||
@@ -1179,14 +1179,14 @@ void ListEntitiesClimateResponse::encode(ProtoWriteBuffer buffer) const {
|
||||
for (const auto &it : *this->supported_swing_modes) {
|
||||
buffer.encode_uint32(14, static_cast<uint32_t>(it), true);
|
||||
}
|
||||
for (const char *it : *this->supported_custom_fan_modes) {
|
||||
buffer.encode_string(15, it, strlen(it), true);
|
||||
for (const auto &it : *this->supported_custom_fan_modes) {
|
||||
buffer.encode_string(15, it, true);
|
||||
}
|
||||
for (const auto &it : *this->supported_presets) {
|
||||
buffer.encode_uint32(16, static_cast<uint32_t>(it), true);
|
||||
}
|
||||
for (const char *it : *this->supported_custom_presets) {
|
||||
buffer.encode_string(17, it, strlen(it), true);
|
||||
for (const auto &it : *this->supported_custom_presets) {
|
||||
buffer.encode_string(17, it, true);
|
||||
}
|
||||
buffer.encode_bool(18, this->disabled_by_default);
|
||||
#ifdef USE_ENTITY_ICON
|
||||
@@ -1229,8 +1229,8 @@ void ListEntitiesClimateResponse::calculate_size(ProtoSize &size) const {
|
||||
}
|
||||
}
|
||||
if (!this->supported_custom_fan_modes->empty()) {
|
||||
for (const char *it : *this->supported_custom_fan_modes) {
|
||||
size.add_length_force(1, strlen(it));
|
||||
for (const auto &it : *this->supported_custom_fan_modes) {
|
||||
size.add_length_force(1, it.size());
|
||||
}
|
||||
}
|
||||
if (!this->supported_presets->empty()) {
|
||||
@@ -1239,8 +1239,8 @@ void ListEntitiesClimateResponse::calculate_size(ProtoSize &size) const {
|
||||
}
|
||||
}
|
||||
if (!this->supported_custom_presets->empty()) {
|
||||
for (const char *it : *this->supported_custom_presets) {
|
||||
size.add_length_force(2, strlen(it));
|
||||
for (const auto &it : *this->supported_custom_presets) {
|
||||
size.add_length_force(2, it.size());
|
||||
}
|
||||
}
|
||||
size.add_bool(2, this->disabled_by_default);
|
||||
|
||||
@@ -1384,9 +1384,9 @@ class ListEntitiesClimateResponse final : public InfoResponseProtoMessage {
|
||||
bool supports_action{false};
|
||||
const climate::ClimateFanModeMask *supported_fan_modes{};
|
||||
const climate::ClimateSwingModeMask *supported_swing_modes{};
|
||||
const std::vector<const char *> *supported_custom_fan_modes{};
|
||||
const std::vector<std::string> *supported_custom_fan_modes{};
|
||||
const climate::ClimatePresetMask *supported_presets{};
|
||||
const std::vector<const char *> *supported_custom_presets{};
|
||||
const std::vector<std::string> *supported_custom_presets{};
|
||||
float visual_current_temperature_step{0.0f};
|
||||
bool supports_current_humidity{false};
|
||||
bool supports_target_humidity{false};
|
||||
|
||||
@@ -50,13 +50,21 @@ class BedJetClimate : public climate::Climate, public BedJetClient, public Polli
|
||||
// Climate doesn't have a "TURBO" mode, but we can use the BOOST preset instead.
|
||||
climate::CLIMATE_PRESET_BOOST,
|
||||
});
|
||||
// String literals are stored in rodata and valid for program lifetime
|
||||
traits.set_supported_custom_presets({
|
||||
this->heating_mode_ == HEAT_MODE_EXTENDED ? "LTD HT" : "EXT HT",
|
||||
// We could fetch biodata from bedjet and set these names that way.
|
||||
// But then we have to invert the lookup in order to send the right preset.
|
||||
// For now, we can leave them as M1-3 to match the remote buttons.
|
||||
// EXT HT added to match remote button.
|
||||
"EXT HT",
|
||||
"M1",
|
||||
"M2",
|
||||
"M3",
|
||||
});
|
||||
if (this->heating_mode_ == HEAT_MODE_EXTENDED) {
|
||||
traits.add_supported_custom_preset("LTD HT");
|
||||
} else {
|
||||
traits.add_supported_custom_preset("EXT HT");
|
||||
}
|
||||
traits.set_visual_min_temperature(19.0);
|
||||
traits.set_visual_max_temperature(43.0);
|
||||
traits.set_visual_temperature_step(1.0);
|
||||
|
||||
@@ -387,8 +387,8 @@ void Climate::save_state_() {
|
||||
const auto &supported = traits.get_supported_custom_fan_modes();
|
||||
// std::vector maintains insertion order
|
||||
size_t i = 0;
|
||||
for (const char *mode : supported) {
|
||||
if (strcmp(mode, custom_fan_mode.value().c_str()) == 0) {
|
||||
for (const auto &mode : supported) {
|
||||
if (mode == custom_fan_mode) {
|
||||
state.custom_fan_mode = i;
|
||||
break;
|
||||
}
|
||||
@@ -404,8 +404,8 @@ void Climate::save_state_() {
|
||||
const auto &supported = traits.get_supported_custom_presets();
|
||||
// std::vector maintains insertion order
|
||||
size_t i = 0;
|
||||
for (const char *preset : supported) {
|
||||
if (strcmp(preset, custom_preset.value().c_str()) == 0) {
|
||||
for (const auto &preset : supported) {
|
||||
if (preset == custom_preset) {
|
||||
state.custom_preset = i;
|
||||
break;
|
||||
}
|
||||
@@ -527,7 +527,7 @@ ClimateCall ClimateDeviceRestoreState::to_call(Climate *climate) {
|
||||
if (this->uses_custom_fan_mode) {
|
||||
if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
|
||||
call.fan_mode_.reset();
|
||||
call.custom_fan_mode_ = std::string(traits.get_supported_custom_fan_modes()[this->custom_fan_mode]);
|
||||
call.custom_fan_mode_ = *std::next(traits.get_supported_custom_fan_modes().cbegin(), this->custom_fan_mode);
|
||||
}
|
||||
} else if (traits.supports_fan_mode(this->fan_mode)) {
|
||||
call.set_fan_mode(this->fan_mode);
|
||||
@@ -535,7 +535,7 @@ ClimateCall ClimateDeviceRestoreState::to_call(Climate *climate) {
|
||||
if (this->uses_custom_preset) {
|
||||
if (this->custom_preset < traits.get_supported_custom_presets().size()) {
|
||||
call.preset_.reset();
|
||||
call.custom_preset_ = std::string(traits.get_supported_custom_presets()[this->custom_preset]);
|
||||
call.custom_preset_ = *std::next(traits.get_supported_custom_presets().cbegin(), this->custom_preset);
|
||||
}
|
||||
} else if (traits.supports_preset(this->preset)) {
|
||||
call.set_preset(this->preset);
|
||||
@@ -562,7 +562,7 @@ void ClimateDeviceRestoreState::apply(Climate *climate) {
|
||||
if (this->uses_custom_fan_mode) {
|
||||
if (this->custom_fan_mode < traits.get_supported_custom_fan_modes().size()) {
|
||||
climate->fan_mode.reset();
|
||||
climate->custom_fan_mode = std::string(traits.get_supported_custom_fan_modes()[this->custom_fan_mode]);
|
||||
climate->custom_fan_mode = *std::next(traits.get_supported_custom_fan_modes().cbegin(), this->custom_fan_mode);
|
||||
}
|
||||
} else if (traits.supports_fan_mode(this->fan_mode)) {
|
||||
climate->fan_mode = this->fan_mode;
|
||||
@@ -571,7 +571,7 @@ void ClimateDeviceRestoreState::apply(Climate *climate) {
|
||||
if (this->uses_custom_preset) {
|
||||
if (this->custom_preset < traits.get_supported_custom_presets().size()) {
|
||||
climate->preset.reset();
|
||||
climate->custom_preset = std::string(traits.get_supported_custom_presets()[this->custom_preset]);
|
||||
climate->custom_preset = *std::next(traits.get_supported_custom_presets().cbegin(), this->custom_preset);
|
||||
}
|
||||
} else if (traits.supports_preset(this->preset)) {
|
||||
climate->preset = this->preset;
|
||||
@@ -656,8 +656,8 @@ void Climate::dump_traits_(const char *tag) {
|
||||
}
|
||||
if (!traits.get_supported_custom_fan_modes().empty()) {
|
||||
ESP_LOGCONFIG(tag, " Supported custom fan modes:");
|
||||
for (const char *s : traits.get_supported_custom_fan_modes())
|
||||
ESP_LOGCONFIG(tag, " - %s", s);
|
||||
for (const std::string &s : traits.get_supported_custom_fan_modes())
|
||||
ESP_LOGCONFIG(tag, " - %s", s.c_str());
|
||||
}
|
||||
if (!traits.get_supported_presets().empty()) {
|
||||
ESP_LOGCONFIG(tag, " Supported presets:");
|
||||
@@ -666,8 +666,8 @@ void Climate::dump_traits_(const char *tag) {
|
||||
}
|
||||
if (!traits.get_supported_custom_presets().empty()) {
|
||||
ESP_LOGCONFIG(tag, " Supported custom presets:");
|
||||
for (const char *s : traits.get_supported_custom_presets())
|
||||
ESP_LOGCONFIG(tag, " - %s", s);
|
||||
for (const std::string &s : traits.get_supported_custom_presets())
|
||||
ESP_LOGCONFIG(tag, " - %s", s.c_str());
|
||||
}
|
||||
if (!traits.get_supported_swing_modes().empty()) {
|
||||
ESP_LOGCONFIG(tag, " Supported swing modes:");
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include "climate_mode.h"
|
||||
#include "esphome/core/finite_set_mask.h"
|
||||
@@ -19,6 +18,16 @@ using ClimateSwingModeMask =
|
||||
FiniteSetMask<ClimateSwingMode, DefaultBitPolicy<ClimateSwingMode, CLIMATE_SWING_HORIZONTAL + 1>>;
|
||||
using ClimatePresetMask = FiniteSetMask<ClimatePreset, DefaultBitPolicy<ClimatePreset, CLIMATE_PRESET_ACTIVITY + 1>>;
|
||||
|
||||
// Lightweight linear search for small vectors (1-20 items)
|
||||
// Avoids std::find template overhead
|
||||
template<typename T> inline bool vector_contains(const std::vector<T> &vec, const T &value) {
|
||||
for (const auto &item : vec) {
|
||||
if (item == value)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** This class contains all static data for climate devices.
|
||||
*
|
||||
* All climate devices must support these features:
|
||||
@@ -119,46 +128,46 @@ class ClimateTraits {
|
||||
|
||||
void set_supported_fan_modes(ClimateFanModeMask modes) { this->supported_fan_modes_ = modes; }
|
||||
void add_supported_fan_mode(ClimateFanMode mode) { this->supported_fan_modes_.insert(mode); }
|
||||
void add_supported_custom_fan_mode(const std::string &mode) { this->supported_custom_fan_modes_.push_back(mode); }
|
||||
bool supports_fan_mode(ClimateFanMode fan_mode) const { return this->supported_fan_modes_.count(fan_mode); }
|
||||
bool get_supports_fan_modes() const {
|
||||
return !this->supported_fan_modes_.empty() || !this->supported_custom_fan_modes_.empty();
|
||||
}
|
||||
const ClimateFanModeMask &get_supported_fan_modes() const { return this->supported_fan_modes_; }
|
||||
|
||||
void set_supported_custom_fan_modes(std::initializer_list<const char *> modes) {
|
||||
void set_supported_custom_fan_modes(std::vector<std::string> supported_custom_fan_modes) {
|
||||
this->supported_custom_fan_modes_ = std::move(supported_custom_fan_modes);
|
||||
}
|
||||
void set_supported_custom_fan_modes(std::initializer_list<std::string> modes) {
|
||||
this->supported_custom_fan_modes_ = modes;
|
||||
}
|
||||
void set_supported_custom_fan_modes(const std::vector<const char *> &modes) {
|
||||
this->supported_custom_fan_modes_ = modes;
|
||||
template<size_t N> void set_supported_custom_fan_modes(const char *const (&modes)[N]) {
|
||||
this->supported_custom_fan_modes_.assign(modes, modes + N);
|
||||
}
|
||||
const std::vector<const char *> &get_supported_custom_fan_modes() const { return this->supported_custom_fan_modes_; }
|
||||
const std::vector<std::string> &get_supported_custom_fan_modes() const { return this->supported_custom_fan_modes_; }
|
||||
bool supports_custom_fan_mode(const std::string &custom_fan_mode) const {
|
||||
for (const char *mode : this->supported_custom_fan_modes_) {
|
||||
if (strcmp(mode, custom_fan_mode.c_str()) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return vector_contains(this->supported_custom_fan_modes_, custom_fan_mode);
|
||||
}
|
||||
|
||||
void set_supported_presets(ClimatePresetMask presets) { this->supported_presets_ = presets; }
|
||||
void add_supported_preset(ClimatePreset preset) { this->supported_presets_.insert(preset); }
|
||||
void add_supported_custom_preset(const std::string &preset) { this->supported_custom_presets_.push_back(preset); }
|
||||
bool supports_preset(ClimatePreset preset) const { return this->supported_presets_.count(preset); }
|
||||
bool get_supports_presets() const { return !this->supported_presets_.empty(); }
|
||||
const ClimatePresetMask &get_supported_presets() const { return this->supported_presets_; }
|
||||
|
||||
void set_supported_custom_presets(std::initializer_list<const char *> presets) {
|
||||
void set_supported_custom_presets(std::vector<std::string> supported_custom_presets) {
|
||||
this->supported_custom_presets_ = std::move(supported_custom_presets);
|
||||
}
|
||||
void set_supported_custom_presets(std::initializer_list<std::string> presets) {
|
||||
this->supported_custom_presets_ = presets;
|
||||
}
|
||||
void set_supported_custom_presets(const std::vector<const char *> &presets) {
|
||||
this->supported_custom_presets_ = presets;
|
||||
template<size_t N> void set_supported_custom_presets(const char *const (&presets)[N]) {
|
||||
this->supported_custom_presets_.assign(presets, presets + N);
|
||||
}
|
||||
const std::vector<const char *> &get_supported_custom_presets() const { return this->supported_custom_presets_; }
|
||||
const std::vector<std::string> &get_supported_custom_presets() const { return this->supported_custom_presets_; }
|
||||
bool supports_custom_preset(const std::string &custom_preset) const {
|
||||
for (const char *preset : this->supported_custom_presets_) {
|
||||
if (strcmp(preset, custom_preset.c_str()) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return vector_contains(this->supported_custom_presets_, custom_preset);
|
||||
}
|
||||
|
||||
void set_supported_swing_modes(ClimateSwingModeMask modes) { this->supported_swing_modes_ = modes; }
|
||||
@@ -230,11 +239,8 @@ class ClimateTraits {
|
||||
climate::ClimateFanModeMask supported_fan_modes_;
|
||||
climate::ClimateSwingModeMask supported_swing_modes_;
|
||||
climate::ClimatePresetMask supported_presets_;
|
||||
// Store const char* pointers to avoid std::string overhead
|
||||
// Pointers must remain valid for traits lifetime (typically string literals in rodata,
|
||||
// or pointers to strings with sufficient lifetime like member variables)
|
||||
std::vector<const char *> supported_custom_fan_modes_;
|
||||
std::vector<const char *> supported_custom_presets_;
|
||||
std::vector<std::string> supported_custom_fan_modes_;
|
||||
std::vector<std::string> supported_custom_presets_;
|
||||
};
|
||||
|
||||
} // namespace climate
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#include "e131_addressable_light_effect.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace esphome {
|
||||
namespace e131 {
|
||||
|
||||
@@ -78,14 +76,14 @@ void E131Component::loop() {
|
||||
}
|
||||
|
||||
void E131Component::add_effect(E131AddressableLightEffect *light_effect) {
|
||||
if (std::find(light_effects_.begin(), light_effects_.end(), light_effect) != light_effects_.end()) {
|
||||
if (light_effects_.count(light_effect)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Registering '%s' for universes %d-%d.", light_effect->get_name(), light_effect->get_first_universe(),
|
||||
light_effect->get_last_universe());
|
||||
|
||||
light_effects_.push_back(light_effect);
|
||||
light_effects_.insert(light_effect);
|
||||
|
||||
for (auto universe = light_effect->get_first_universe(); universe <= light_effect->get_last_universe(); ++universe) {
|
||||
join_(universe);
|
||||
@@ -93,17 +91,14 @@ void E131Component::add_effect(E131AddressableLightEffect *light_effect) {
|
||||
}
|
||||
|
||||
void E131Component::remove_effect(E131AddressableLightEffect *light_effect) {
|
||||
auto it = std::find(light_effects_.begin(), light_effects_.end(), light_effect);
|
||||
if (it == light_effects_.end()) {
|
||||
if (!light_effects_.count(light_effect)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "Unregistering '%s' for universes %d-%d.", light_effect->get_name(), light_effect->get_first_universe(),
|
||||
light_effect->get_last_universe());
|
||||
|
||||
// Swap with last element and pop for O(1) removal (order doesn't matter)
|
||||
*it = light_effects_.back();
|
||||
light_effects_.pop_back();
|
||||
light_effects_.erase(light_effect);
|
||||
|
||||
for (auto universe = light_effect->get_first_universe(); universe <= light_effect->get_last_universe(); ++universe) {
|
||||
leave_(universe);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <cinttypes>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace esphome {
|
||||
@@ -46,8 +47,9 @@ class E131Component : public esphome::Component {
|
||||
|
||||
E131ListenMethod listen_method_{E131_MULTICAST};
|
||||
std::unique_ptr<socket::Socket> socket_;
|
||||
std::vector<E131AddressableLightEffect *> light_effects_;
|
||||
std::set<E131AddressableLightEffect *> light_effects_;
|
||||
std::map<int, int> universe_consumers_;
|
||||
std::map<int, E131Packet> universe_packets_;
|
||||
};
|
||||
|
||||
} // namespace e131
|
||||
|
||||
@@ -94,8 +94,6 @@ async def to_code(config):
|
||||
)
|
||||
use_interrupt = False
|
||||
|
||||
cg.add(var.set_use_interrupt(use_interrupt))
|
||||
if use_interrupt:
|
||||
cg.add(var.set_interrupt_type(config[CONF_INTERRUPT_TYPE]))
|
||||
else:
|
||||
# Only generate call when disabling interrupts (default is true)
|
||||
cg.add(var.set_use_interrupt(use_interrupt))
|
||||
|
||||
@@ -125,7 +125,7 @@ lv_img_dsc_t *Image::get_lv_img_dsc() {
|
||||
|
||||
case IMAGE_TYPE_RGB:
|
||||
#if LV_COLOR_DEPTH == 32
|
||||
switch (this->transparency_) {
|
||||
switch (this->transparent_) {
|
||||
case TRANSPARENCY_ALPHA_CHANNEL:
|
||||
this->dsc_.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA;
|
||||
break;
|
||||
@@ -156,8 +156,7 @@ lv_img_dsc_t *Image::get_lv_img_dsc() {
|
||||
break;
|
||||
}
|
||||
#else
|
||||
this->dsc_.header.cf =
|
||||
this->transparency_ == TRANSPARENCY_ALPHA_CHANNEL ? LV_IMG_CF_RGB565A8 : LV_IMG_CF_RGB565;
|
||||
this->dsc_.header.cf = this->transparent_ == TRANSPARENCY_ALPHA_CHANNEL ? LV_IMG_CF_RGB565A8 : LV_IMG_CF_RGB565;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ from ..lv_validation import (
|
||||
pixels,
|
||||
size,
|
||||
)
|
||||
from ..lvcode import LocalVariable, lv, lv_assign, lv_expr
|
||||
from ..lvcode import LocalVariable, lv, lv_assign
|
||||
from ..schemas import STYLE_PROPS, STYLE_REMAP, TEXT_SCHEMA, point_schema
|
||||
from ..types import LvType, ObjUpdateAction, WidgetType
|
||||
from . import Widget, get_widgets
|
||||
@@ -70,18 +70,15 @@ class CanvasType(WidgetType):
|
||||
width = config[CONF_WIDTH]
|
||||
height = config[CONF_HEIGHT]
|
||||
use_alpha = "_ALPHA" if config[CONF_TRANSPARENT] else ""
|
||||
buf_size = literal(
|
||||
f"LV_CANVAS_BUF_SIZE_TRUE_COLOR{use_alpha}({width}, {height})"
|
||||
lv.canvas_set_buffer(
|
||||
w.obj,
|
||||
lv.custom_mem_alloc(
|
||||
literal(f"LV_CANVAS_BUF_SIZE_TRUE_COLOR{use_alpha}({width}, {height})")
|
||||
),
|
||||
width,
|
||||
height,
|
||||
literal(f"LV_IMG_CF_TRUE_COLOR{use_alpha}"),
|
||||
)
|
||||
with LocalVariable("buf", cg.void, lv_expr.custom_mem_alloc(buf_size)) as buf:
|
||||
cg.add(cg.RawExpression(f"memset({buf}, 0, {buf_size});"))
|
||||
lv.canvas_set_buffer(
|
||||
w.obj,
|
||||
buf,
|
||||
width,
|
||||
height,
|
||||
literal(f"LV_IMG_CF_TRUE_COLOR{use_alpha}"),
|
||||
)
|
||||
|
||||
|
||||
canvas_spec = CanvasType()
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace midea {
|
||||
namespace ac {
|
||||
|
||||
const char *const Constants::TAG = "midea";
|
||||
const char *const Constants::FREEZE_PROTECTION = "freeze protection";
|
||||
const char *const Constants::SILENT = "silent";
|
||||
const char *const Constants::TURBO = "turbo";
|
||||
const std::string Constants::FREEZE_PROTECTION = "freeze protection";
|
||||
const std::string Constants::SILENT = "silent";
|
||||
const std::string Constants::TURBO = "turbo";
|
||||
|
||||
ClimateMode Converters::to_climate_mode(MideaMode mode) {
|
||||
switch (mode) {
|
||||
@@ -108,7 +108,7 @@ bool Converters::is_custom_midea_fan_mode(MideaFanMode mode) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *Converters::to_custom_climate_fan_mode(MideaFanMode mode) {
|
||||
const std::string &Converters::to_custom_climate_fan_mode(MideaFanMode mode) {
|
||||
switch (mode) {
|
||||
case MideaFanMode::FAN_SILENT:
|
||||
return Constants::SILENT;
|
||||
@@ -151,7 +151,7 @@ ClimatePreset Converters::to_climate_preset(MideaPreset preset) {
|
||||
|
||||
bool Converters::is_custom_midea_preset(MideaPreset preset) { return preset == MideaPreset::PRESET_FREEZE_PROTECTION; }
|
||||
|
||||
const char *Converters::to_custom_climate_preset(MideaPreset preset) { return Constants::FREEZE_PROTECTION; }
|
||||
const std::string &Converters::to_custom_climate_preset(MideaPreset preset) { return Constants::FREEZE_PROTECTION; }
|
||||
|
||||
MideaPreset Converters::to_midea_preset(const std::string &preset) { return MideaPreset::PRESET_FREEZE_PROTECTION; }
|
||||
|
||||
@@ -169,7 +169,7 @@ void Converters::to_climate_traits(ClimateTraits &traits, const dudanov::midea::
|
||||
if (capabilities.supportEcoPreset())
|
||||
traits.add_supported_preset(ClimatePreset::CLIMATE_PRESET_ECO);
|
||||
if (capabilities.supportFrostProtectionPreset())
|
||||
traits.set_supported_custom_presets({Constants::FREEZE_PROTECTION});
|
||||
traits.add_supported_custom_preset(Constants::FREEZE_PROTECTION);
|
||||
}
|
||||
|
||||
} // namespace ac
|
||||
|
||||
@@ -20,9 +20,9 @@ using MideaPreset = dudanov::midea::ac::Preset;
|
||||
class Constants {
|
||||
public:
|
||||
static const char *const TAG;
|
||||
static const char *const FREEZE_PROTECTION;
|
||||
static const char *const SILENT;
|
||||
static const char *const TURBO;
|
||||
static const std::string FREEZE_PROTECTION;
|
||||
static const std::string SILENT;
|
||||
static const std::string TURBO;
|
||||
};
|
||||
|
||||
class Converters {
|
||||
@@ -35,12 +35,12 @@ class Converters {
|
||||
static MideaPreset to_midea_preset(const std::string &preset);
|
||||
static bool is_custom_midea_preset(MideaPreset preset);
|
||||
static ClimatePreset to_climate_preset(MideaPreset preset);
|
||||
static const char *to_custom_climate_preset(MideaPreset preset);
|
||||
static const std::string &to_custom_climate_preset(MideaPreset preset);
|
||||
static MideaFanMode to_midea_fan_mode(ClimateFanMode fan_mode);
|
||||
static MideaFanMode to_midea_fan_mode(const std::string &fan_mode);
|
||||
static bool is_custom_midea_fan_mode(MideaFanMode fan_mode);
|
||||
static ClimateFanMode to_climate_fan_mode(MideaFanMode fan_mode);
|
||||
static const char *to_custom_climate_fan_mode(MideaFanMode fan_mode);
|
||||
static const std::string &to_custom_climate_fan_mode(MideaFanMode fan_mode);
|
||||
static void to_climate_traits(ClimateTraits &traits, const dudanov::midea::ac::Capabilities &capabilities);
|
||||
};
|
||||
|
||||
|
||||
@@ -84,10 +84,8 @@ ClimateTraits AirConditioner::traits() {
|
||||
traits.set_supported_modes(this->supported_modes_);
|
||||
traits.set_supported_swing_modes(this->supported_swing_modes_);
|
||||
traits.set_supported_presets(this->supported_presets_);
|
||||
if (!this->supported_custom_presets_.empty())
|
||||
traits.set_supported_custom_presets(this->supported_custom_presets_);
|
||||
if (!this->supported_custom_fan_modes_.empty())
|
||||
traits.set_supported_custom_fan_modes(this->supported_custom_fan_modes_);
|
||||
traits.set_supported_custom_presets(this->supported_custom_presets_);
|
||||
traits.set_supported_custom_fan_modes(this->supported_custom_fan_modes_);
|
||||
/* + MINIMAL SET OF CAPABILITIES */
|
||||
traits.add_supported_fan_mode(ClimateFanMode::CLIMATE_FAN_AUTO);
|
||||
traits.add_supported_fan_mode(ClimateFanMode::CLIMATE_FAN_LOW);
|
||||
|
||||
@@ -46,8 +46,8 @@ class AirConditioner : public ApplianceBase<dudanov::midea::ac::AirConditioner>,
|
||||
void set_supported_modes(ClimateModeMask modes) { this->supported_modes_ = modes; }
|
||||
void set_supported_swing_modes(ClimateSwingModeMask modes) { this->supported_swing_modes_ = modes; }
|
||||
void set_supported_presets(ClimatePresetMask presets) { this->supported_presets_ = presets; }
|
||||
void set_custom_presets(std::initializer_list<const char *> presets) { this->supported_custom_presets_ = presets; }
|
||||
void set_custom_fan_modes(std::initializer_list<const char *> modes) { this->supported_custom_fan_modes_ = modes; }
|
||||
void set_custom_presets(const std::vector<std::string> &presets) { this->supported_custom_presets_ = presets; }
|
||||
void set_custom_fan_modes(const std::vector<std::string> &modes) { this->supported_custom_fan_modes_ = modes; }
|
||||
|
||||
protected:
|
||||
void control(const ClimateCall &call) override;
|
||||
@@ -55,8 +55,8 @@ class AirConditioner : public ApplianceBase<dudanov::midea::ac::AirConditioner>,
|
||||
ClimateModeMask supported_modes_{};
|
||||
ClimateSwingModeMask supported_swing_modes_{};
|
||||
ClimatePresetMask supported_presets_{};
|
||||
std::vector<const char *> supported_custom_presets_{};
|
||||
std::vector<const char *> supported_custom_fan_modes_{};
|
||||
std::vector<std::string> supported_custom_presets_{};
|
||||
std::vector<std::string> supported_custom_fan_modes_{};
|
||||
Sensor *outdoor_sensor_{nullptr};
|
||||
Sensor *humidity_sensor_{nullptr};
|
||||
Sensor *power_sensor_{nullptr};
|
||||
|
||||
@@ -9,7 +9,10 @@ namespace template_ {
|
||||
|
||||
class TemplateBinarySensor : public Component, public binary_sensor::BinarySensor {
|
||||
public:
|
||||
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }
|
||||
template<typename F> void set_template(F &&f) {
|
||||
this->f_.set(std::forward<F>(f));
|
||||
this->enable_loop();
|
||||
}
|
||||
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
|
||||
@@ -18,8 +18,14 @@ class TemplateCover : public cover::Cover, public Component {
|
||||
public:
|
||||
TemplateCover();
|
||||
|
||||
template<typename F> void set_state_lambda(F &&f) { this->state_f_.set(std::forward<F>(f)); }
|
||||
template<typename F> void set_tilt_lambda(F &&f) { this->tilt_f_.set(std::forward<F>(f)); }
|
||||
template<typename F> void set_state_lambda(F &&f) {
|
||||
this->state_f_.set(std::forward<F>(f));
|
||||
this->enable_loop();
|
||||
}
|
||||
template<typename F> void set_tilt_lambda(F &&f) {
|
||||
this->tilt_f_.set(std::forward<F>(f));
|
||||
this->enable_loop();
|
||||
}
|
||||
Trigger<> *get_open_trigger() const;
|
||||
Trigger<> *get_close_trigger() const;
|
||||
Trigger<> *get_stop_trigger() const;
|
||||
|
||||
@@ -11,11 +11,6 @@ static const char *const TAG = "template.lock";
|
||||
TemplateLock::TemplateLock()
|
||||
: lock_trigger_(new Trigger<>()), unlock_trigger_(new Trigger<>()), open_trigger_(new Trigger<>()) {}
|
||||
|
||||
void TemplateLock::setup() {
|
||||
if (!this->f_.has_value())
|
||||
this->disable_loop();
|
||||
}
|
||||
|
||||
void TemplateLock::loop() {
|
||||
auto val = this->f_();
|
||||
if (val.has_value()) {
|
||||
|
||||
@@ -12,10 +12,12 @@ class TemplateLock : public lock::Lock, public Component {
|
||||
public:
|
||||
TemplateLock();
|
||||
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
||||
template<typename F> void set_state_lambda(F &&f) { this->f_.set(std::forward<F>(f)); }
|
||||
template<typename F> void set_state_lambda(F &&f) {
|
||||
this->f_.set(std::forward<F>(f));
|
||||
this->enable_loop();
|
||||
}
|
||||
Trigger<> *get_lock_trigger() const;
|
||||
Trigger<> *get_unlock_trigger() const;
|
||||
Trigger<> *get_open_trigger() const;
|
||||
|
||||
@@ -15,7 +15,10 @@ class TemplateSwitch : public switch_::Switch, public Component {
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
|
||||
template<typename F> void set_state_lambda(F &&f) { this->f_.set(std::forward<F>(f)); }
|
||||
template<typename F> void set_state_lambda(F &&f) {
|
||||
this->f_.set(std::forward<F>(f));
|
||||
this->enable_loop();
|
||||
}
|
||||
Trigger<> *get_turn_on_trigger() const;
|
||||
Trigger<> *get_turn_off_trigger() const;
|
||||
void set_optimistic(bool optimistic);
|
||||
|
||||
@@ -18,7 +18,10 @@ class TemplateValve : public valve::Valve, public Component {
|
||||
public:
|
||||
TemplateValve();
|
||||
|
||||
template<typename F> void set_state_lambda(F &&f) { this->state_f_.set(std::forward<F>(f)); }
|
||||
template<typename F> void set_state_lambda(F &&f) {
|
||||
this->state_f_.set(std::forward<F>(f));
|
||||
this->enable_loop();
|
||||
}
|
||||
Trigger<> *get_open_trigger() const;
|
||||
Trigger<> *get_close_trigger() const;
|
||||
Trigger<> *get_stop_trigger() const;
|
||||
|
||||
@@ -9,8 +9,6 @@ from esphome.const import (
|
||||
CONF_COOL_DEADBAND,
|
||||
CONF_COOL_MODE,
|
||||
CONF_COOL_OVERRUN,
|
||||
CONF_CUSTOM_FAN_MODES,
|
||||
CONF_CUSTOM_PRESETS,
|
||||
CONF_DEFAULT_MODE,
|
||||
CONF_DEFAULT_TARGET_TEMPERATURE_HIGH,
|
||||
CONF_DEFAULT_TARGET_TEMPERATURE_LOW,
|
||||
@@ -660,8 +658,6 @@ CONFIG_SCHEMA = cv.All(
|
||||
}
|
||||
),
|
||||
cv.Optional(CONF_PRESET): cv.ensure_list(PRESET_CONFIG_SCHEMA),
|
||||
cv.Optional(CONF_CUSTOM_FAN_MODES): cv.ensure_list(cv.string_strict),
|
||||
cv.Optional(CONF_CUSTOM_PRESETS): cv.ensure_list(cv.string_strict),
|
||||
cv.Optional(CONF_ON_BOOT_RESTORE_FROM): validate_on_boot_restore_from,
|
||||
cv.Optional(CONF_PRESET_CHANGE): automation.validate_automation(
|
||||
single=True
|
||||
@@ -1012,22 +1008,3 @@ async def to_code(config):
|
||||
await automation.build_automation(
|
||||
var.get_preset_change_trigger(), [], config[CONF_PRESET_CHANGE]
|
||||
)
|
||||
|
||||
# Collect custom preset names from preset map (non-standard) and custom_presets list
|
||||
custom_preset_names = [
|
||||
preset_config[CONF_NAME]
|
||||
for preset_config in config.get(CONF_PRESET, [])
|
||||
if preset_config[CONF_NAME].upper() not in climate.CLIMATE_PRESETS
|
||||
]
|
||||
custom_preset_names.extend(config.get(CONF_CUSTOM_PRESETS, []))
|
||||
if custom_preset_names:
|
||||
cg.add(var.set_custom_presets(custom_preset_names))
|
||||
|
||||
# Collect custom fan modes (filter out standard enum fan modes)
|
||||
custom_fan_modes = [
|
||||
mode
|
||||
for mode in config.get(CONF_CUSTOM_FAN_MODES, [])
|
||||
if mode.upper() not in climate.CLIMATE_FAN_MODES
|
||||
]
|
||||
if custom_fan_modes:
|
||||
cg.add(var.set_custom_fan_modes(custom_fan_modes))
|
||||
|
||||
@@ -321,12 +321,8 @@ climate::ClimateTraits ThermostatClimate::traits() {
|
||||
for (auto &it : this->preset_config_) {
|
||||
traits.add_supported_preset(it.first);
|
||||
}
|
||||
// Custom presets and fan modes are set directly from Python (includes both map entries and additional lists)
|
||||
if (!this->additional_custom_presets_.empty()) {
|
||||
traits.set_supported_custom_presets(this->additional_custom_presets_);
|
||||
}
|
||||
if (!this->additional_custom_fan_modes_.empty()) {
|
||||
traits.set_supported_custom_fan_modes(this->additional_custom_fan_modes_);
|
||||
for (auto &it : this->custom_preset_config_) {
|
||||
traits.add_supported_custom_preset(it.first);
|
||||
}
|
||||
return traits;
|
||||
}
|
||||
@@ -1252,14 +1248,6 @@ void ThermostatClimate::set_custom_preset_config(const std::string &name,
|
||||
this->custom_preset_config_[name] = config;
|
||||
}
|
||||
|
||||
void ThermostatClimate::set_custom_fan_modes(std::initializer_list<const char *> custom_fan_modes) {
|
||||
this->additional_custom_fan_modes_ = custom_fan_modes;
|
||||
}
|
||||
|
||||
void ThermostatClimate::set_custom_presets(std::initializer_list<const char *> custom_presets) {
|
||||
this->additional_custom_presets_ = custom_presets;
|
||||
}
|
||||
|
||||
ThermostatClimate::ThermostatClimate()
|
||||
: cool_action_trigger_(new Trigger<>()),
|
||||
supplemental_cool_action_trigger_(new Trigger<>()),
|
||||
|
||||
@@ -133,8 +133,6 @@ class ThermostatClimate : public climate::Climate, public Component {
|
||||
|
||||
void set_preset_config(climate::ClimatePreset preset, const ThermostatClimateTargetTempConfig &config);
|
||||
void set_custom_preset_config(const std::string &name, const ThermostatClimateTargetTempConfig &config);
|
||||
void set_custom_fan_modes(std::initializer_list<const char *> custom_fan_modes);
|
||||
void set_custom_presets(std::initializer_list<const char *> custom_presets);
|
||||
|
||||
Trigger<> *get_cool_action_trigger() const;
|
||||
Trigger<> *get_supplemental_cool_action_trigger() const;
|
||||
@@ -539,10 +537,6 @@ class ThermostatClimate : public climate::Climate, public Component {
|
||||
std::map<climate::ClimatePreset, ThermostatClimateTargetTempConfig> preset_config_{};
|
||||
/// The set of custom preset configurations this thermostat supports (eg. "My Custom Preset")
|
||||
std::map<std::string, ThermostatClimateTargetTempConfig> custom_preset_config_{};
|
||||
/// Additional custom fan modes to expose (beyond those with actions)
|
||||
std::vector<const char *> additional_custom_fan_modes_{};
|
||||
/// Additional custom presets to expose (beyond those in custom_preset_config_)
|
||||
std::vector<const char *> additional_custom_presets_{};
|
||||
};
|
||||
|
||||
} // namespace thermostat
|
||||
|
||||
@@ -1,51 +1,120 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <concepts>
|
||||
#include "esphome/core/optional.h"
|
||||
|
||||
namespace esphome {
|
||||
|
||||
/** Lightweight wrapper for template platform lambdas (stateless function pointers only).
|
||||
/** Helper class for template platforms that stores either a stateless lambda (function pointer)
|
||||
* or a stateful lambda (std::function pointer).
|
||||
*
|
||||
* This optimizes template platforms by storing only a function pointer (4 bytes on ESP32)
|
||||
* instead of std::function (16-32 bytes).
|
||||
* This provides backward compatibility with PR #11555 while maintaining the optimization:
|
||||
* - Stateless lambdas (no capture) → function pointer (4 bytes on ESP32)
|
||||
* - Stateful lambdas (with capture) → pointer to std::function (4 bytes on ESP32)
|
||||
* Total size: enum (1 byte) + union (4 bytes) + padding = 8 bytes (same as PR #11555)
|
||||
*
|
||||
* IMPORTANT: This only supports stateless lambdas (no captures). The set_template() method
|
||||
* is an internal API used by YAML codegen, not intended for external use.
|
||||
*
|
||||
* Lambdas must return optional<T> to support the pattern:
|
||||
* return {}; // Don't publish a value
|
||||
* Both lambda types must return optional<T> (as YAML codegen does) to support the pattern:
|
||||
* return {}; // Don't publish a value
|
||||
* return 42.0; // Publish this value
|
||||
*
|
||||
* operator() returns optional<T>, returning nullopt when no lambda is set (nullptr check).
|
||||
* operator() returns optional<T>, returning nullopt when no lambda is set (type == NONE).
|
||||
* This eliminates redundant "is lambda set" checks by reusing optional's discriminator.
|
||||
*
|
||||
* @tparam T The return type (e.g., float for sensor values)
|
||||
* @tparam T The return type (e.g., float for TemplateLambda<optional<float>>)
|
||||
* @tparam Args Optional arguments for the lambda
|
||||
*/
|
||||
template<typename T, typename... Args> class TemplateLambda {
|
||||
public:
|
||||
TemplateLambda() : f_(nullptr) {}
|
||||
TemplateLambda() : type_(NONE) {}
|
||||
|
||||
/** Set the lambda function pointer.
|
||||
* INTERNAL API: Only for use by YAML codegen.
|
||||
* Only stateless lambdas (no captures) are supported.
|
||||
*/
|
||||
void set(optional<T> (*f)(Args...)) { this->f_ = f; }
|
||||
|
||||
/** Check if a lambda is set */
|
||||
bool has_value() const { return this->f_ != nullptr; }
|
||||
|
||||
/** Call the lambda, returning nullopt if no lambda is set */
|
||||
optional<T> operator()(Args &&...args) {
|
||||
if (this->f_ == nullptr)
|
||||
return nullopt;
|
||||
return this->f_(std::forward<Args>(args)...);
|
||||
// For stateless lambdas: use function pointer
|
||||
template<typename F>
|
||||
requires std::invocable<F, Args...> && std::convertible_to < F, optional<T>(*)
|
||||
(Args...) > void set(F f) {
|
||||
this->reset_();
|
||||
this->type_ = STATELESS_LAMBDA;
|
||||
this->stateless_f_ = f; // Implicit conversion to function pointer
|
||||
}
|
||||
|
||||
/** Alias for operator() for compatibility */
|
||||
optional<T> call(Args &&...args) { return (*this)(std::forward<Args>(args)...); }
|
||||
// For stateful lambdas: use std::function pointer
|
||||
template<typename F>
|
||||
requires std::invocable<F, Args...> &&
|
||||
(!std::convertible_to<F, optional<T> (*)(Args...)>) &&std::convertible_to<std::invoke_result_t<F, Args...>,
|
||||
optional<T>> void set(F &&f) {
|
||||
this->reset_();
|
||||
this->type_ = LAMBDA;
|
||||
this->f_ = new std::function<optional<T>(Args...)>(std::forward<F>(f));
|
||||
}
|
||||
|
||||
~TemplateLambda() { this->reset_(); }
|
||||
|
||||
// Copy constructor
|
||||
TemplateLambda(const TemplateLambda &) = delete;
|
||||
TemplateLambda &operator=(const TemplateLambda &) = delete;
|
||||
|
||||
// Move constructor
|
||||
TemplateLambda(TemplateLambda &&other) noexcept : type_(other.type_) {
|
||||
if (type_ == LAMBDA) {
|
||||
this->f_ = other.f_;
|
||||
other.f_ = nullptr;
|
||||
} else if (type_ == STATELESS_LAMBDA) {
|
||||
this->stateless_f_ = other.stateless_f_;
|
||||
}
|
||||
other.type_ = NONE;
|
||||
}
|
||||
|
||||
TemplateLambda &operator=(TemplateLambda &&other) noexcept {
|
||||
if (this != &other) {
|
||||
this->reset_();
|
||||
this->type_ = other.type_;
|
||||
if (type_ == LAMBDA) {
|
||||
this->f_ = other.f_;
|
||||
other.f_ = nullptr;
|
||||
} else if (type_ == STATELESS_LAMBDA) {
|
||||
this->stateless_f_ = other.stateless_f_;
|
||||
}
|
||||
other.type_ = NONE;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool has_value() const { return this->type_ != NONE; }
|
||||
|
||||
// Returns optional<T>, returning nullopt if no lambda is set
|
||||
optional<T> operator()(Args... args) {
|
||||
switch (this->type_) {
|
||||
case STATELESS_LAMBDA:
|
||||
return this->stateless_f_(args...); // Direct function pointer call
|
||||
case LAMBDA:
|
||||
return (*this->f_)(args...); // std::function call via pointer
|
||||
case NONE:
|
||||
default:
|
||||
return nullopt; // No lambda set
|
||||
}
|
||||
}
|
||||
|
||||
optional<T> call(Args... args) { return (*this)(args...); }
|
||||
|
||||
protected:
|
||||
optional<T> (*f_)(Args...); // Function pointer (4 bytes on ESP32)
|
||||
void reset_() {
|
||||
if (this->type_ == LAMBDA) {
|
||||
delete this->f_;
|
||||
this->f_ = nullptr;
|
||||
}
|
||||
this->type_ = NONE;
|
||||
}
|
||||
|
||||
enum : uint8_t {
|
||||
NONE,
|
||||
STATELESS_LAMBDA,
|
||||
LAMBDA,
|
||||
} type_;
|
||||
|
||||
union {
|
||||
optional<T> (*stateless_f_)(Args...); // Function pointer (4 bytes on ESP32)
|
||||
std::function<optional<T>(Args...)> *f_; // Pointer to std::function (4 bytes on ESP32)
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace esphome
|
||||
|
||||
@@ -1610,9 +1610,8 @@ class RepeatedTypeInfo(TypeInfo):
|
||||
# Other types need the actual value
|
||||
# Special handling for const char* elements
|
||||
if self._use_pointer and "const char" in self._container_no_template:
|
||||
field_id_size = self.calculate_field_id_size()
|
||||
o += f" for (const char *it : {container_ref}) {{\n"
|
||||
o += f" size.add_length_force({field_id_size}, strlen(it));\n"
|
||||
o += " size.add_length_force(1, strlen(it));\n"
|
||||
else:
|
||||
auto_ref = "" if self._ti_is_bool else "&"
|
||||
o += f" for (const auto {auto_ref}it : {container_ref}) {{\n"
|
||||
|
||||
@@ -43,14 +43,12 @@ from enum import StrEnum
|
||||
from functools import cache
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
from helpers import (
|
||||
CPP_FILE_EXTENSIONS,
|
||||
ESPHOME_TESTS_COMPONENTS_PATH,
|
||||
PYTHON_FILE_EXTENSIONS,
|
||||
changed_files,
|
||||
core_changed,
|
||||
@@ -67,17 +65,12 @@ from helpers import (
|
||||
parse_test_filename,
|
||||
root_path,
|
||||
)
|
||||
from split_components_for_ci import create_intelligent_batches
|
||||
|
||||
# Threshold for splitting clang-tidy jobs
|
||||
# For small PRs (< 65 files), use nosplit for faster CI
|
||||
# For large PRs (>= 65 files), use split for better parallelization
|
||||
CLANG_TIDY_SPLIT_THRESHOLD = 65
|
||||
|
||||
# Component test batch size (weighted)
|
||||
# Isolated components count as 10x, groupable components count as 1x
|
||||
COMPONENT_TEST_BATCH_SIZE = 40
|
||||
|
||||
|
||||
class Platform(StrEnum):
|
||||
"""Platform identifiers for memory impact analysis."""
|
||||
@@ -693,22 +686,6 @@ def main() -> None:
|
||||
# Determine which C++ unit tests to run
|
||||
cpp_run_all, cpp_components = determine_cpp_unit_tests(args.branch)
|
||||
|
||||
# Split components into batches for CI testing
|
||||
# This intelligently groups components with similar bus configurations
|
||||
component_test_batches: list[str]
|
||||
if changed_components_with_tests:
|
||||
tests_dir = Path(root_path) / ESPHOME_TESTS_COMPONENTS_PATH
|
||||
batches, _ = create_intelligent_batches(
|
||||
components=changed_components_with_tests,
|
||||
tests_dir=tests_dir,
|
||||
batch_size=COMPONENT_TEST_BATCH_SIZE,
|
||||
directly_changed=directly_changed_with_tests,
|
||||
)
|
||||
# Convert batches to space-separated strings for CI matrix
|
||||
component_test_batches = [" ".join(batch) for batch in batches]
|
||||
else:
|
||||
component_test_batches = []
|
||||
|
||||
output: dict[str, Any] = {
|
||||
"integration_tests": run_integration,
|
||||
"clang_tidy": run_clang_tidy,
|
||||
@@ -726,7 +703,6 @@ def main() -> None:
|
||||
"memory_impact": memory_impact,
|
||||
"cpp_unit_tests_run_all": cpp_run_all,
|
||||
"cpp_unit_tests_components": cpp_components,
|
||||
"component_test_batches": component_test_batches,
|
||||
}
|
||||
|
||||
# Output as JSON
|
||||
|
||||
@@ -62,10 +62,6 @@ def create_intelligent_batches(
|
||||
) -> tuple[list[list[str]], dict[tuple[str, str], list[str]]]:
|
||||
"""Create batches optimized for component grouping.
|
||||
|
||||
IMPORTANT: This function is called from both split_components_for_ci.py (standalone script)
|
||||
and determine-jobs.py (integrated into job determination). Be careful when refactoring
|
||||
to ensure changes work in both contexts.
|
||||
|
||||
Args:
|
||||
components: List of component names to batch
|
||||
tests_dir: Path to tests/components directory
|
||||
|
||||
@@ -18,8 +18,7 @@ def test_gpio_binary_sensor_basic_setup(
|
||||
|
||||
assert "new gpio::GPIOBinarySensor();" in main_cpp
|
||||
assert "App.register_binary_sensor" in main_cpp
|
||||
# set_use_interrupt(true) should NOT be generated (uses C++ default)
|
||||
assert "bs_gpio->set_use_interrupt(true);" not in main_cpp
|
||||
assert "bs_gpio->set_use_interrupt(true);" in main_cpp
|
||||
assert "bs_gpio->set_interrupt_type(gpio::INTERRUPT_ANY_EDGE);" in main_cpp
|
||||
|
||||
|
||||
@@ -52,8 +51,8 @@ def test_gpio_binary_sensor_esp8266_other_pins_use_interrupt(
|
||||
"tests/component_tests/gpio/test_gpio_binary_sensor_esp8266.yaml"
|
||||
)
|
||||
|
||||
# GPIO5 should still use interrupts (default, so no setter call)
|
||||
assert "bs_gpio5->set_use_interrupt(true);" not in main_cpp
|
||||
# GPIO5 should still use interrupts
|
||||
assert "bs_gpio5->set_use_interrupt(true);" in main_cpp
|
||||
assert "bs_gpio5->set_interrupt_type(gpio::INTERRUPT_ANY_EDGE);" in main_cpp
|
||||
|
||||
|
||||
|
||||
@@ -10,12 +10,26 @@ esphome:
|
||||
state: !lambda "return 42.0;"
|
||||
|
||||
# Test C++ API: set_template() with stateless lambda (no captures)
|
||||
# NOTE: set_template() is not intended to be a public API, but we test it to ensure it doesn't break.
|
||||
- lambda: |-
|
||||
id(template_sens).set_template([]() -> esphome::optional<float> {
|
||||
return 123.0f;
|
||||
});
|
||||
|
||||
# Test C++ API: set_template() with stateful lambda (with captures)
|
||||
# This is the regression test for issue #11555
|
||||
- lambda: |-
|
||||
float captured_value = 456.0f;
|
||||
id(template_sens).set_template([captured_value]() -> esphome::optional<float> {
|
||||
return captured_value;
|
||||
});
|
||||
|
||||
# Test C++ API: set_template() with more complex capture
|
||||
- lambda: |-
|
||||
auto sensor_id = id(template_sens);
|
||||
id(template_number).set_template([sensor_id]() -> esphome::optional<float> {
|
||||
return sensor_id->state * 2.0f;
|
||||
});
|
||||
|
||||
- datetime.date.set:
|
||||
id: test_date
|
||||
date:
|
||||
|
||||
@@ -15,12 +15,6 @@ climate:
|
||||
- name: Away
|
||||
default_target_temperature_low: 16°C
|
||||
default_target_temperature_high: 20°C
|
||||
custom_fan_modes:
|
||||
- "Custom Fan 1"
|
||||
- "Custom Fan 2"
|
||||
custom_presets:
|
||||
- "Custom Preset 1"
|
||||
- "Custom Preset 2"
|
||||
idle_action:
|
||||
- logger.log: idle_action
|
||||
cool_action:
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
esphome:
|
||||
name: climate-custom-modes-test
|
||||
host:
|
||||
api:
|
||||
logger:
|
||||
|
||||
sensor:
|
||||
- platform: template
|
||||
id: thermostat_sensor
|
||||
lambda: "return 22.0;"
|
||||
|
||||
climate:
|
||||
- platform: thermostat
|
||||
id: test_thermostat
|
||||
name: Test Thermostat Custom Modes
|
||||
sensor: thermostat_sensor
|
||||
preset:
|
||||
- name: Away
|
||||
default_target_temperature_low: 16°C
|
||||
default_target_temperature_high: 20°C
|
||||
custom_fan_modes:
|
||||
- "Turbo"
|
||||
- "Silent"
|
||||
- "Sleep Mode"
|
||||
custom_presets:
|
||||
- "Eco Plus"
|
||||
- "Comfort"
|
||||
- "Vacation Mode"
|
||||
idle_action:
|
||||
- logger.log: idle_action
|
||||
cool_action:
|
||||
- logger.log: cool_action
|
||||
heat_action:
|
||||
- logger.log: heat_action
|
||||
min_cooling_off_time: 10s
|
||||
min_cooling_run_time: 10s
|
||||
min_heating_off_time: 10s
|
||||
min_heating_run_time: 10s
|
||||
min_idle_time: 10s
|
||||
@@ -32,7 +32,6 @@ switch:
|
||||
name: "Test Switch"
|
||||
id: test_switch
|
||||
optimistic: true
|
||||
lambda: return false;
|
||||
|
||||
interval:
|
||||
- interval: 0.5s
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
"""Integration test for climate custom fan modes and presets."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from aioesphomeapi import ClimateInfo, ClimatePreset
|
||||
import pytest
|
||||
|
||||
from .types import APIClientConnectedFactory, RunCompiledFunction
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_climate_custom_fan_modes_and_presets(
|
||||
yaml_config: str,
|
||||
run_compiled: RunCompiledFunction,
|
||||
api_client_connected: APIClientConnectedFactory,
|
||||
) -> None:
|
||||
"""Test that custom fan modes and presets are properly exposed via API."""
|
||||
async with run_compiled(yaml_config), api_client_connected() as client:
|
||||
# Get entities and services
|
||||
entities, services = await client.list_entities_services()
|
||||
climate_infos = [e for e in entities if isinstance(e, ClimateInfo)]
|
||||
assert len(climate_infos) == 1, "Expected exactly 1 climate entity"
|
||||
|
||||
test_climate = climate_infos[0]
|
||||
|
||||
# Verify custom fan modes are exposed
|
||||
custom_fan_modes = test_climate.supported_custom_fan_modes
|
||||
assert len(custom_fan_modes) == 3, (
|
||||
f"Expected 3 custom fan modes, got {len(custom_fan_modes)}"
|
||||
)
|
||||
assert "Turbo" in custom_fan_modes, "Expected 'Turbo' in custom fan modes"
|
||||
assert "Silent" in custom_fan_modes, "Expected 'Silent' in custom fan modes"
|
||||
assert "Sleep Mode" in custom_fan_modes, (
|
||||
"Expected 'Sleep Mode' in custom fan modes"
|
||||
)
|
||||
|
||||
# Verify enum presets are exposed (from preset: config map)
|
||||
assert ClimatePreset.AWAY in test_climate.supported_presets, (
|
||||
"Expected AWAY in enum presets"
|
||||
)
|
||||
|
||||
# Verify custom string presets are exposed (from custom_presets: config list)
|
||||
custom_presets = test_climate.supported_custom_presets
|
||||
assert len(custom_presets) == 3, (
|
||||
f"Expected 3 custom presets, got {len(custom_presets)}: {custom_presets}"
|
||||
)
|
||||
assert "Eco Plus" in custom_presets, "Expected 'Eco Plus' in custom presets"
|
||||
assert "Comfort" in custom_presets, "Expected 'Comfort' in custom presets"
|
||||
assert "Vacation Mode" in custom_presets, (
|
||||
"Expected 'Vacation Mode' in custom presets"
|
||||
)
|
||||
@@ -152,14 +152,6 @@ def test_main_all_tests_should_run(
|
||||
assert output["memory_impact"]["should_run"] == "false"
|
||||
assert output["cpp_unit_tests_run_all"] is False
|
||||
assert output["cpp_unit_tests_components"] == ["wifi", "api", "sensor"]
|
||||
# component_test_batches should be present and be a list of space-separated strings
|
||||
assert "component_test_batches" in output
|
||||
assert isinstance(output["component_test_batches"], list)
|
||||
# Each batch should be a space-separated string of component names
|
||||
for batch in output["component_test_batches"]:
|
||||
assert isinstance(batch, str)
|
||||
# Should contain at least one component (no empty batches)
|
||||
assert len(batch) > 0
|
||||
|
||||
|
||||
def test_main_no_tests_should_run(
|
||||
@@ -217,9 +209,6 @@ def test_main_no_tests_should_run(
|
||||
assert output["memory_impact"]["should_run"] == "false"
|
||||
assert output["cpp_unit_tests_run_all"] is False
|
||||
assert output["cpp_unit_tests_components"] == []
|
||||
# component_test_batches should be empty list
|
||||
assert "component_test_batches" in output
|
||||
assert output["component_test_batches"] == []
|
||||
|
||||
|
||||
def test_main_with_branch_argument(
|
||||
|
||||
Reference in New Issue
Block a user