diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 39bcb83cfb..7dfefedd54 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -661,11 +661,12 @@ uint16_t APIConnection::try_send_climate_info(EntityBase *entity, APIConnection ListEntitiesClimateResponse msg; auto traits = climate->get_traits(); // Flags set for backward compatibility, deprecated in 2025.11.0 - msg.supports_current_temperature = traits.get_supports_current_temperature(); - msg.supports_current_humidity = traits.get_supports_current_humidity(); - msg.supports_two_point_target_temperature = traits.get_supports_two_point_target_temperature(); - msg.supports_target_humidity = traits.get_supports_target_humidity(); - msg.supports_action = traits.get_supports_action(); + msg.supports_current_temperature = traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_TEMPERATURE); + msg.supports_current_humidity = traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_HUMIDITY); + msg.supports_two_point_target_temperature = traits.has_feature_flags( + climate::CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE | climate::CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE); + msg.supports_target_humidity = traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY); + msg.supports_action = traits.has_feature_flags(climate::CLIMATE_SUPPORTS_ACTION); // Current feature flags and other supported parameters msg.feature_flags = traits.get_feature_flags(); msg.supported_modes = &traits.get_supported_modes_for_api_(); diff --git a/esphome/components/bme680_bsec/__init__.py b/esphome/components/bme680_bsec/__init__.py index 330dc4dd9c..8a8d74b5f3 100644 --- a/esphome/components/bme680_bsec/__init__.py +++ b/esphome/components/bme680_bsec/__init__.py @@ -41,7 +41,7 @@ CONFIG_SCHEMA = cv.All( cv.Schema( { cv.GenerateID(): cv.declare_id(BME680BSECComponent), - cv.Optional(CONF_TEMPERATURE_OFFSET, default=0): cv.temperature, + cv.Optional(CONF_TEMPERATURE_OFFSET, default=0): cv.temperature_delta, cv.Optional(CONF_IAQ_MODE, default="STATIC"): cv.enum( IAQ_MODE_OPTIONS, upper=True ), diff --git a/esphome/components/bme68x_bsec2/__init__.py b/esphome/components/bme68x_bsec2/__init__.py index f4235b31b4..e421efb2d6 100644 --- a/esphome/components/bme68x_bsec2/__init__.py +++ b/esphome/components/bme68x_bsec2/__init__.py @@ -139,7 +139,7 @@ CONFIG_SCHEMA_BASE = ( cv.Optional(CONF_SUPPLY_VOLTAGE, default="3.3V"): cv.enum( VOLTAGE_OPTIONS, upper=True ), - cv.Optional(CONF_TEMPERATURE_OFFSET, default=0): cv.temperature, + cv.Optional(CONF_TEMPERATURE_OFFSET, default=0): cv.temperature_delta, cv.Optional( CONF_STATE_SAVE_INTERVAL, default="6hours" ): cv.positive_time_period_minutes, diff --git a/esphome/components/mqtt/mqtt_climate.cpp b/esphome/components/mqtt/mqtt_climate.cpp index e16f097812..a6f4e0a201 100644 --- a/esphome/components/mqtt/mqtt_climate.cpp +++ b/esphome/components/mqtt/mqtt_climate.cpp @@ -17,11 +17,11 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo // NOLINTBEGIN(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson auto traits = this->device_->get_traits(); // current_temperature_topic - if (traits.get_supports_current_temperature()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_TEMPERATURE)) { root[MQTT_CURRENT_TEMPERATURE_TOPIC] = this->get_current_temperature_state_topic(); } // current_humidity_topic - if (traits.get_supports_current_humidity()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_HUMIDITY)) { root[MQTT_CURRENT_HUMIDITY_TOPIC] = this->get_current_humidity_state_topic(); } // mode_command_topic @@ -45,7 +45,8 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo if (traits.supports_mode(CLIMATE_MODE_HEAT_COOL)) modes.add("heat_cool"); - if (traits.get_supports_two_point_target_temperature()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE | + climate::CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE)) { // temperature_low_command_topic root[MQTT_TEMPERATURE_LOW_COMMAND_TOPIC] = this->get_target_temperature_low_command_topic(); // temperature_low_state_topic @@ -61,7 +62,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo root[MQTT_TEMPERATURE_STATE_TOPIC] = this->get_target_temperature_state_topic(); } - if (traits.get_supports_target_humidity()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) { // target_humidity_command_topic root[MQTT_TARGET_HUMIDITY_COMMAND_TOPIC] = this->get_target_humidity_command_topic(); // target_humidity_state_topic @@ -109,7 +110,7 @@ void MQTTClimateComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCo presets.add(preset); } - if (traits.get_supports_action()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_ACTION)) { // action_topic root[MQTT_ACTION_TOPIC] = this->get_action_state_topic(); } @@ -174,7 +175,8 @@ void MQTTClimateComponent::setup() { call.perform(); }); - if (traits.get_supports_two_point_target_temperature()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE | + climate::CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE)) { this->subscribe(this->get_target_temperature_low_command_topic(), [this](const std::string &topic, const std::string &payload) { auto val = parse_number(payload); @@ -211,7 +213,7 @@ void MQTTClimateComponent::setup() { }); } - if (traits.get_supports_target_humidity()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) { this->subscribe(this->get_target_humidity_command_topic(), [this](const std::string &topic, const std::string &payload) { auto val = parse_number(payload); @@ -290,12 +292,14 @@ bool MQTTClimateComponent::publish_state_() { success = false; int8_t target_accuracy = traits.get_target_temperature_accuracy_decimals(); int8_t current_accuracy = traits.get_current_temperature_accuracy_decimals(); - if (traits.get_supports_current_temperature() && !std::isnan(this->device_->current_temperature)) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_TEMPERATURE) && + !std::isnan(this->device_->current_temperature)) { std::string payload = value_accuracy_to_string(this->device_->current_temperature, current_accuracy); if (!this->publish(this->get_current_temperature_state_topic(), payload)) success = false; } - if (traits.get_supports_two_point_target_temperature()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE | + climate::CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE)) { std::string payload = value_accuracy_to_string(this->device_->target_temperature_low, target_accuracy); if (!this->publish(this->get_target_temperature_low_state_topic(), payload)) success = false; @@ -308,12 +312,14 @@ bool MQTTClimateComponent::publish_state_() { success = false; } - if (traits.get_supports_current_humidity() && !std::isnan(this->device_->current_humidity)) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_HUMIDITY) && + !std::isnan(this->device_->current_humidity)) { std::string payload = value_accuracy_to_string(this->device_->current_humidity, 0); if (!this->publish(this->get_current_humidity_state_topic(), payload)) success = false; } - if (traits.get_supports_target_humidity() && !std::isnan(this->device_->target_humidity)) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY) && + !std::isnan(this->device_->target_humidity)) { std::string payload = value_accuracy_to_string(this->device_->target_humidity, 0); if (!this->publish(this->get_target_humidity_state_topic(), payload)) success = false; @@ -357,7 +363,7 @@ bool MQTTClimateComponent::publish_state_() { success = false; } - if (traits.get_supports_action()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_ACTION)) { const char *payload; switch (this->device_->action) { case CLIMATE_ACTION_OFF: diff --git a/esphome/components/prometheus/prometheus_handler.cpp b/esphome/components/prometheus/prometheus_handler.cpp index 68ef18e5ce..6e7ed6f79f 100644 --- a/esphome/components/prometheus/prometheus_handler.cpp +++ b/esphome/components/prometheus/prometheus_handler.cpp @@ -916,7 +916,7 @@ void PrometheusHandler::climate_row_(AsyncResponseStream *stream, climate::Clima auto min_temp_value = value_accuracy_to_string(traits.get_visual_min_temperature(), target_accuracy); climate_value_row_(stream, obj, area, node, friendly_name, min_temp, min_temp_value); // now check optional traits - if (traits.get_supports_current_temperature()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_TEMPERATURE)) { std::string current_temp = "current_temperature"; if (std::isnan(obj->current_temperature)) { climate_failed_row_(stream, obj, area, node, friendly_name, current_temp, true); @@ -927,7 +927,7 @@ void PrometheusHandler::climate_row_(AsyncResponseStream *stream, climate::Clima climate_failed_row_(stream, obj, area, node, friendly_name, current_temp, false); } } - if (traits.get_supports_current_humidity()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_HUMIDITY)) { std::string current_humidity = "current_humidity"; if (std::isnan(obj->current_humidity)) { climate_failed_row_(stream, obj, area, node, friendly_name, current_humidity, true); @@ -938,7 +938,7 @@ void PrometheusHandler::climate_row_(AsyncResponseStream *stream, climate::Clima climate_failed_row_(stream, obj, area, node, friendly_name, current_humidity, false); } } - if (traits.get_supports_target_humidity()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY)) { std::string target_humidity = "target_humidity"; if (std::isnan(obj->target_humidity)) { climate_failed_row_(stream, obj, area, node, friendly_name, target_humidity, true); @@ -949,7 +949,8 @@ void PrometheusHandler::climate_row_(AsyncResponseStream *stream, climate::Clima climate_failed_row_(stream, obj, area, node, friendly_name, target_humidity, false); } } - if (traits.get_supports_two_point_target_temperature()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE | + climate::CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE)) { std::string target_temp_low = "target_temperature_low"; auto target_temp_low_value = value_accuracy_to_string(obj->target_temperature_low, target_accuracy); climate_value_row_(stream, obj, area, node, friendly_name, target_temp_low, target_temp_low_value); @@ -961,7 +962,7 @@ void PrometheusHandler::climate_row_(AsyncResponseStream *stream, climate::Clima auto target_temp_value = value_accuracy_to_string(obj->target_temperature, target_accuracy); climate_value_row_(stream, obj, area, node, friendly_name, target_temp, target_temp_value); } - if (traits.get_supports_action()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_ACTION)) { std::string climate_trait_category = "action"; const auto *climate_trait_value = climate::climate_action_to_string(obj->action); climate_setting_row_(stream, obj, area, node, friendly_name, climate_trait_category, climate_trait_value); diff --git a/esphome/components/remote_base/__init__.py b/esphome/components/remote_base/__init__.py index 42ebae77f7..ccf16a8beb 100644 --- a/esphome/components/remote_base/__init__.py +++ b/esphome/components/remote_base/__init__.py @@ -1056,6 +1056,52 @@ async def sony_action(var, config, args): cg.add(var.set_nbits(template_)) +# Symphony +SymphonyData, SymphonyBinarySensor, SymphonyTrigger, SymphonyAction, SymphonyDumper = ( + declare_protocol("Symphony") +) +SYMPHONY_SCHEMA = cv.Schema( + { + cv.Required(CONF_DATA): cv.hex_uint32_t, + cv.Required(CONF_NBITS): cv.int_range(min=1, max=32), + cv.Optional(CONF_COMMAND_REPEATS, default=2): cv.uint8_t, + } +) + + +@register_binary_sensor("symphony", SymphonyBinarySensor, SYMPHONY_SCHEMA) +def symphony_binary_sensor(var, config): + cg.add( + var.set_data( + cg.StructInitializer( + SymphonyData, + ("data", config[CONF_DATA]), + ("nbits", config[CONF_NBITS]), + ) + ) + ) + + +@register_trigger("symphony", SymphonyTrigger, SymphonyData) +def symphony_trigger(var, config): + pass + + +@register_dumper("symphony", SymphonyDumper) +def symphony_dumper(var, config): + pass + + +@register_action("symphony", SymphonyAction, SYMPHONY_SCHEMA) +async def symphony_action(var, config, args): + template_ = await cg.templatable(config[CONF_DATA], args, cg.uint32) + cg.add(var.set_data(template_)) + template_ = await cg.templatable(config[CONF_NBITS], args, cg.uint32) + cg.add(var.set_nbits(template_)) + template_ = await cg.templatable(config[CONF_COMMAND_REPEATS], args, cg.uint8) + cg.add(var.set_repeats(template_)) + + # Raw def validate_raw_alternating(value): assert isinstance(value, list) diff --git a/esphome/components/remote_base/symphony_protocol.cpp b/esphome/components/remote_base/symphony_protocol.cpp new file mode 100644 index 0000000000..34b5dba07f --- /dev/null +++ b/esphome/components/remote_base/symphony_protocol.cpp @@ -0,0 +1,120 @@ +#include "symphony_protocol.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace remote_base { + +static const char *const TAG = "remote.symphony"; + +// Reference implementation and timing details: +// IRremoteESP8266 ir_Symphony.cpp +// https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/ir_Symphony.cpp +// The implementation below mirrors the constant bit-time mapping and +// footer-gap handling used there. + +// Symphony protocol timing specifications (tuned to handset captures) +static const uint32_t BIT_ZERO_HIGH_US = 460; // short +static const uint32_t BIT_ZERO_LOW_US = 1260; // long +static const uint32_t BIT_ONE_HIGH_US = 1260; // long +static const uint32_t BIT_ONE_LOW_US = 460; // short +static const uint32_t CARRIER_FREQUENCY = 38000; + +// IRremoteESP8266 reference: kSymphonyFooterGap = 4 * (mark + space) +static const uint32_t FOOTER_GAP_US = 4 * (BIT_ZERO_HIGH_US + BIT_ZERO_LOW_US); +// Typical inter-frame gap (~34.8 ms observed) +static const uint32_t INTER_FRAME_GAP_US = 34760; + +void SymphonyProtocol::encode(RemoteTransmitData *dst, const SymphonyData &data) { + dst->set_carrier_frequency(CARRIER_FREQUENCY); + ESP_LOGD(TAG, "Sending Symphony: data=0x%0*X nbits=%u repeats=%u", (data.nbits + 3) / 4, (uint32_t) data.data, + data.nbits, data.repeats); + // Each bit produces a mark+space (2 entries). We fold the inter-frame/footer gap + // into the last bit's space of each frame to avoid over-length gaps. + dst->reserve(data.nbits * 2u * data.repeats); + + for (uint8_t repeats = 0; repeats < data.repeats; repeats++) { + // Data bits (MSB first) + for (uint32_t mask = 1UL << (data.nbits - 1); mask != 0; mask >>= 1) { + const bool is_last_bit = (mask == 1); + const bool is_last_frame = (repeats == (data.repeats - 1)); + if (is_last_bit) { + // Emit last bit's mark; replace its space with the proper gap + if (data.data & mask) { + dst->mark(BIT_ONE_HIGH_US); + } else { + dst->mark(BIT_ZERO_HIGH_US); + } + dst->space(is_last_frame ? FOOTER_GAP_US : INTER_FRAME_GAP_US); + } else { + if (data.data & mask) { + dst->item(BIT_ONE_HIGH_US, BIT_ONE_LOW_US); + } else { + dst->item(BIT_ZERO_HIGH_US, BIT_ZERO_LOW_US); + } + } + } + } +} + +optional SymphonyProtocol::decode(RemoteReceiveData src) { + auto is_valid_len = [](uint8_t nbits) -> bool { return nbits == 8 || nbits == 12 || nbits == 16; }; + + RemoteReceiveData s = src; // copy + SymphonyData out{0, 0, 1}; + + for (; out.nbits < 32; out.nbits++) { + if (s.expect_mark(BIT_ONE_HIGH_US)) { + if (!s.expect_space(BIT_ONE_LOW_US)) { + // Allow footer gap immediately after the last mark + if (s.peek_space_at_least(FOOTER_GAP_US)) { + uint8_t bits_with_this = out.nbits + 1; + if (is_valid_len(bits_with_this)) { + out.data = (out.data << 1UL) | 1UL; + out.nbits = bits_with_this; + return out; + } + } + return {}; + } + // Successfully consumed a '1' bit (mark + space) + out.data = (out.data << 1UL) | 1UL; + continue; + } else if (s.expect_mark(BIT_ZERO_HIGH_US)) { + if (!s.expect_space(BIT_ZERO_LOW_US)) { + // Allow footer gap immediately after the last mark + if (s.peek_space_at_least(FOOTER_GAP_US)) { + uint8_t bits_with_this = out.nbits + 1; + if (is_valid_len(bits_with_this)) { + out.data = (out.data << 1UL) | 0UL; + out.nbits = bits_with_this; + return out; + } + } + return {}; + } + // Successfully consumed a '0' bit (mark + space) + out.data = (out.data << 1UL) | 0UL; + continue; + } else { + // Completed a valid-length frame followed by a footer gap + if (is_valid_len(out.nbits) && s.peek_space_at_least(FOOTER_GAP_US)) { + return out; + } + return {}; + } + } + + if (is_valid_len(out.nbits) && s.peek_space_at_least(FOOTER_GAP_US)) { + return out; + } + + return {}; +} + +void SymphonyProtocol::dump(const SymphonyData &data) { + const int32_t hex_width = (data.nbits + 3) / 4; // pad to nibble width + ESP_LOGI(TAG, "Received Symphony: data=0x%0*X, nbits=%d", hex_width, (uint32_t) data.data, data.nbits); +} + +} // namespace remote_base +} // namespace esphome diff --git a/esphome/components/remote_base/symphony_protocol.h b/esphome/components/remote_base/symphony_protocol.h new file mode 100644 index 0000000000..7e77a268ba --- /dev/null +++ b/esphome/components/remote_base/symphony_protocol.h @@ -0,0 +1,44 @@ +#pragma once + +#include "esphome/core/component.h" +#include "remote_base.h" + +#include + +namespace esphome { +namespace remote_base { + +struct SymphonyData { + uint32_t data; + uint8_t nbits; + uint8_t repeats{1}; + + bool operator==(const SymphonyData &rhs) const { return data == rhs.data && nbits == rhs.nbits; } +}; + +class SymphonyProtocol : public RemoteProtocol { + public: + void encode(RemoteTransmitData *dst, const SymphonyData &data) override; + optional decode(RemoteReceiveData src) override; + void dump(const SymphonyData &data) override; +}; + +DECLARE_REMOTE_PROTOCOL(Symphony) + +template class SymphonyAction : public RemoteTransmitterActionBase { + public: + TEMPLATABLE_VALUE(uint32_t, data) + TEMPLATABLE_VALUE(uint8_t, nbits) + TEMPLATABLE_VALUE(uint8_t, repeats) + + void encode(RemoteTransmitData *dst, Ts... x) override { + SymphonyData data{}; + data.data = this->data_.value(x...); + data.nbits = this->nbits_.value(x...); + data.repeats = this->repeats_.value(x...); + SymphonyProtocol().encode(dst, data); + } +}; + +} // namespace remote_base +} // namespace esphome diff --git a/esphome/components/scd4x/sensor.py b/esphome/components/scd4x/sensor.py index 6b2188cd5a..ec90234ac3 100644 --- a/esphome/components/scd4x/sensor.py +++ b/esphome/components/scd4x/sensor.py @@ -81,7 +81,7 @@ CONFIG_SCHEMA = ( cv.int_range(min=0, max=0xFFFF, max_included=False), ), cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION): cv.pressure, - cv.Optional(CONF_TEMPERATURE_OFFSET, default="4°C"): cv.temperature, + cv.Optional(CONF_TEMPERATURE_OFFSET, default="4°C"): cv.temperature_delta, cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE): cv.use_id( sensor.Sensor ), diff --git a/esphome/components/thermostat/climate.py b/esphome/components/thermostat/climate.py index 57abbc67b9..a928d208f3 100644 --- a/esphome/components/thermostat/climate.py +++ b/esphome/components/thermostat/climate.py @@ -71,9 +71,14 @@ from esphome.const import ( CONF_VISUAL, ) -CONF_PRESET_CHANGE = "preset_change" CONF_DEFAULT_PRESET = "default_preset" +CONF_HUMIDITY_CONTROL_DEHUMIDIFY_ACTION = "humidity_control_dehumidify_action" +CONF_HUMIDITY_CONTROL_HUMIDIFY_ACTION = "humidity_control_humidify_action" +CONF_HUMIDITY_CONTROL_OFF_ACTION = "humidity_control_off_action" +CONF_HUMIDITY_HYSTERESIS = "humidity_hysteresis" CONF_ON_BOOT_RESTORE_FROM = "on_boot_restore_from" +CONF_PRESET_CHANGE = "preset_change" +CONF_TARGET_HUMIDITY_CHANGE_ACTION = "target_humidity_change_action" CODEOWNERS = ["@kbx81"] @@ -241,6 +246,14 @@ def validate_thermostat(config): CONF_MAX_HEATING_RUN_TIME, CONF_SUPPLEMENTAL_HEATING_ACTION, ], + CONF_HUMIDITY_CONTROL_DEHUMIDIFY_ACTION: [ + CONF_HUMIDITY_CONTROL_OFF_ACTION, + CONF_HUMIDITY_SENSOR, + ], + CONF_HUMIDITY_CONTROL_HUMIDIFY_ACTION: [ + CONF_HUMIDITY_CONTROL_OFF_ACTION, + CONF_HUMIDITY_SENSOR, + ], } for config_trigger, req_triggers in requirements.items(): for req_trigger in req_triggers: @@ -338,7 +351,7 @@ def validate_thermostat(config): # Warn about using the removed CONF_DEFAULT_MODE and advise users if CONF_DEFAULT_MODE in config and config[CONF_DEFAULT_MODE] is not None: raise cv.Invalid( - f"{CONF_DEFAULT_MODE} is no longer valid. Please switch to using presets and specify a {CONF_DEFAULT_PRESET}." + f"{CONF_DEFAULT_MODE} is no longer valid. Please switch to using presets and specify a {CONF_DEFAULT_PRESET}" ) default_mode = config[CONF_DEFAULT_MODE] @@ -588,9 +601,24 @@ CONFIG_SCHEMA = cv.All( cv.Optional(CONF_SWING_VERTICAL_ACTION): automation.validate_automation( single=True ), + cv.Optional( + CONF_TARGET_HUMIDITY_CHANGE_ACTION + ): automation.validate_automation(single=True), cv.Optional( CONF_TARGET_TEMPERATURE_CHANGE_ACTION ): automation.validate_automation(single=True), + cv.Exclusive( + CONF_HUMIDITY_CONTROL_DEHUMIDIFY_ACTION, + group_of_exclusion="humidity_control", + ): automation.validate_automation(single=True), + cv.Exclusive( + CONF_HUMIDITY_CONTROL_HUMIDIFY_ACTION, + group_of_exclusion="humidity_control", + ): automation.validate_automation(single=True), + cv.Optional( + CONF_HUMIDITY_CONTROL_OFF_ACTION + ): automation.validate_automation(single=True), + cv.Optional(CONF_HUMIDITY_HYSTERESIS, default=1.0): cv.percentage, cv.Optional(CONF_DEFAULT_MODE, default=None): cv.valid, cv.Optional(CONF_DEFAULT_PRESET): cv.templatable(cv.string), cv.Optional(CONF_DEFAULT_TARGET_TEMPERATURE_HIGH): cv.temperature, @@ -882,12 +910,39 @@ async def to_code(config): config[CONF_SWING_VERTICAL_ACTION], ) cg.add(var.set_supports_swing_mode_vertical(True)) + if CONF_TARGET_HUMIDITY_CHANGE_ACTION in config: + await automation.build_automation( + var.get_humidity_change_trigger(), + [], + config[CONF_TARGET_HUMIDITY_CHANGE_ACTION], + ) if CONF_TARGET_TEMPERATURE_CHANGE_ACTION in config: await automation.build_automation( var.get_temperature_change_trigger(), [], config[CONF_TARGET_TEMPERATURE_CHANGE_ACTION], ) + if CONF_HUMIDITY_CONTROL_DEHUMIDIFY_ACTION in config: + cg.add(var.set_supports_dehumidification(True)) + await automation.build_automation( + var.get_humidity_control_dehumidify_action_trigger(), + [], + config[CONF_HUMIDITY_CONTROL_DEHUMIDIFY_ACTION], + ) + if CONF_HUMIDITY_CONTROL_HUMIDIFY_ACTION in config: + cg.add(var.set_supports_humidification(True)) + await automation.build_automation( + var.get_humidity_control_humidify_action_trigger(), + [], + config[CONF_HUMIDITY_CONTROL_HUMIDIFY_ACTION], + ) + if CONF_HUMIDITY_CONTROL_OFF_ACTION in config: + await automation.build_automation( + var.get_humidity_control_off_action_trigger(), + [], + config[CONF_HUMIDITY_CONTROL_OFF_ACTION], + ) + cg.add(var.set_humidity_hysteresis(config[CONF_HUMIDITY_HYSTERESIS])) if CONF_PRESET in config: for preset_config in config[CONF_PRESET]: diff --git a/esphome/components/thermostat/thermostat_climate.cpp b/esphome/components/thermostat/thermostat_climate.cpp index 784b3cfb50..18efe3984e 100644 --- a/esphome/components/thermostat/thermostat_climate.cpp +++ b/esphome/components/thermostat/thermostat_climate.cpp @@ -32,6 +32,7 @@ void ThermostatClimate::setup() { if (this->humidity_sensor_ != nullptr) { this->humidity_sensor_->add_on_state_callback([this](float state) { this->current_humidity = state; + this->switch_to_humidity_control_action_(this->compute_humidity_control_action_()); this->publish_state(); }); this->current_humidity = this->humidity_sensor_->state; @@ -84,6 +85,8 @@ void ThermostatClimate::refresh() { this->switch_to_supplemental_action_(this->compute_supplemental_action_()); this->switch_to_fan_mode_(this->fan_mode.value(), false); this->switch_to_swing_mode_(this->swing_mode, false); + this->switch_to_humidity_control_action_(this->compute_humidity_control_action_()); + this->check_humidity_change_trigger_(); this->check_temperature_change_trigger_(); this->publish_state(); } @@ -129,6 +132,11 @@ bool ThermostatClimate::hysteresis_valid() { return true; } +bool ThermostatClimate::humidity_hysteresis_valid() { + return !std::isnan(this->humidity_hysteresis_) && this->humidity_hysteresis_ >= 0.0f && + this->humidity_hysteresis_ < 100.0f; +} + bool ThermostatClimate::limit_setpoints_for_heat_cool() { return this->mode == climate::CLIMATE_MODE_HEAT_COOL || (this->mode == climate::CLIMATE_MODE_AUTO && this->supports_heat_cool_); @@ -189,6 +197,16 @@ void ThermostatClimate::validate_target_temperature_high() { } } +void ThermostatClimate::validate_target_humidity() { + if (std::isnan(this->target_humidity)) { + this->target_humidity = + (this->get_traits().get_visual_max_humidity() - this->get_traits().get_visual_min_humidity()) / 2.0f; + } else { + this->target_humidity = clamp(this->target_humidity, this->get_traits().get_visual_min_humidity(), + this->get_traits().get_visual_max_humidity()); + } +} + void ThermostatClimate::control(const climate::ClimateCall &call) { bool target_temperature_high_changed = false; @@ -235,6 +253,10 @@ void ThermostatClimate::control(const climate::ClimateCall &call) { this->validate_target_temperature(); } } + if (call.get_target_humidity().has_value()) { + this->target_humidity = call.get_target_humidity().value(); + this->validate_target_humidity(); + } // make any changes happen this->refresh(); } @@ -250,6 +272,9 @@ climate::ClimateTraits ThermostatClimate::traits() { if (this->humidity_sensor_ != nullptr) traits.add_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_HUMIDITY); + if (this->supports_humidification_ || this->supports_dehumidification_) + traits.add_feature_flags(climate::CLIMATE_SUPPORTS_TARGET_HUMIDITY); + if (this->supports_auto_) traits.add_supported_mode(climate::CLIMATE_MODE_AUTO); if (this->supports_heat_cool_) @@ -423,6 +448,28 @@ climate::ClimateAction ThermostatClimate::compute_supplemental_action_() { return target_action; } +HumidificationAction ThermostatClimate::compute_humidity_control_action_() { + auto target_action = THERMOSTAT_HUMIDITY_CONTROL_ACTION_OFF; + // if hysteresis value or current_humidity is not valid, we go to OFF + if (std::isnan(this->current_humidity) || !this->humidity_hysteresis_valid()) { + return THERMOSTAT_HUMIDITY_CONTROL_ACTION_OFF; + } + + // ensure set point is valid before computing the action + this->validate_target_humidity(); + // everything has been validated so we can now safely compute the action + if (this->dehumidification_required_() && this->humidification_required_()) { + // this is bad and should never happen, so just stop. + // target_action = THERMOSTAT_HUMIDITY_CONTROL_ACTION_OFF; + } else if (this->supports_dehumidification_ && this->dehumidification_required_()) { + target_action = THERMOSTAT_HUMIDITY_CONTROL_ACTION_DEHUMIDIFY; + } else if (this->supports_humidification_ && this->humidification_required_()) { + target_action = THERMOSTAT_HUMIDITY_CONTROL_ACTION_HUMIDIFY; + } + + return target_action; +} + void ThermostatClimate::switch_to_action_(climate::ClimateAction action, bool publish_state) { // setup_complete_ helps us ensure an action is called immediately after boot if ((action == this->action) && this->setup_complete_) { @@ -596,6 +643,44 @@ void ThermostatClimate::trigger_supplemental_action_() { } } +void ThermostatClimate::switch_to_humidity_control_action_(HumidificationAction action) { + // setup_complete_ helps us ensure an action is called immediately after boot + if ((action == this->humidification_action_) && this->setup_complete_) { + // already in target mode + return; + } + + Trigger<> *trig = this->humidity_control_off_action_trigger_; + switch (action) { + case THERMOSTAT_HUMIDITY_CONTROL_ACTION_OFF: + // trig = this->humidity_control_off_action_trigger_; + ESP_LOGVV(TAG, "Switching to HUMIDIFICATION_OFF action"); + break; + case THERMOSTAT_HUMIDITY_CONTROL_ACTION_DEHUMIDIFY: + trig = this->humidity_control_dehumidify_action_trigger_; + ESP_LOGVV(TAG, "Switching to DEHUMIDIFY action"); + break; + case THERMOSTAT_HUMIDITY_CONTROL_ACTION_HUMIDIFY: + trig = this->humidity_control_humidify_action_trigger_; + ESP_LOGVV(TAG, "Switching to HUMIDIFY action"); + break; + case THERMOSTAT_HUMIDITY_CONTROL_ACTION_NONE: + default: + action = THERMOSTAT_HUMIDITY_CONTROL_ACTION_OFF; + // trig = this->humidity_control_off_action_trigger_; + } + + if (this->prev_humidity_control_trigger_ != nullptr) { + this->prev_humidity_control_trigger_->stop_action(); + this->prev_humidity_control_trigger_ = nullptr; + } + this->humidification_action_ = action; + this->prev_humidity_control_trigger_ = trig; + if (trig != nullptr) { + trig->trigger(); + } +} + void ThermostatClimate::switch_to_fan_mode_(climate::ClimateFanMode fan_mode, bool publish_state) { // setup_complete_ helps us ensure an action is called immediately after boot if ((fan_mode == this->prev_fan_mode_) && this->setup_complete_) { @@ -887,6 +972,20 @@ void ThermostatClimate::idle_on_timer_callback_() { this->switch_to_supplemental_action_(this->compute_supplemental_action_()); } +void ThermostatClimate::check_humidity_change_trigger_() { + if ((this->prev_target_humidity_ == this->target_humidity) && this->setup_complete_) { + return; // nothing changed, no reason to trigger + } else { + // save the new temperature so we can check it again later; the trigger will fire below + this->prev_target_humidity_ = this->target_humidity; + } + // trigger the action + Trigger<> *trig = this->humidity_change_trigger_; + if (trig != nullptr) { + trig->trigger(); + } +} + void ThermostatClimate::check_temperature_change_trigger_() { if (this->supports_two_points_) { // setup_complete_ helps us ensure an action is called immediately after boot @@ -996,6 +1095,32 @@ bool ThermostatClimate::supplemental_heating_required_() { (this->supplemental_action_ == climate::CLIMATE_ACTION_HEATING)); } +bool ThermostatClimate::dehumidification_required_() { + if (this->current_humidity > this->target_humidity + this->humidity_hysteresis_) { + // if the current humidity exceeds the target + hysteresis, dehumidification is required + return true; + } else if (this->current_humidity < this->target_humidity - this->humidity_hysteresis_) { + // if the current humidity is less than the target - hysteresis, dehumidification should stop + return false; + } + // if we get here, the current humidity is between target + hysteresis and target - hysteresis, + // so the action should not change + return this->humidification_action_ == THERMOSTAT_HUMIDITY_CONTROL_ACTION_DEHUMIDIFY; +} + +bool ThermostatClimate::humidification_required_() { + if (this->current_humidity < this->target_humidity - this->humidity_hysteresis_) { + // if the current humidity is below the target - hysteresis, humidification is required + return true; + } else if (this->current_humidity > this->target_humidity + this->humidity_hysteresis_) { + // if the current humidity is above the target + hysteresis, humidification should stop + return false; + } + // if we get here, the current humidity is between target - hysteresis and target + hysteresis, + // so the action should not change + return this->humidification_action_ == THERMOSTAT_HUMIDITY_CONTROL_ACTION_HUMIDIFY; +} + void ThermostatClimate::dump_preset_config_(const char *preset_name, const ThermostatClimateTargetTempConfig &config) { if (this->supports_heat_) { ESP_LOGCONFIG(TAG, " Default Target Temperature Low: %.1f°C", @@ -1152,8 +1277,12 @@ ThermostatClimate::ThermostatClimate() swing_mode_off_trigger_(new Trigger<>()), swing_mode_horizontal_trigger_(new Trigger<>()), swing_mode_vertical_trigger_(new Trigger<>()), + humidity_change_trigger_(new Trigger<>()), temperature_change_trigger_(new Trigger<>()), - preset_change_trigger_(new Trigger<>()) {} + preset_change_trigger_(new Trigger<>()), + humidity_control_dehumidify_action_trigger_(new Trigger<>()), + humidity_control_humidify_action_trigger_(new Trigger<>()), + humidity_control_off_action_trigger_(new Trigger<>()) {} void ThermostatClimate::set_default_preset(const std::string &custom_preset) { this->default_custom_preset_ = custom_preset; @@ -1217,6 +1346,9 @@ void ThermostatClimate::set_sensor(sensor::Sensor *sensor) { this->sensor_ = sen void ThermostatClimate::set_humidity_sensor(sensor::Sensor *humidity_sensor) { this->humidity_sensor_ = humidity_sensor; } +void ThermostatClimate::set_humidity_hysteresis(float humidity_hysteresis) { + this->humidity_hysteresis_ = std::clamp(humidity_hysteresis, 0.0f, 100.0f); +} void ThermostatClimate::set_use_startup_delay(bool use_startup_delay) { this->use_startup_delay_ = use_startup_delay; } void ThermostatClimate::set_supports_heat_cool(bool supports_heat_cool) { this->supports_heat_cool_ = supports_heat_cool; @@ -1284,6 +1416,18 @@ void ThermostatClimate::set_supports_swing_mode_vertical(bool supports_swing_mod void ThermostatClimate::set_supports_two_points(bool supports_two_points) { this->supports_two_points_ = supports_two_points; } +void ThermostatClimate::set_supports_dehumidification(bool supports_dehumidification) { + this->supports_dehumidification_ = supports_dehumidification; + if (supports_dehumidification) { + this->supports_humidification_ = false; + } +} +void ThermostatClimate::set_supports_humidification(bool supports_humidification) { + this->supports_humidification_ = supports_humidification; + if (supports_humidification) { + this->supports_dehumidification_ = false; + } +} Trigger<> *ThermostatClimate::get_cool_action_trigger() const { return this->cool_action_trigger_; } Trigger<> *ThermostatClimate::get_supplemental_cool_action_trigger() const { @@ -1317,8 +1461,18 @@ Trigger<> *ThermostatClimate::get_swing_mode_both_trigger() const { return this- Trigger<> *ThermostatClimate::get_swing_mode_off_trigger() const { return this->swing_mode_off_trigger_; } Trigger<> *ThermostatClimate::get_swing_mode_horizontal_trigger() const { return this->swing_mode_horizontal_trigger_; } Trigger<> *ThermostatClimate::get_swing_mode_vertical_trigger() const { return this->swing_mode_vertical_trigger_; } +Trigger<> *ThermostatClimate::get_humidity_change_trigger() const { return this->humidity_change_trigger_; } Trigger<> *ThermostatClimate::get_temperature_change_trigger() const { return this->temperature_change_trigger_; } Trigger<> *ThermostatClimate::get_preset_change_trigger() const { return this->preset_change_trigger_; } +Trigger<> *ThermostatClimate::get_humidity_control_dehumidify_action_trigger() const { + return this->humidity_control_dehumidify_action_trigger_; +} +Trigger<> *ThermostatClimate::get_humidity_control_humidify_action_trigger() const { + return this->humidity_control_humidify_action_trigger_; +} +Trigger<> *ThermostatClimate::get_humidity_control_off_action_trigger() const { + return this->humidity_control_off_action_trigger_; +} void ThermostatClimate::dump_config() { LOG_CLIMATE("", "Thermostat", this); @@ -1422,7 +1576,12 @@ void ThermostatClimate::dump_config() { " OFF: %s\n" " HORIZONTAL: %s\n" " VERTICAL: %s\n" - " Supports TWO SET POINTS: %s", + " Supports TWO SET POINTS: %s\n" + " Supported Humidity Parameters:\n" + " CURRENT: %s\n" + " TARGET: %s\n" + " DEHUMIDIFICATION: %s\n" + " HUMIDIFICATION: %s", YESNO(this->supports_fan_mode_on_), YESNO(this->supports_fan_mode_off_), YESNO(this->supports_fan_mode_auto_), YESNO(this->supports_fan_mode_low_), YESNO(this->supports_fan_mode_medium_), YESNO(this->supports_fan_mode_high_), @@ -1430,7 +1589,10 @@ void ThermostatClimate::dump_config() { YESNO(this->supports_fan_mode_diffuse_), YESNO(this->supports_fan_mode_quiet_), YESNO(this->supports_swing_mode_both_), YESNO(this->supports_swing_mode_off_), YESNO(this->supports_swing_mode_horizontal_), YESNO(this->supports_swing_mode_vertical_), - YESNO(this->supports_two_points_)); + YESNO(this->supports_two_points_), + YESNO(this->get_traits().has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_HUMIDITY)), + YESNO(this->supports_dehumidification_ || this->supports_humidification_), + YESNO(this->supports_dehumidification_), YESNO(this->supports_humidification_)); if (!this->preset_config_.empty()) { ESP_LOGCONFIG(TAG, " Supported PRESETS:"); diff --git a/esphome/components/thermostat/thermostat_climate.h b/esphome/components/thermostat/thermostat_climate.h index 526f07116e..363d2b09fc 100644 --- a/esphome/components/thermostat/thermostat_climate.h +++ b/esphome/components/thermostat/thermostat_climate.h @@ -13,6 +13,13 @@ namespace esphome { namespace thermostat { +enum HumidificationAction : uint8_t { + THERMOSTAT_HUMIDITY_CONTROL_ACTION_OFF = 0, + THERMOSTAT_HUMIDITY_CONTROL_ACTION_DEHUMIDIFY = 1, + THERMOSTAT_HUMIDITY_CONTROL_ACTION_HUMIDIFY = 2, + THERMOSTAT_HUMIDITY_CONTROL_ACTION_NONE, +}; + enum ThermostatClimateTimerIndex : uint8_t { THERMOSTAT_TIMER_COOLING_MAX_RUN_TIME = 0, THERMOSTAT_TIMER_COOLING_OFF = 1, @@ -90,6 +97,7 @@ class ThermostatClimate : public climate::Climate, public Component { void set_idle_minimum_time_in_sec(uint32_t time); void set_sensor(sensor::Sensor *sensor); void set_humidity_sensor(sensor::Sensor *humidity_sensor); + void set_humidity_hysteresis(float humidity_hysteresis); void set_use_startup_delay(bool use_startup_delay); void set_supports_auto(bool supports_auto); void set_supports_heat_cool(bool supports_heat_cool); @@ -115,6 +123,8 @@ class ThermostatClimate : public climate::Climate, public Component { void set_supports_swing_mode_horizontal(bool supports_swing_mode_horizontal); void set_supports_swing_mode_off(bool supports_swing_mode_off); void set_supports_swing_mode_vertical(bool supports_swing_mode_vertical); + void set_supports_dehumidification(bool supports_dehumidification); + void set_supports_humidification(bool supports_humidification); void set_supports_two_points(bool supports_two_points); void set_preset_config(climate::ClimatePreset preset, const ThermostatClimateTargetTempConfig &config); @@ -148,8 +158,12 @@ class ThermostatClimate : public climate::Climate, public Component { Trigger<> *get_swing_mode_horizontal_trigger() const; Trigger<> *get_swing_mode_off_trigger() const; Trigger<> *get_swing_mode_vertical_trigger() const; + Trigger<> *get_humidity_change_trigger() const; Trigger<> *get_temperature_change_trigger() const; Trigger<> *get_preset_change_trigger() const; + Trigger<> *get_humidity_control_dehumidify_action_trigger() const; + Trigger<> *get_humidity_control_humidify_action_trigger() const; + Trigger<> *get_humidity_control_off_action_trigger() const; /// Get current hysteresis values float cool_deadband(); float cool_overrun(); @@ -166,11 +180,13 @@ class ThermostatClimate : public climate::Climate, public Component { climate::ClimateFanMode locked_fan_mode(); /// Set point and hysteresis validation bool hysteresis_valid(); // returns true if valid + bool humidity_hysteresis_valid(); // returns true if valid bool limit_setpoints_for_heat_cool(); // returns true if set points should be further limited within visual range void validate_target_temperature(); void validate_target_temperatures(bool pin_target_temperature_high); void validate_target_temperature_low(); void validate_target_temperature_high(); + void validate_target_humidity(); protected: /// Override control to change settings of the climate device. @@ -192,11 +208,13 @@ class ThermostatClimate : public climate::Climate, public Component { /// Re-compute the required action of this climate controller. climate::ClimateAction compute_action_(bool ignore_timers = false); climate::ClimateAction compute_supplemental_action_(); + HumidificationAction compute_humidity_control_action_(); /// Switch the climate device to the given climate action. void switch_to_action_(climate::ClimateAction action, bool publish_state = true); void switch_to_supplemental_action_(climate::ClimateAction action); void trigger_supplemental_action_(); + void switch_to_humidity_control_action_(HumidificationAction action); /// Switch the climate device to the given climate fan mode. void switch_to_fan_mode_(climate::ClimateFanMode fan_mode, bool publish_state = true); @@ -207,6 +225,9 @@ class ThermostatClimate : public climate::Climate, public Component { /// Switch the climate device to the given climate swing mode. void switch_to_swing_mode_(climate::ClimateSwingMode swing_mode, bool publish_state = true); + /// Check if the humidity change trigger should be called. + void check_humidity_change_trigger_(); + /// Check if the temperature change trigger should be called. void check_temperature_change_trigger_(); @@ -243,6 +264,8 @@ class ThermostatClimate : public climate::Climate, public Component { bool heating_required_(); bool supplemental_cooling_required_(); bool supplemental_heating_required_(); + bool dehumidification_required_(); + bool humidification_required_(); void dump_preset_config_(const char *preset_name, const ThermostatClimateTargetTempConfig &config); @@ -259,6 +282,9 @@ class ThermostatClimate : public climate::Climate, public Component { /// The current supplemental action climate::ClimateAction supplemental_action_{climate::CLIMATE_ACTION_OFF}; + /// The current humidification action + HumidificationAction humidification_action_{THERMOSTAT_HUMIDITY_CONTROL_ACTION_NONE}; + /// Default standard preset to use on start up climate::ClimatePreset default_preset_{}; @@ -321,6 +347,12 @@ class ThermostatClimate : public climate::Climate, public Component { /// A false value means that the controller has no such support. bool supports_two_points_{false}; + /// Whether the controller supports dehumidification and/or humidification + /// + /// A false value means that the controller has no such support. + bool supports_dehumidification_{false}; + bool supports_humidification_{false}; + /// Flags indicating if maximum allowable run time was exceeded bool cooling_max_runtime_exceeded_{false}; bool heating_max_runtime_exceeded_{false}; @@ -331,9 +363,10 @@ class ThermostatClimate : public climate::Climate, public Component { /// setup_complete_ blocks modifying/resetting the temps immediately after boot bool setup_complete_{false}; - /// Store previously-known temperatures + /// Store previously-known humidity and temperatures /// - /// These are used to determine when the temperature change trigger/action needs to be called + /// These are used to determine when a temperature/humidity has changed + float prev_target_humidity_{NAN}; float prev_target_temperature_{NAN}; float prev_target_temperature_low_{NAN}; float prev_target_temperature_high_{NAN}; @@ -347,6 +380,9 @@ class ThermostatClimate : public climate::Climate, public Component { float heating_deadband_{0}; float heating_overrun_{0}; + /// Hysteresis values used for computing humidification action + float humidity_hysteresis_{0}; + /// Maximum allowable temperature deltas before engaging supplemental cooling/heating actions float supplemental_cool_delta_{0}; float supplemental_heat_delta_{0}; @@ -448,12 +484,24 @@ class ThermostatClimate : public climate::Climate, public Component { /// The trigger to call when the controller should switch the swing mode to "vertical". Trigger<> *swing_mode_vertical_trigger_{nullptr}; + /// The trigger to call when the target humidity changes. + Trigger<> *humidity_change_trigger_{nullptr}; + /// The trigger to call when the target temperature(s) change(es). Trigger<> *temperature_change_trigger_{nullptr}; /// The trigger to call when the preset mode changes Trigger<> *preset_change_trigger_{nullptr}; + /// The trigger to call when dehumidification is required + Trigger<> *humidity_control_dehumidify_action_trigger_{nullptr}; + + /// The trigger to call when humidification is required + Trigger<> *humidity_control_humidify_action_trigger_{nullptr}; + + /// The trigger to call when (de)humidification should stop + Trigger<> *humidity_control_off_action_trigger_{nullptr}; + /// A reference to the trigger that was previously active. /// /// This is so that the previous trigger can be stopped before enabling a new one @@ -462,6 +510,7 @@ class ThermostatClimate : public climate::Climate, public Component { Trigger<> *prev_fan_mode_trigger_{nullptr}; Trigger<> *prev_mode_trigger_{nullptr}; Trigger<> *prev_swing_mode_trigger_{nullptr}; + Trigger<> *prev_humidity_control_trigger_{nullptr}; /// Default custom preset to use on start up std::string default_custom_preset_{}; diff --git a/esphome/components/web_server/web_server.cpp b/esphome/components/web_server/web_server.cpp index f18f21b16b..1d08ef5a35 100644 --- a/esphome/components/web_server/web_server.cpp +++ b/esphome/components/web_server/web_server.cpp @@ -1325,7 +1325,7 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf root["max_temp"] = value_accuracy_to_string(traits.get_visual_max_temperature(), target_accuracy); root["min_temp"] = value_accuracy_to_string(traits.get_visual_min_temperature(), target_accuracy); root["step"] = traits.get_visual_target_temperature_step(); - if (traits.get_supports_action()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_ACTION)) { root["action"] = PSTR_LOCAL(climate_action_to_string(obj->action)); root["state"] = root["action"]; has_state = true; @@ -1345,14 +1345,15 @@ std::string WebServer::climate_json(climate::Climate *obj, JsonDetail start_conf if (traits.get_supports_swing_modes()) { root["swing_mode"] = PSTR_LOCAL(climate_swing_mode_to_string(obj->swing_mode)); } - if (traits.get_supports_current_temperature()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_CURRENT_TEMPERATURE)) { if (!std::isnan(obj->current_temperature)) { root["current_temperature"] = value_accuracy_to_string(obj->current_temperature, current_accuracy); } else { root["current_temperature"] = "NA"; } } - if (traits.get_supports_two_point_target_temperature()) { + if (traits.has_feature_flags(climate::CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE | + climate::CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE)) { root["target_temperature_low"] = value_accuracy_to_string(obj->target_temperature_low, target_accuracy); root["target_temperature_high"] = value_accuracy_to_string(obj->target_temperature_high, target_accuracy); if (!has_state) { diff --git a/esphome/components/xgzp68xx/sensor.py b/esphome/components/xgzp68xx/sensor.py index 74cef3bf7b..2b38392a02 100644 --- a/esphome/components/xgzp68xx/sensor.py +++ b/esphome/components/xgzp68xx/sensor.py @@ -3,6 +3,7 @@ from esphome.components import i2c, sensor import esphome.config_validation as cv from esphome.const import ( CONF_ID, + CONF_OVERSAMPLING, CONF_PRESSURE, CONF_TEMPERATURE, DEVICE_CLASS_PRESSURE, @@ -18,6 +19,17 @@ CODEOWNERS = ["@gcormier"] CONF_K_VALUE = "k_value" xgzp68xx_ns = cg.esphome_ns.namespace("xgzp68xx") +XGZP68XXOversampling = xgzp68xx_ns.enum("XGZP68XXOversampling") +OVERSAMPLING_OPTIONS = { + "256X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_256X, + "512X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_512X, + "1024X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_1024X, + "2048X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_2048X, + "4096X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_4096X, + "8192X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_8192X, + "16384X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_16384X, + "32768X": XGZP68XXOversampling.XGZP68XX_OVERSAMPLING_32768X, +} XGZP68XXComponent = xgzp68xx_ns.class_( "XGZP68XXComponent", cg.PollingComponent, i2c.I2CDevice ) @@ -31,6 +43,12 @@ CONFIG_SCHEMA = ( accuracy_decimals=1, device_class=DEVICE_CLASS_PRESSURE, state_class=STATE_CLASS_MEASUREMENT, + ).extend( + { + cv.Optional(CONF_OVERSAMPLING, default="4096X"): cv.enum( + OVERSAMPLING_OPTIONS, upper=True + ), + } ), cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( unit_of_measurement=UNIT_CELSIUS, @@ -58,5 +76,6 @@ async def to_code(config): if pressure_config := config.get(CONF_PRESSURE): sens = await sensor.new_sensor(pressure_config) cg.add(var.set_pressure_sensor(sens)) + cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING])) cg.add(var.set_k_value(config[CONF_K_VALUE])) diff --git a/esphome/components/xgzp68xx/xgzp68xx.cpp b/esphome/components/xgzp68xx/xgzp68xx.cpp index 20a97cd04b..2b0824de0a 100644 --- a/esphome/components/xgzp68xx/xgzp68xx.cpp +++ b/esphome/components/xgzp68xx/xgzp68xx.cpp @@ -16,16 +16,49 @@ static const uint8_t SYSCONFIG_ADDRESS = 0xA5; static const uint8_t PCONFIG_ADDRESS = 0xA6; static const uint8_t READ_COMMAND = 0x0A; +[[maybe_unused]] static const char *oversampling_to_str(XGZP68XXOversampling oversampling) { + switch (oversampling) { + case XGZP68XX_OVERSAMPLING_256X: + return "256x"; + case XGZP68XX_OVERSAMPLING_512X: + return "512x"; + case XGZP68XX_OVERSAMPLING_1024X: + return "1024x"; + case XGZP68XX_OVERSAMPLING_2048X: + return "2048x"; + case XGZP68XX_OVERSAMPLING_4096X: + return "4096x"; + case XGZP68XX_OVERSAMPLING_8192X: + return "8192x"; + case XGZP68XX_OVERSAMPLING_16384X: + return "16384x"; + case XGZP68XX_OVERSAMPLING_32768X: + return "32768x"; + default: + return "UNKNOWN"; + } +} + void XGZP68XXComponent::update() { + // Do we need to change oversampling? + if (this->last_pressure_oversampling_ != this->pressure_oversampling_) { + uint8_t oldconfig = 0; + this->read_register(PCONFIG_ADDRESS, &oldconfig, 1); + uint8_t newconfig = (oldconfig & 0xf8) | (this->pressure_oversampling_ & 0x7); + this->write_register(PCONFIG_ADDRESS, &newconfig, 1); + ESP_LOGD(TAG, "oversampling to %s: oldconfig = 0x%x newconfig = 0x%x", + oversampling_to_str(this->pressure_oversampling_), oldconfig, newconfig); + this->last_pressure_oversampling_ = this->pressure_oversampling_; + } + // Request temp + pressure acquisition this->write_register(0x30, &READ_COMMAND, 1); // Wait 20mS per datasheet this->set_timeout("measurement", 20, [this]() { - uint8_t data[5]; - uint32_t pressure_raw; - uint16_t temperature_raw; - float pressure_in_pa, temperature; + uint8_t data[5] = {}; + uint32_t pressure_raw = 0; + uint16_t temperature_raw = 0; int success; // Read the sensor data @@ -42,23 +75,11 @@ void XGZP68XXComponent::update() { ESP_LOGV(TAG, "Got raw pressure=%" PRIu32 ", raw temperature=%u", pressure_raw, temperature_raw); ESP_LOGV(TAG, "K value is %u", this->k_value_); - // The most significant bit of both pressure and temperature will be 1 to indicate a negative value. - // This is directly from the datasheet, and the calculations below will handle this. - if (pressure_raw > pow(2, 23)) { - // Negative pressure - pressure_in_pa = (pressure_raw - pow(2, 24)) / (float) (this->k_value_); - } else { - // Positive pressure - pressure_in_pa = pressure_raw / (float) (this->k_value_); - } + // Sign extend the pressure + float pressure_in_pa = (float) (((int32_t) pressure_raw << 8) >> 8); + pressure_in_pa /= (float) (this->k_value_); - if (temperature_raw > pow(2, 15)) { - // Negative temperature - temperature = (float) (temperature_raw - pow(2, 16)) / 256.0f; - } else { - // Positive temperature - temperature = (float) temperature_raw / 256.0f; - } + float temperature = ((float) (int16_t) temperature_raw) / 256.0f; if (this->pressure_sensor_ != nullptr) this->pressure_sensor_->publish_state(pressure_in_pa); @@ -69,20 +90,27 @@ void XGZP68XXComponent::update() { } void XGZP68XXComponent::setup() { - uint8_t config; + uint8_t config1 = 0, config2 = 0; // Display some sample bits to confirm we are talking to the sensor - this->read_register(SYSCONFIG_ADDRESS, &config, 1); - ESP_LOGCONFIG(TAG, - "Gain value is %d\n" - "XGZP68xx started!", - (config >> 3) & 0b111); + if (i2c::ErrorCode::ERROR_OK != this->read_register(SYSCONFIG_ADDRESS, &config1, 1)) { + this->mark_failed(); + return; + } + if (i2c::ErrorCode::ERROR_OK != this->read_register(PCONFIG_ADDRESS, &config2, 1)) { + this->mark_failed(); + return; + } + ESP_LOGD(TAG, "sys_config 0x%x, p_config 0x%x", config1, config2); } void XGZP68XXComponent::dump_config() { ESP_LOGCONFIG(TAG, "XGZP68xx:"); LOG_SENSOR(" ", "Temperature: ", this->temperature_sensor_); LOG_SENSOR(" ", "Pressure: ", this->pressure_sensor_); + if (this->pressure_sensor_ != nullptr) { + ESP_LOGCONFIG(TAG, " Oversampling: %s", oversampling_to_str(this->pressure_oversampling_)); + } LOG_I2C_DEVICE(this); if (this->is_failed()) { ESP_LOGE(TAG, " Connection failed"); diff --git a/esphome/components/xgzp68xx/xgzp68xx.h b/esphome/components/xgzp68xx/xgzp68xx.h index 1bb7304b15..ce9cfd6b78 100644 --- a/esphome/components/xgzp68xx/xgzp68xx.h +++ b/esphome/components/xgzp68xx/xgzp68xx.h @@ -7,11 +7,29 @@ namespace esphome { namespace xgzp68xx { +/// Enum listing all oversampling options for the XGZP68XX. +enum XGZP68XXOversampling : uint8_t { + XGZP68XX_OVERSAMPLING_256X = 0b100, + XGZP68XX_OVERSAMPLING_512X = 0b101, + XGZP68XX_OVERSAMPLING_1024X = 0b000, + XGZP68XX_OVERSAMPLING_2048X = 0b001, + XGZP68XX_OVERSAMPLING_4096X = 0b010, + XGZP68XX_OVERSAMPLING_8192X = 0b011, + XGZP68XX_OVERSAMPLING_16384X = 0b110, + XGZP68XX_OVERSAMPLING_32768X = 0b111, + + XGZP68XX_OVERSAMPLING_UNKNOWN = (uint8_t) -1, +}; + class XGZP68XXComponent : public PollingComponent, public sensor::Sensor, public i2c::I2CDevice { public: SUB_SENSOR(temperature) SUB_SENSOR(pressure) void set_k_value(uint16_t k_value) { this->k_value_ = k_value; } + /// Set the pressure oversampling value. Defaults to 4096X. + void set_pressure_oversampling(XGZP68XXOversampling pressure_oversampling) { + this->pressure_oversampling_ = pressure_oversampling; + } void update() override; void setup() override; @@ -21,6 +39,8 @@ class XGZP68XXComponent : public PollingComponent, public sensor::Sensor, public /// Internal method to read the pressure from the component after it has been scheduled. void read_pressure_(); uint16_t k_value_; + XGZP68XXOversampling pressure_oversampling_{XGZP68XX_OVERSAMPLING_4096X}; + XGZP68XXOversampling last_pressure_oversampling_{XGZP68XX_OVERSAMPLING_UNKNOWN}; }; } // namespace xgzp68xx diff --git a/esphome/dashboard/web_server.py b/esphome/dashboard/web_server.py index a79c67c3d2..804a2b99af 100644 --- a/esphome/dashboard/web_server.py +++ b/esphome/dashboard/web_server.py @@ -1058,7 +1058,8 @@ class DownloadBinaryRequestHandler(BaseHandler): "download", f"{storage_json.name}-{file_name}", ) - path = storage_json.firmware_bin_path.with_name(file_name) + + path = storage_json.firmware_bin_path.parent.joinpath(file_name) if not path.is_file(): args = ["esphome", "idedata", settings.rel_path(configuration)] diff --git a/requirements.txt b/requirements.txt index 92ab24e754..ec7794c75a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ platformio==6.1.18 # When updating platformio, also update /docker/Dockerfile esptool==5.1.0 click==8.1.7 esphome-dashboard==20251013.0 -aioesphomeapi==42.0.0 +aioesphomeapi==42.2.0 zeroconf==0.148.0 puremagic==1.30 ruamel.yaml==0.18.15 # dashboard_import diff --git a/script/analyze_component_buses.py b/script/analyze_component_buses.py index 98edfef145..d0882e22e9 100755 --- a/script/analyze_component_buses.py +++ b/script/analyze_component_buses.py @@ -50,7 +50,14 @@ PACKAGE_DEPENDENCIES = { # Bus types that can be defined directly in config files # Components defining these directly cannot be grouped (they create unique bus IDs) -DIRECT_BUS_TYPES = ("i2c", "spi", "uart", "modbus") +DIRECT_BUS_TYPES = ( + "i2c", + "spi", + "uart", + "modbus", + "remote_transmitter", + "remote_receiver", +) # Signature for components with no bus requirements # These components can be merged with any other group @@ -68,6 +75,8 @@ BASE_BUS_COMPONENTS = { "uart", "modbus", "canbus", + "remote_transmitter", + "remote_receiver", } # Components that must be tested in isolation (not grouped or batched with others) diff --git a/tests/components/absolute_humidity/common.yaml b/tests/components/absolute_humidity/common.yaml index 87a99f5206..026f88654f 100644 --- a/tests/components/absolute_humidity/common.yaml +++ b/tests/components/absolute_humidity/common.yaml @@ -8,14 +8,12 @@ sensor: lambda: |- if (millis() > 10000) { return 0.6; - } else { - return 0.0; } + return 0.0; - platform: template id: template_temperature lambda: |- if (millis() > 10000) { return 42.0; - } else { - return 0.0; } + return 0.0; diff --git a/tests/components/analog_threshold/common.yaml b/tests/components/analog_threshold/common.yaml index 44d79756b5..26c401b92a 100644 --- a/tests/components/analog_threshold/common.yaml +++ b/tests/components/analog_threshold/common.yaml @@ -5,9 +5,8 @@ sensor: lambda: |- if (millis() > 10000) { return 42.0; - } else { - return 0.0; } + return 0.0; update_interval: 15s binary_sensor: diff --git a/tests/components/ballu/common.yaml b/tests/components/ballu/common.yaml index 52f86aa26a..178c39b8ce 100644 --- a/tests/components/ballu/common.yaml +++ b/tests/components/ballu/common.yaml @@ -1,7 +1,3 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: heatpumpir protocol: ballu @@ -10,3 +6,4 @@ climate: name: HeatpumpIR Climate min_temperature: 18 max_temperature: 30 + transmitter_id: xmitr diff --git a/tests/components/ballu/test.esp8266-ard.yaml b/tests/components/ballu/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/ballu/test.esp8266-ard.yaml +++ b/tests/components/ballu/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/binary_sensor/common.yaml b/tests/components/binary_sensor/common.yaml index 2b4a006352..ed6322768f 100644 --- a/tests/components/binary_sensor/common.yaml +++ b/tests/components/binary_sensor/common.yaml @@ -23,9 +23,8 @@ binary_sensor: - lambda: |- if (id(some_binary_sensor).state) { return x; - } else { - return {}; } + return {}; - settle: 100ms - timeout: 10s diff --git a/tests/components/binary_sensor_map/common.yaml b/tests/components/binary_sensor_map/common.yaml index 2fed5ae515..c054022583 100644 --- a/tests/components/binary_sensor_map/common.yaml +++ b/tests/components/binary_sensor_map/common.yaml @@ -4,25 +4,22 @@ binary_sensor: lambda: |- if (millis() > 10000) { return true; - } else { - return false; } + return false; - platform: template id: bin2 lambda: |- if (millis() > 20000) { return true; - } else { - return false; } + return false; - platform: template id: bin3 lambda: |- if (millis() > 30000) { return true; - } else { - return false; } + return false; sensor: - platform: binary_sensor_map diff --git a/tests/components/climate_ir_lg/common.yaml b/tests/components/climate_ir_lg/common.yaml index c8f84411c0..da0d656b21 100644 --- a/tests/components/climate_ir_lg/common.yaml +++ b/tests/components/climate_ir_lg/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: climate_ir_lg name: LG Climate + transmitter_id: xmitr diff --git a/tests/components/climate_ir_lg/test.esp32-c3-idf.yaml b/tests/components/climate_ir_lg/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/climate_ir_lg/test.esp32-c3-idf.yaml +++ b/tests/components/climate_ir_lg/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/climate_ir_lg/test.esp32-idf.yaml b/tests/components/climate_ir_lg/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/climate_ir_lg/test.esp32-idf.yaml +++ b/tests/components/climate_ir_lg/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/climate_ir_lg/test.esp8266-ard.yaml b/tests/components/climate_ir_lg/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/climate_ir_lg/test.esp8266-ard.yaml +++ b/tests/components/climate_ir_lg/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/combination/common.yaml b/tests/components/combination/common.yaml index 62246190af..0e5d512d08 100644 --- a/tests/components/combination/common.yaml +++ b/tests/components/combination/common.yaml @@ -4,17 +4,15 @@ sensor: lambda: |- if (millis() > 10000) { return 0.6; - } else { - return 0.0; } + return 0.0; - platform: template id: template_temperature2 lambda: |- if (millis() > 20000) { return 0.8; - } else { - return 0.0; } + return 0.0; - platform: combination type: kalman name: Kalman-filtered temperature diff --git a/tests/components/coolix/common.yaml b/tests/components/coolix/common.yaml index abe609c3ea..a1f68b8be0 100644 --- a/tests/components/coolix/common.yaml +++ b/tests/components/coolix/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: coolix name: Coolix Climate + transmitter_id: xmitr diff --git a/tests/components/coolix/test.esp32-c3-idf.yaml b/tests/components/coolix/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/coolix/test.esp32-c3-idf.yaml +++ b/tests/components/coolix/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/coolix/test.esp32-idf.yaml b/tests/components/coolix/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/coolix/test.esp32-idf.yaml +++ b/tests/components/coolix/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/coolix/test.esp8266-ard.yaml b/tests/components/coolix/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/coolix/test.esp8266-ard.yaml +++ b/tests/components/coolix/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/daikin/common.yaml b/tests/components/daikin/common.yaml index 27f381b422..fd73841686 100644 --- a/tests/components/daikin/common.yaml +++ b/tests/components/daikin/common.yaml @@ -1,7 +1,3 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: heatpumpir protocol: daikin @@ -10,3 +6,4 @@ climate: name: HeatpumpIR Climate min_temperature: 18 max_temperature: 30 + transmitter_id: xmitr diff --git a/tests/components/daikin/test.esp8266-ard.yaml b/tests/components/daikin/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/daikin/test.esp8266-ard.yaml +++ b/tests/components/daikin/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/daikin_arc/common.yaml b/tests/components/daikin_arc/common.yaml index 5c0510f6df..53df3cf911 100644 --- a/tests/components/daikin_arc/common.yaml +++ b/tests/components/daikin_arc/common.yaml @@ -1,18 +1,3 @@ -remote_transmitter: - pin: ${tx_pin} - carrier_duty_percent: 50% - id: tsvr - -remote_receiver: - id: rcvr - pin: - number: ${rx_pin} - inverted: true - mode: - input: true - pullup: true - tolerance: 40% - climate: - platform: daikin_arc name: Daikin AC diff --git a/tests/components/daikin_arc/test.esp8266-ard.yaml b/tests/components/daikin_arc/test.esp8266-ard.yaml index 5698a7ef5f..aa8651e556 100644 --- a/tests/components/daikin_arc/test.esp8266-ard.yaml +++ b/tests/components/daikin_arc/test.esp8266-ard.yaml @@ -1,5 +1,5 @@ -substitutions: - tx_pin: GPIO0 - rx_pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml + remote_receiver: !include ../../test_build_components/common/remote_receiver/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/daikin_brc/common.yaml b/tests/components/daikin_brc/common.yaml index c9d7baa989..89786954ba 100644 --- a/tests/components/daikin_brc/common.yaml +++ b/tests/components/daikin_brc/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: daikin_brc name: Daikin_brc Climate + transmitter_id: xmitr diff --git a/tests/components/daikin_brc/test.esp32-c3-idf.yaml b/tests/components/daikin_brc/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/daikin_brc/test.esp32-c3-idf.yaml +++ b/tests/components/daikin_brc/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/daikin_brc/test.esp32-idf.yaml b/tests/components/daikin_brc/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/daikin_brc/test.esp32-idf.yaml +++ b/tests/components/daikin_brc/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/daikin_brc/test.esp8266-ard.yaml b/tests/components/daikin_brc/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/daikin_brc/test.esp8266-ard.yaml +++ b/tests/components/daikin_brc/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/delonghi/common.yaml b/tests/components/delonghi/common.yaml index 8e9a1293d7..c3935adcbd 100644 --- a/tests/components/delonghi/common.yaml +++ b/tests/components/delonghi/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: delonghi name: Delonghi Climate + transmitter_id: xmitr diff --git a/tests/components/delonghi/test.esp32-c3-idf.yaml b/tests/components/delonghi/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/delonghi/test.esp32-c3-idf.yaml +++ b/tests/components/delonghi/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/delonghi/test.esp32-idf.yaml b/tests/components/delonghi/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/delonghi/test.esp32-idf.yaml +++ b/tests/components/delonghi/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/delonghi/test.esp8266-ard.yaml b/tests/components/delonghi/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/delonghi/test.esp8266-ard.yaml +++ b/tests/components/delonghi/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/duty_time/common.yaml b/tests/components/duty_time/common.yaml index 28fa4afd1c..761d10f16a 100644 --- a/tests/components/duty_time/common.yaml +++ b/tests/components/duty_time/common.yaml @@ -4,9 +4,8 @@ binary_sensor: lambda: |- if (millis() > 10000) { return true; - } else { - return false; } + return false; sensor: - platform: duty_time diff --git a/tests/components/emmeti/common.yaml b/tests/components/emmeti/common.yaml index ac4201e19b..77f381ecf9 100644 --- a/tests/components/emmeti/common.yaml +++ b/tests/components/emmeti/common.yaml @@ -1,14 +1,5 @@ -remote_transmitter: - id: tx - pin: ${remote_transmitter_pin} - carrier_duty_percent: 100% - -remote_receiver: - id: rcvr - pin: ${remote_receiver_pin} - climate: - platform: emmeti name: Emmeti receiver_id: rcvr - transmitter_id: tx + transmitter_id: xmitr diff --git a/tests/components/emmeti/test.esp32-idf.yaml b/tests/components/emmeti/test.esp32-idf.yaml index 2689ff279e..b241dbd159 100644 --- a/tests/components/emmeti/test.esp32-idf.yaml +++ b/tests/components/emmeti/test.esp32-idf.yaml @@ -1,5 +1,5 @@ -substitutions: - remote_transmitter_pin: GPIO33 - remote_receiver_pin: GPIO32 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml + remote_receiver: !include ../../test_build_components/common/remote_receiver/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/emmeti/test.esp8266-ard.yaml b/tests/components/emmeti/test.esp8266-ard.yaml index 1c9baa4ea3..aa8651e556 100644 --- a/tests/components/emmeti/test.esp8266-ard.yaml +++ b/tests/components/emmeti/test.esp8266-ard.yaml @@ -1,5 +1,5 @@ -substitutions: - remote_transmitter_pin: GPIO0 - remote_receiver_pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml + remote_receiver: !include ../../test_build_components/common/remote_receiver/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/endstop/common.yaml b/tests/components/endstop/common.yaml index 341fbf7260..b92b1e13b9 100644 --- a/tests/components/endstop/common.yaml +++ b/tests/components/endstop/common.yaml @@ -4,9 +4,8 @@ binary_sensor: lambda: |- if (millis() > 10000) { return true; - } else { - return false; } + return false; switch: - platform: template diff --git a/tests/components/fujitsu_general/common.yaml b/tests/components/fujitsu_general/common.yaml index 3359b89f2a..51bd1441c0 100644 --- a/tests/components/fujitsu_general/common.yaml +++ b/tests/components/fujitsu_general/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: fujitsu_general name: Fujitsu General Climate + transmitter_id: xmitr diff --git a/tests/components/fujitsu_general/test.esp32-c3-idf.yaml b/tests/components/fujitsu_general/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/fujitsu_general/test.esp32-c3-idf.yaml +++ b/tests/components/fujitsu_general/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/fujitsu_general/test.esp32-idf.yaml b/tests/components/fujitsu_general/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/fujitsu_general/test.esp32-idf.yaml +++ b/tests/components/fujitsu_general/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/fujitsu_general/test.esp8266-ard.yaml b/tests/components/fujitsu_general/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/fujitsu_general/test.esp8266-ard.yaml +++ b/tests/components/fujitsu_general/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/gree/common.yaml b/tests/components/gree/common.yaml index c221184bbf..e706076034 100644 --- a/tests/components/gree/common.yaml +++ b/tests/components/gree/common.yaml @@ -1,8 +1,5 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: gree name: GREE model: generic + transmitter_id: xmitr diff --git a/tests/components/gree/test.esp32-c3-idf.yaml b/tests/components/gree/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/gree/test.esp32-c3-idf.yaml +++ b/tests/components/gree/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/gree/test.esp32-idf.yaml b/tests/components/gree/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/gree/test.esp32-idf.yaml +++ b/tests/components/gree/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/gree/test.esp8266-ard.yaml b/tests/components/gree/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/gree/test.esp8266-ard.yaml +++ b/tests/components/gree/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/heatpumpir/common.yaml b/tests/components/heatpumpir/common.yaml index d740f31518..a2779f9803 100644 --- a/tests/components/heatpumpir/common.yaml +++ b/tests/components/heatpumpir/common.yaml @@ -1,7 +1,3 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: heatpumpir protocol: mitsubishi_heavy_zm @@ -10,6 +6,7 @@ climate: name: HeatpumpIR Climate Mitsubishi min_temperature: 18 max_temperature: 30 + transmitter_id: xmitr - platform: heatpumpir protocol: daikin horizontal_default: mleft @@ -17,6 +14,7 @@ climate: name: HeatpumpIR Climate Daikin min_temperature: 18 max_temperature: 30 + transmitter_id: xmitr - platform: heatpumpir protocol: panasonic_altdke horizontal_default: mright @@ -24,3 +22,4 @@ climate: name: HeatpumpIR Climate Panasonic min_temperature: 18 max_temperature: 30 + transmitter_id: xmitr diff --git a/tests/components/heatpumpir/test.bk72xx-ard.yaml b/tests/components/heatpumpir/test.bk72xx-ard.yaml index 06e1aea364..6cce191825 100644 --- a/tests/components/heatpumpir/test.bk72xx-ard.yaml +++ b/tests/components/heatpumpir/test.bk72xx-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO6 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/bk72xx-ard.yaml <<: !include common.yaml diff --git a/tests/components/heatpumpir/test.esp32-ard.yaml b/tests/components/heatpumpir/test.esp32-ard.yaml index 7b012aa64c..01009de071 100644 --- a/tests/components/heatpumpir/test.esp32-ard.yaml +++ b/tests/components/heatpumpir/test.esp32-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-ard.yaml <<: !include common.yaml diff --git a/tests/components/heatpumpir/test.esp8266-ard.yaml b/tests/components/heatpumpir/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/heatpumpir/test.esp8266-ard.yaml +++ b/tests/components/heatpumpir/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/hitachi_ac344/common.yaml b/tests/components/hitachi_ac344/common.yaml index 960f032035..797e7875e5 100644 --- a/tests/components/hitachi_ac344/common.yaml +++ b/tests/components/hitachi_ac344/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: hitachi_ac344 name: Hitachi Climate + transmitter_id: xmitr diff --git a/tests/components/hitachi_ac344/test.bk72xx-ard.yaml b/tests/components/hitachi_ac344/test.bk72xx-ard.yaml index 06e1aea364..6cce191825 100644 --- a/tests/components/hitachi_ac344/test.bk72xx-ard.yaml +++ b/tests/components/hitachi_ac344/test.bk72xx-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO6 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/bk72xx-ard.yaml <<: !include common.yaml diff --git a/tests/components/hitachi_ac344/test.esp32-c3-idf.yaml b/tests/components/hitachi_ac344/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/hitachi_ac344/test.esp32-c3-idf.yaml +++ b/tests/components/hitachi_ac344/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/hitachi_ac344/test.esp32-idf.yaml b/tests/components/hitachi_ac344/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/hitachi_ac344/test.esp32-idf.yaml +++ b/tests/components/hitachi_ac344/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/hitachi_ac344/test.esp8266-ard.yaml b/tests/components/hitachi_ac344/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/hitachi_ac344/test.esp8266-ard.yaml +++ b/tests/components/hitachi_ac344/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/hitachi_ac424/common.yaml b/tests/components/hitachi_ac424/common.yaml index ad904c73a3..615bda4544 100644 --- a/tests/components/hitachi_ac424/common.yaml +++ b/tests/components/hitachi_ac424/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: hitachi_ac424 name: Hitachi Climate + transmitter_id: xmitr diff --git a/tests/components/hitachi_ac424/test.bk72xx-ard.yaml b/tests/components/hitachi_ac424/test.bk72xx-ard.yaml index 06e1aea364..6cce191825 100644 --- a/tests/components/hitachi_ac424/test.bk72xx-ard.yaml +++ b/tests/components/hitachi_ac424/test.bk72xx-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO6 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/bk72xx-ard.yaml <<: !include common.yaml diff --git a/tests/components/hitachi_ac424/test.esp32-c3-idf.yaml b/tests/components/hitachi_ac424/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/hitachi_ac424/test.esp32-c3-idf.yaml +++ b/tests/components/hitachi_ac424/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/hitachi_ac424/test.esp32-idf.yaml b/tests/components/hitachi_ac424/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/hitachi_ac424/test.esp32-idf.yaml +++ b/tests/components/hitachi_ac424/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/hitachi_ac424/test.esp8266-ard.yaml b/tests/components/hitachi_ac424/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/hitachi_ac424/test.esp8266-ard.yaml +++ b/tests/components/hitachi_ac424/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/lock/common.yaml b/tests/components/lock/common.yaml index 1ee88a239a..9ba7f34857 100644 --- a/tests/components/lock/common.yaml +++ b/tests/components/lock/common.yaml @@ -17,9 +17,8 @@ lock: lambda: |- if (millis() > 10000) { return LOCK_STATE_LOCKED; - } else { - return LOCK_STATE_UNLOCKED; } + return LOCK_STATE_UNLOCKED; optimistic: true assumed_state: false on_unlock: diff --git a/tests/components/midea/common.yaml b/tests/components/midea/common.yaml index a0909401ff..fec85aee96 100644 --- a/tests/components/midea/common.yaml +++ b/tests/components/midea/common.yaml @@ -2,10 +2,6 @@ wifi: ssid: MySSID password: password1 -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: midea id: midea_unit @@ -16,7 +12,7 @@ climate: x.set_mode(CLIMATE_MODE_FAN_ONLY); on_state: - logger.log: State changed! - transmitter_id: + transmitter_id: xmitr period: 1s num_attempts: 5 timeout: 2s diff --git a/tests/components/midea/test.esp32-ard.yaml b/tests/components/midea/test.esp32-ard.yaml index b78163199a..1e3fe0ff51 100644 --- a/tests/components/midea/test.esp32-ard.yaml +++ b/tests/components/midea/test.esp32-ard.yaml @@ -1,7 +1,5 @@ -substitutions: - pin: GPIO2 - packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-ard.yaml uart: !include ../../test_build_components/common/uart/esp32-ard.yaml <<: !include common.yaml diff --git a/tests/components/midea/test.esp8266-ard.yaml b/tests/components/midea/test.esp8266-ard.yaml index dc276e274c..9825ff85a1 100644 --- a/tests/components/midea/test.esp8266-ard.yaml +++ b/tests/components/midea/test.esp8266-ard.yaml @@ -1,7 +1,5 @@ -substitutions: - pin: GPIO15 - packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/midea_ir/common.yaml b/tests/components/midea_ir/common.yaml index e8d89cecc2..e4cc4bb19c 100644 --- a/tests/components/midea_ir/common.yaml +++ b/tests/components/midea_ir/common.yaml @@ -1,8 +1,5 @@ -remote_transmitter: - pin: 4 - carrier_duty_percent: 50% - climate: - platform: midea_ir name: Midea IR use_fahrenheit: true + transmitter_id: xmitr diff --git a/tests/components/midea_ir/test.esp32-c3-idf.yaml b/tests/components/midea_ir/test.esp32-c3-idf.yaml index dade44d145..43d5343715 100644 --- a/tests/components/midea_ir/test.esp32-c3-idf.yaml +++ b/tests/components/midea_ir/test.esp32-c3-idf.yaml @@ -1 +1,4 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml + <<: !include common.yaml diff --git a/tests/components/midea_ir/test.esp32-idf.yaml b/tests/components/midea_ir/test.esp32-idf.yaml index dade44d145..e891f9dc85 100644 --- a/tests/components/midea_ir/test.esp32-idf.yaml +++ b/tests/components/midea_ir/test.esp32-idf.yaml @@ -1 +1,4 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml + <<: !include common.yaml diff --git a/tests/components/midea_ir/test.esp8266-ard.yaml b/tests/components/midea_ir/test.esp8266-ard.yaml index dade44d145..4bed2f03e5 100644 --- a/tests/components/midea_ir/test.esp8266-ard.yaml +++ b/tests/components/midea_ir/test.esp8266-ard.yaml @@ -1 +1,4 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml + <<: !include common.yaml diff --git a/tests/components/mitsubishi/common.yaml b/tests/components/mitsubishi/common.yaml index c0fc959c5b..4a2deda163 100644 --- a/tests/components/mitsubishi/common.yaml +++ b/tests/components/mitsubishi/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: 4 - carrier_duty_percent: 50% - climate: - platform: mitsubishi name: Mitsubishi + transmitter_id: xmitr diff --git a/tests/components/mitsubishi/test.esp32-c3-idf.yaml b/tests/components/mitsubishi/test.esp32-c3-idf.yaml index dade44d145..43d5343715 100644 --- a/tests/components/mitsubishi/test.esp32-c3-idf.yaml +++ b/tests/components/mitsubishi/test.esp32-c3-idf.yaml @@ -1 +1,4 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml + <<: !include common.yaml diff --git a/tests/components/mitsubishi/test.esp32-idf.yaml b/tests/components/mitsubishi/test.esp32-idf.yaml index dade44d145..e891f9dc85 100644 --- a/tests/components/mitsubishi/test.esp32-idf.yaml +++ b/tests/components/mitsubishi/test.esp32-idf.yaml @@ -1 +1,4 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml + <<: !include common.yaml diff --git a/tests/components/mitsubishi/test.esp8266-ard.yaml b/tests/components/mitsubishi/test.esp8266-ard.yaml index dade44d145..4bed2f03e5 100644 --- a/tests/components/mitsubishi/test.esp8266-ard.yaml +++ b/tests/components/mitsubishi/test.esp8266-ard.yaml @@ -1 +1,4 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml + <<: !include common.yaml diff --git a/tests/components/mqtt/common.yaml b/tests/components/mqtt/common.yaml index 1ab8872fdb..3f1b83bb01 100644 --- a/tests/components/mqtt/common.yaml +++ b/tests/components/mqtt/common.yaml @@ -72,10 +72,9 @@ binary_sensor: if (id(template_sens).state > 30) { // Garage Door is open. return true; - } else { - // Garage Door is closed. - return false; } + // Garage Door is closed. + return false; on_state: - mqtt.publish: topic: some/topic/binary_sensor @@ -217,9 +216,8 @@ cover: lambda: |- if (id(some_binary_sensor).state) { return COVER_OPEN; - } else { - return COVER_CLOSED; } + return COVER_CLOSED; open_action: - logger.log: open_action close_action: @@ -321,9 +319,8 @@ lock: lambda: |- if (id(some_binary_sensor).state) { return LOCK_STATE_LOCKED; - } else { - return LOCK_STATE_UNLOCKED; } + return LOCK_STATE_UNLOCKED; lock_action: - logger.log: lock_action unlock_action: @@ -360,9 +357,8 @@ sensor: lambda: |- if (id(some_binary_sensor).state) { return 42.0; - } else { - return 0.0; } + return 0.0; update_interval: 60s on_value: - mqtt.publish: @@ -390,9 +386,8 @@ switch: lambda: |- if (id(some_binary_sensor).state) { return true; - } else { - return false; } + return false; turn_on_action: - logger.log: turn_on_action turn_off_action: @@ -436,9 +431,8 @@ valve: lambda: |- if (id(some_binary_sensor).state) { return VALVE_OPEN; - } else { - return VALVE_CLOSED; } + return VALVE_CLOSED; alarm_control_panel: - platform: template diff --git a/tests/components/noblex/common.yaml b/tests/components/noblex/common.yaml index f5e471a9a7..8053d84d4b 100644 --- a/tests/components/noblex/common.yaml +++ b/tests/components/noblex/common.yaml @@ -1,12 +1,3 @@ -remote_receiver: - id: rcvr - pin: 4 - dump: all - -remote_transmitter: - pin: 2 - carrier_duty_percent: 50% - sensor: - platform: template id: noblex_ac_sensor diff --git a/tests/components/noblex/test.esp32-c3-idf.yaml b/tests/components/noblex/test.esp32-c3-idf.yaml index dade44d145..fe77c44eed 100644 --- a/tests/components/noblex/test.esp32-c3-idf.yaml +++ b/tests/components/noblex/test.esp32-c3-idf.yaml @@ -1 +1,5 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml + remote_receiver: !include ../../test_build_components/common/remote_receiver/esp32-c3-idf.yaml + <<: !include common.yaml diff --git a/tests/components/noblex/test.esp32-idf.yaml b/tests/components/noblex/test.esp32-idf.yaml index dade44d145..b241dbd159 100644 --- a/tests/components/noblex/test.esp32-idf.yaml +++ b/tests/components/noblex/test.esp32-idf.yaml @@ -1 +1,5 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml + remote_receiver: !include ../../test_build_components/common/remote_receiver/esp32-idf.yaml + <<: !include common.yaml diff --git a/tests/components/noblex/test.esp8266-ard.yaml b/tests/components/noblex/test.esp8266-ard.yaml index dade44d145..aa8651e556 100644 --- a/tests/components/noblex/test.esp8266-ard.yaml +++ b/tests/components/noblex/test.esp8266-ard.yaml @@ -1 +1,5 @@ +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml + remote_receiver: !include ../../test_build_components/common/remote_receiver/esp8266-ard.yaml + <<: !include common.yaml diff --git a/tests/components/pid/common.yaml b/tests/components/pid/common.yaml index 5f7762872f..262e75591e 100644 --- a/tests/components/pid/common.yaml +++ b/tests/components/pid/common.yaml @@ -27,9 +27,8 @@ sensor: lambda: |- if (millis() > 10000) { return 42.0; - } else { - return 0.0; } + return 0.0; update_interval: 60s climate: diff --git a/tests/components/prometheus/common.yaml b/tests/components/prometheus/common.yaml index 9a16088ba0..cf46e882a7 100644 --- a/tests/components/prometheus/common.yaml +++ b/tests/components/prometheus/common.yaml @@ -35,9 +35,8 @@ sensor: lambda: |- if (millis() > 10000) { return 42.0; - } else { - return 0.0; } + return 0.0; update_interval: 60s text_sensor: @@ -49,9 +48,8 @@ text_sensor: lambda: |- if (millis() > 10000) { return {"Hello World"}; - } else { - return {"Goodbye (cruel) World"}; } + return {"Goodbye (cruel) World"}; update_interval: 60s binary_sensor: @@ -60,9 +58,8 @@ binary_sensor: lambda: |- if (millis() > 10000) { return true; - } else { - return false; } + return false; switch: - platform: template @@ -70,9 +67,8 @@ switch: lambda: |- if (millis() > 10000) { return true; - } else { - return false; } + return false; optimistic: true fan: @@ -85,9 +81,8 @@ cover: lambda: |- if (millis() > 10000) { return COVER_OPEN; - } else { - return COVER_CLOSED; } + return COVER_CLOSED; lock: - platform: template @@ -95,9 +90,8 @@ lock: lambda: |- if (millis() > 10000) { return LOCK_STATE_LOCKED; - } else { - return LOCK_STATE_UNLOCKED; } + return LOCK_STATE_UNLOCKED; optimistic: true select: @@ -128,13 +122,10 @@ valve: optimistic: true has_position: true -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: climate_ir_lg name: LG Climate + transmitter_id: xmitr prometheus: include_internal: true diff --git a/tests/components/prometheus/test.esp32-c3-idf.yaml b/tests/components/prometheus/test.esp32-c3-idf.yaml index f00bca5947..fedeaf822a 100644 --- a/tests/components/prometheus/test.esp32-c3-idf.yaml +++ b/tests/components/prometheus/test.esp32-c3-idf.yaml @@ -1,5 +1,7 @@ substitutions: verify_ssl: "false" - pin: GPIO2 + +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/prometheus/test.esp32-idf.yaml b/tests/components/prometheus/test.esp32-idf.yaml index d60caadb05..e590417623 100644 --- a/tests/components/prometheus/test.esp32-idf.yaml +++ b/tests/components/prometheus/test.esp32-idf.yaml @@ -1,8 +1,8 @@ substitutions: verify_ssl: "false" - pin: GPIO2 packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml spi: !include ../../test_build_components/common/spi/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/prometheus/test.esp8266-ard.yaml b/tests/components/prometheus/test.esp8266-ard.yaml index 6ee1831769..bae76751e8 100644 --- a/tests/components/prometheus/test.esp8266-ard.yaml +++ b/tests/components/prometheus/test.esp8266-ard.yaml @@ -1,5 +1,7 @@ substitutions: verify_ssl: "false" - pin: GPIO5 + +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/remote_receiver/common-actions.yaml b/tests/components/remote_receiver/common-actions.yaml index ca7713f58a..c2dc2f0c29 100644 --- a/tests/components/remote_receiver/common-actions.yaml +++ b/tests/components/remote_receiver/common-actions.yaml @@ -143,6 +143,11 @@ on_sony: - logger.log: format: "on_sony: %lu %u" args: ["long(x.data)", "x.nbits"] +on_symphony: + then: + - logger.log: + format: "on_symphony: 0x%lX %u" + args: ["long(x.data)", "x.nbits"] on_toshiba_ac: then: - logger.log: diff --git a/tests/components/remote_transmitter/common-buttons.yaml b/tests/components/remote_transmitter/common-buttons.yaml index 3be4bf3cca..58127d1ab4 100644 --- a/tests/components/remote_transmitter/common-buttons.yaml +++ b/tests/components/remote_transmitter/common-buttons.yaml @@ -53,6 +53,12 @@ button: remote_transmitter.transmit_sony: data: 0xABCDEF nbits: 12 + - platform: template + name: Symphony + on_press: + remote_transmitter.transmit_symphony: + data: 0xE88 + nbits: 12 - platform: template name: Panasonic on_press: diff --git a/tests/components/tcl112/common.yaml b/tests/components/tcl112/common.yaml index 0e43de4a4a..1074712f94 100644 --- a/tests/components/tcl112/common.yaml +++ b/tests/components/tcl112/common.yaml @@ -1,7 +1,3 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - sensor: - platform: template id: tcl112_sensor @@ -13,3 +9,4 @@ climate: supports_heat: true supports_cool: true sensor: tcl112_sensor + transmitter_id: xmitr diff --git a/tests/components/tcl112/test.esp32-c3-idf.yaml b/tests/components/tcl112/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/tcl112/test.esp32-c3-idf.yaml +++ b/tests/components/tcl112/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/tcl112/test.esp32-idf.yaml b/tests/components/tcl112/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/tcl112/test.esp32-idf.yaml +++ b/tests/components/tcl112/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/tcl112/test.esp8266-ard.yaml b/tests/components/tcl112/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/tcl112/test.esp8266-ard.yaml +++ b/tests/components/tcl112/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/template/common-base.yaml b/tests/components/template/common-base.yaml index 48537d21bc..ea812532d4 100644 --- a/tests/components/template/common-base.yaml +++ b/tests/components/template/common-base.yaml @@ -59,9 +59,8 @@ binary_sensor: - lambda: |- if (id(other_binary_sensor).state) { return x; - } else { - return {}; } + return {}; - settle: 500ms - timeout: 5s @@ -72,9 +71,8 @@ sensor: lambda: |- if (id(some_binary_sensor).state) { return 42.0; - } else { - return 0.0; } + return 0.0; update_interval: 60s filters: - calibrate_linear: @@ -183,9 +181,8 @@ switch: lambda: |- if (id(some_binary_sensor).state) { return true; - } else { - return false; } + return false; turn_on_action: - logger.log: "turn_on_action" turn_off_action: @@ -203,9 +200,8 @@ cover: lambda: |- if (id(some_binary_sensor).state) { return COVER_OPEN; - } else { - return COVER_CLOSED; } + return COVER_CLOSED; open_action: - logger.log: open_action close_action: @@ -238,9 +234,8 @@ lock: lambda: |- if (id(some_binary_sensor).state) { return LOCK_STATE_LOCKED; - } else { - return LOCK_STATE_UNLOCKED; } + return LOCK_STATE_UNLOCKED; lock_action: - logger.log: lock_action unlock_action: @@ -255,9 +250,8 @@ valve: lambda: |- if (id(some_binary_sensor).state) { return VALVE_OPEN; - } else { - return VALVE_CLOSED; } + return VALVE_CLOSED; open_action: - logger.log: open_action close_action: diff --git a/tests/components/thermostat/common.yaml b/tests/components/thermostat/common.yaml index d630a93efc..4aa87c0ac3 100644 --- a/tests/components/thermostat/common.yaml +++ b/tests/components/thermostat/common.yaml @@ -69,6 +69,11 @@ climate: - logger.log: swing_vertical_action swing_both_action: - logger.log: swing_both_action + humidity_control_humidify_action: + - logger.log: humidity_control_humidify_action + humidity_control_off_action: + - logger.log: humidity_control_off_action + humidity_hysteresis: 1.0 startup_delay: true supplemental_cooling_delta: 2.0 cool_deadband: 0.5 diff --git a/tests/components/toshiba/common.yaml b/tests/components/toshiba/common.yaml index 79a833980e..ba96c0628d 100644 --- a/tests/components/toshiba/common.yaml +++ b/tests/components/toshiba/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: toshiba name: Toshiba Climate + transmitter_id: xmitr diff --git a/tests/components/toshiba/test.esp32-c3-idf.yaml b/tests/components/toshiba/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/toshiba/test.esp32-c3-idf.yaml +++ b/tests/components/toshiba/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/toshiba/test.esp32-idf.yaml b/tests/components/toshiba/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/toshiba/test.esp32-idf.yaml +++ b/tests/components/toshiba/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/toshiba/test.esp8266-ard.yaml b/tests/components/toshiba/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/toshiba/test.esp8266-ard.yaml +++ b/tests/components/toshiba/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/total_daily_energy/common.yaml b/tests/components/total_daily_energy/common.yaml index ae4d30408b..dd7e648da6 100644 --- a/tests/components/total_daily_energy/common.yaml +++ b/tests/components/total_daily_energy/common.yaml @@ -17,10 +17,10 @@ sensor: name: HLW8012 Voltage power: name: HLW8012 Power - id: hlw8012_power + id: total_daily_energy_hlw8012_power energy: name: HLW8012 Energy - id: hlw8012_energy + id: total_daily_energy_hlw8012_energy update_interval: 15s current_resistor: 0.001 ohm voltage_divider: 2351 @@ -29,4 +29,4 @@ sensor: model: hlw8012 - platform: total_daily_energy name: HLW8012 Total Daily Energy - power_id: hlw8012_power + power_id: total_daily_energy_hlw8012_power diff --git a/tests/components/whirlpool/common.yaml b/tests/components/whirlpool/common.yaml index 804c1aac26..6d55db1f08 100644 --- a/tests/components/whirlpool/common.yaml +++ b/tests/components/whirlpool/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: whirlpool name: Whirlpool Climate + transmitter_id: xmitr diff --git a/tests/components/whirlpool/test.esp32-c3-idf.yaml b/tests/components/whirlpool/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/whirlpool/test.esp32-c3-idf.yaml +++ b/tests/components/whirlpool/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/whirlpool/test.esp32-idf.yaml b/tests/components/whirlpool/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/whirlpool/test.esp32-idf.yaml +++ b/tests/components/whirlpool/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/whirlpool/test.esp8266-ard.yaml b/tests/components/whirlpool/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/whirlpool/test.esp8266-ard.yaml +++ b/tests/components/whirlpool/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/whynter/common.yaml b/tests/components/whynter/common.yaml index 04ad6bed54..63df11dd91 100644 --- a/tests/components/whynter/common.yaml +++ b/tests/components/whynter/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: whynter name: Whynter Climate + transmitter_id: xmitr diff --git a/tests/components/whynter/test.esp32-c3-idf.yaml b/tests/components/whynter/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/whynter/test.esp32-c3-idf.yaml +++ b/tests/components/whynter/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/whynter/test.esp32-idf.yaml b/tests/components/whynter/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/whynter/test.esp32-idf.yaml +++ b/tests/components/whynter/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/whynter/test.esp8266-ard.yaml b/tests/components/whynter/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/whynter/test.esp8266-ard.yaml +++ b/tests/components/whynter/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/xgzp68xx/common.yaml b/tests/components/xgzp68xx/common.yaml index f76b1de508..00e51e764c 100644 --- a/tests/components/xgzp68xx/common.yaml +++ b/tests/components/xgzp68xx/common.yaml @@ -6,3 +6,4 @@ sensor: name: Pressure Temperature pressure: name: Differential pressure + oversampling: 1024x diff --git a/tests/components/yashima/common.yaml b/tests/components/yashima/common.yaml index bfe181f1a6..431c27ebb3 100644 --- a/tests/components/yashima/common.yaml +++ b/tests/components/yashima/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: yashima name: Yashima Climate + transmitter_id: xmitr diff --git a/tests/components/yashima/test.esp32-c3-idf.yaml b/tests/components/yashima/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/yashima/test.esp32-c3-idf.yaml +++ b/tests/components/yashima/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/yashima/test.esp32-idf.yaml b/tests/components/yashima/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/yashima/test.esp32-idf.yaml +++ b/tests/components/yashima/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/yashima/test.esp8266-ard.yaml b/tests/components/yashima/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/yashima/test.esp8266-ard.yaml +++ b/tests/components/yashima/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/components/zhlt01/common.yaml b/tests/components/zhlt01/common.yaml index 0adbe77325..d0fd531c87 100644 --- a/tests/components/zhlt01/common.yaml +++ b/tests/components/zhlt01/common.yaml @@ -1,7 +1,4 @@ -remote_transmitter: - pin: ${pin} - carrier_duty_percent: 50% - climate: - platform: zhlt01 name: ZH/LT-01 Climate + transmitter_id: xmitr diff --git a/tests/components/zhlt01/test.esp32-c3-idf.yaml b/tests/components/zhlt01/test.esp32-c3-idf.yaml index 7b012aa64c..43d5343715 100644 --- a/tests/components/zhlt01/test.esp32-c3-idf.yaml +++ b/tests/components/zhlt01/test.esp32-c3-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-c3-idf.yaml <<: !include common.yaml diff --git a/tests/components/zhlt01/test.esp32-idf.yaml b/tests/components/zhlt01/test.esp32-idf.yaml index 7b012aa64c..e891f9dc85 100644 --- a/tests/components/zhlt01/test.esp32-idf.yaml +++ b/tests/components/zhlt01/test.esp32-idf.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO2 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp32-idf.yaml <<: !include common.yaml diff --git a/tests/components/zhlt01/test.esp8266-ard.yaml b/tests/components/zhlt01/test.esp8266-ard.yaml index f5097fcf5f..4bed2f03e5 100644 --- a/tests/components/zhlt01/test.esp8266-ard.yaml +++ b/tests/components/zhlt01/test.esp8266-ard.yaml @@ -1,4 +1,4 @@ -substitutions: - pin: GPIO5 +packages: + remote_transmitter: !include ../../test_build_components/common/remote_transmitter/esp8266-ard.yaml <<: !include common.yaml diff --git a/tests/dashboard/test_web_server.py b/tests/dashboard/test_web_server.py index 6c424e56d4..385841b1c8 100644 --- a/tests/dashboard/test_web_server.py +++ b/tests/dashboard/test_web_server.py @@ -35,6 +35,26 @@ from esphome.zeroconf import DiscoveredImport from .common import get_fixture_path +def get_build_path(base_path: Path, device_name: str) -> Path: + """Get the build directory path for a device. + + This is a test helper that constructs the standard ESPHome build directory + structure. Note: This helper does NOT perform path traversal sanitization + because it's only used in tests where we control the inputs. The actual + web_server.py code handles sanitization in DownloadBinaryRequestHandler.get() + via file_name.replace("..", "").lstrip("/"). + + Args: + base_path: The base temporary path (typically tmp_path from pytest) + device_name: The name of the device (should not contain path separators + in production use, but tests may use it for specific scenarios) + + Returns: + Path to the build directory (.esphome/build/device_name) + """ + return base_path / ".esphome" / "build" / device_name + + class DashboardTestHelper: def __init__(self, io_loop: IOLoop, client: AsyncHTTPClient, port: int) -> None: self.io_loop = io_loop @@ -417,6 +437,180 @@ async def test_download_binary_handler_idedata_fallback( assert response.body == b"bootloader content" +@pytest.mark.asyncio +@pytest.mark.usefixtures("mock_ext_storage_path") +async def test_download_binary_handler_subdirectory_file( + dashboard: DashboardTestHelper, + tmp_path: Path, + mock_storage_json: MagicMock, +) -> None: + """Test the DownloadBinaryRequestHandler.get with file in subdirectory (nRF52 case). + + This is a regression test for issue #11343 where the Path migration broke + downloads for nRF52 firmware files in subdirectories like 'zephyr/zephyr.uf2'. + + The issue was that with_name() doesn't accept path separators: + - Before: path = storage_json.firmware_bin_path.with_name(file_name) + ValueError: Invalid name 'zephyr/zephyr.uf2' + - After: path = storage_json.firmware_bin_path.parent.joinpath(file_name) + Works correctly with subdirectory paths + """ + # Create a fake nRF52 build structure with firmware in subdirectory + build_dir = get_build_path(tmp_path, "nrf52-device") + zephyr_dir = build_dir / "zephyr" + zephyr_dir.mkdir(parents=True) + + # Create the main firmware binary (would be in build root) + firmware_file = build_dir / "firmware.bin" + firmware_file.write_bytes(b"main firmware") + + # Create the UF2 file in zephyr subdirectory (nRF52 specific) + uf2_file = zephyr_dir / "zephyr.uf2" + uf2_file.write_bytes(b"nRF52 UF2 firmware content") + + # Mock storage JSON + mock_storage = Mock() + mock_storage.name = "nrf52-device" + mock_storage.firmware_bin_path = firmware_file + mock_storage_json.load.return_value = mock_storage + + # Request the UF2 file with subdirectory path + response = await dashboard.fetch( + "/download.bin?configuration=nrf52-device.yaml&file=zephyr/zephyr.uf2", + method="GET", + ) + assert response.code == 200 + assert response.body == b"nRF52 UF2 firmware content" + assert response.headers["Content-Type"] == "application/octet-stream" + assert "attachment" in response.headers["Content-Disposition"] + # Download name should be device-name + full file path + assert "nrf52-device-zephyr/zephyr.uf2" in response.headers["Content-Disposition"] + + +@pytest.mark.asyncio +@pytest.mark.usefixtures("mock_ext_storage_path") +async def test_download_binary_handler_subdirectory_file_url_encoded( + dashboard: DashboardTestHelper, + tmp_path: Path, + mock_storage_json: MagicMock, +) -> None: + """Test the DownloadBinaryRequestHandler.get with URL-encoded subdirectory path. + + Verifies that URL-encoded paths (e.g., zephyr%2Fzephyr.uf2) are correctly + decoded and handled, and that custom download names work with subdirectories. + """ + # Create a fake build structure with firmware in subdirectory + build_dir = get_build_path(tmp_path, "test") + zephyr_dir = build_dir / "zephyr" + zephyr_dir.mkdir(parents=True) + + firmware_file = build_dir / "firmware.bin" + firmware_file.write_bytes(b"content") + + uf2_file = zephyr_dir / "zephyr.uf2" + uf2_file.write_bytes(b"content") + + # Mock storage JSON + mock_storage = Mock() + mock_storage.name = "test_device" + mock_storage.firmware_bin_path = firmware_file + mock_storage_json.load.return_value = mock_storage + + # Request with URL-encoded path and custom download name + response = await dashboard.fetch( + "/download.bin?configuration=test.yaml&file=zephyr%2Fzephyr.uf2&download=custom_name.bin", + method="GET", + ) + assert response.code == 200 + assert "custom_name.bin" in response.headers["Content-Disposition"] + + +@pytest.mark.asyncio +@pytest.mark.usefixtures("mock_ext_storage_path") +@pytest.mark.parametrize( + "attack_path", + [ + pytest.param("../../../secrets.yaml", id="basic_traversal"), + pytest.param("..%2F..%2F..%2Fsecrets.yaml", id="url_encoded"), + pytest.param("zephyr/../../../secrets.yaml", id="traversal_with_prefix"), + pytest.param("/etc/passwd", id="absolute_path"), + pytest.param("//etc/passwd", id="double_slash_absolute"), + pytest.param("....//secrets.yaml", id="multiple_dots"), + ], +) +async def test_download_binary_handler_path_traversal_protection( + dashboard: DashboardTestHelper, + tmp_path: Path, + mock_storage_json: MagicMock, + attack_path: str, +) -> None: + """Test that DownloadBinaryRequestHandler prevents path traversal attacks. + + Verifies that attempts to use '..' in file paths are sanitized to prevent + accessing files outside the build directory. Tests multiple attack vectors. + """ + # Create build structure + build_dir = get_build_path(tmp_path, "test") + build_dir.mkdir(parents=True) + firmware_file = build_dir / "firmware.bin" + firmware_file.write_bytes(b"firmware content") + + # Create a sensitive file outside the build directory that should NOT be accessible + sensitive_file = tmp_path / "secrets.yaml" + sensitive_file.write_bytes(b"secret: my_secret_password") + + # Mock storage JSON + mock_storage = Mock() + mock_storage.name = "test_device" + mock_storage.firmware_bin_path = firmware_file + mock_storage_json.load.return_value = mock_storage + + # Attempt path traversal attack - should be blocked + with pytest.raises(HTTPClientError) as exc_info: + await dashboard.fetch( + f"/download.bin?configuration=test.yaml&file={attack_path}", + method="GET", + ) + # Should get 404 (file not found after sanitization) or 500 (idedata fails) + assert exc_info.value.code in (404, 500) + + +@pytest.mark.asyncio +@pytest.mark.usefixtures("mock_ext_storage_path") +async def test_download_binary_handler_multiple_subdirectory_levels( + dashboard: DashboardTestHelper, + tmp_path: Path, + mock_storage_json: MagicMock, +) -> None: + """Test downloading files from multiple subdirectory levels. + + Verifies that joinpath correctly handles multi-level paths like 'build/output/firmware.bin'. + """ + # Create nested directory structure + build_dir = get_build_path(tmp_path, "test") + nested_dir = build_dir / "build" / "output" + nested_dir.mkdir(parents=True) + + firmware_file = build_dir / "firmware.bin" + firmware_file.write_bytes(b"main") + + nested_file = nested_dir / "firmware.bin" + nested_file.write_bytes(b"nested firmware content") + + # Mock storage JSON + mock_storage = Mock() + mock_storage.name = "test_device" + mock_storage.firmware_bin_path = firmware_file + mock_storage_json.load.return_value = mock_storage + + response = await dashboard.fetch( + "/download.bin?configuration=test.yaml&file=build/output/firmware.bin", + method="GET", + ) + assert response.code == 200 + assert response.body == b"nested firmware content" + + @pytest.mark.asyncio async def test_edit_request_handler_post_invalid_file( dashboard: DashboardTestHelper, diff --git a/tests/integration/fixtures/batch_delay_zero_rapid_transitions.yaml b/tests/integration/fixtures/batch_delay_zero_rapid_transitions.yaml index 32cacfaa79..f7b0fdcb63 100644 --- a/tests/integration/fixtures/batch_delay_zero_rapid_transitions.yaml +++ b/tests/integration/fixtures/batch_delay_zero_rapid_transitions.yaml @@ -34,10 +34,9 @@ binary_sensor: ESP_LOGD("test", "Button ON at %u", now); } return true; - } else { - // Only log state change - if (id(ir_remote_button).state) { - ESP_LOGD("test", "Button OFF at %u", now); - } - return false; } + // Only log state change + if (id(ir_remote_button).state) { + ESP_LOGD("test", "Button OFF at %u", now); + } + return false; diff --git a/tests/test_build_components/common/remote_receiver/esp32-c3-idf.yaml b/tests/test_build_components/common/remote_receiver/esp32-c3-idf.yaml new file mode 100644 index 0000000000..ad5acedf55 --- /dev/null +++ b/tests/test_build_components/common/remote_receiver/esp32-c3-idf.yaml @@ -0,0 +1,16 @@ +# Common remote_receiver configuration for ESP32-C3 IDF tests +# Provides a shared remote receiver that all components can use +# Components will auto-use this receiver if they don't specify receiver_id + +substitutions: + remote_receiver_pin: GPIO5 + +remote_receiver: + - id: rcvr + pin: ${remote_receiver_pin} + dump: all + tolerance: 25% + clock_resolution: 2000000 + filter_symbols: 2 + receive_symbols: 4 + rmt_symbols: 64 diff --git a/tests/test_build_components/common/remote_receiver/esp32-idf.yaml b/tests/test_build_components/common/remote_receiver/esp32-idf.yaml new file mode 100644 index 0000000000..2905e22233 --- /dev/null +++ b/tests/test_build_components/common/remote_receiver/esp32-idf.yaml @@ -0,0 +1,16 @@ +# Common remote_receiver configuration for ESP32 IDF tests +# Provides a shared remote receiver that all components can use +# Components will auto-use this receiver if they don't specify receiver_id + +substitutions: + remote_receiver_pin: GPIO32 + +remote_receiver: + - id: rcvr + pin: ${remote_receiver_pin} + dump: all + tolerance: 25% + clock_resolution: 2000000 + filter_symbols: 2 + receive_symbols: 4 + rmt_symbols: 64 diff --git a/tests/test_build_components/common/remote_receiver/esp8266-ard.yaml b/tests/test_build_components/common/remote_receiver/esp8266-ard.yaml new file mode 100644 index 0000000000..e2472d00c5 --- /dev/null +++ b/tests/test_build_components/common/remote_receiver/esp8266-ard.yaml @@ -0,0 +1,12 @@ +# Common remote_receiver configuration for ESP8266 Arduino tests +# Provides a shared remote receiver that all components can use +# Components will auto-use this receiver if they don't specify receiver_id + +substitutions: + remote_receiver_pin: GPIO5 + +remote_receiver: + id: rcvr + pin: ${remote_receiver_pin} + dump: all + tolerance: 25% diff --git a/tests/test_build_components/common/remote_transmitter/bk72xx-ard.yaml b/tests/test_build_components/common/remote_transmitter/bk72xx-ard.yaml new file mode 100644 index 0000000000..b951b8713f --- /dev/null +++ b/tests/test_build_components/common/remote_transmitter/bk72xx-ard.yaml @@ -0,0 +1,11 @@ +# Common remote_transmitter configuration for BK72XX Arduino tests +# Provides a shared remote transmitter that all components can use +# Components will auto-use this transmitter if they don't specify transmitter_id + +substitutions: + remote_transmitter_pin: GPIO6 + +remote_transmitter: + id: xmitr + pin: ${remote_transmitter_pin} + carrier_duty_percent: 50% diff --git a/tests/test_build_components/common/remote_transmitter/esp32-ard.yaml b/tests/test_build_components/common/remote_transmitter/esp32-ard.yaml new file mode 100644 index 0000000000..4378e328af --- /dev/null +++ b/tests/test_build_components/common/remote_transmitter/esp32-ard.yaml @@ -0,0 +1,11 @@ +# Common remote_transmitter configuration for ESP32 Arduino tests +# Provides a shared remote transmitter that all components can use +# Components will auto-use this transmitter if they don't specify transmitter_id + +substitutions: + remote_transmitter_pin: GPIO2 + +remote_transmitter: + id: xmitr + pin: ${remote_transmitter_pin} + carrier_duty_percent: 50% diff --git a/tests/test_build_components/common/remote_transmitter/esp32-c3-idf.yaml b/tests/test_build_components/common/remote_transmitter/esp32-c3-idf.yaml new file mode 100644 index 0000000000..b6b9a87fe1 --- /dev/null +++ b/tests/test_build_components/common/remote_transmitter/esp32-c3-idf.yaml @@ -0,0 +1,13 @@ +# Common remote_transmitter configuration for ESP32-C3 IDF tests +# Provides a shared remote transmitter that all components can use +# Components will auto-use this transmitter if they don't specify transmitter_id + +substitutions: + remote_transmitter_pin: GPIO2 + +remote_transmitter: + - id: xmitr + pin: ${remote_transmitter_pin} + carrier_duty_percent: 50% + clock_resolution: 2000000 + rmt_symbols: 64 diff --git a/tests/test_build_components/common/remote_transmitter/esp32-idf.yaml b/tests/test_build_components/common/remote_transmitter/esp32-idf.yaml new file mode 100644 index 0000000000..1d771b3edd --- /dev/null +++ b/tests/test_build_components/common/remote_transmitter/esp32-idf.yaml @@ -0,0 +1,13 @@ +# Common remote_transmitter configuration for ESP32 IDF tests +# Provides a shared remote transmitter that all components can use +# Components will auto-use this transmitter if they don't specify transmitter_id + +substitutions: + remote_transmitter_pin: GPIO2 + +remote_transmitter: + - id: xmitr + pin: ${remote_transmitter_pin} + carrier_duty_percent: 50% + clock_resolution: 2000000 + rmt_symbols: 64 diff --git a/tests/test_build_components/common/remote_transmitter/esp8266-ard.yaml b/tests/test_build_components/common/remote_transmitter/esp8266-ard.yaml new file mode 100644 index 0000000000..3be59c7997 --- /dev/null +++ b/tests/test_build_components/common/remote_transmitter/esp8266-ard.yaml @@ -0,0 +1,11 @@ +# Common remote_transmitter configuration for ESP8266 Arduino tests +# Provides a shared remote transmitter that all components can use +# Components will auto-use this transmitter if they don't specify transmitter_id + +substitutions: + remote_transmitter_pin: GPIO2 + +remote_transmitter: + id: xmitr + pin: ${remote_transmitter_pin} + carrier_duty_percent: 50%