From 84c00a58675a63f7ef587119494d49fb81dbe671 Mon Sep 17 00:00:00 2001 From: Samuel Sieb Date: Mon, 23 Oct 2023 11:26:23 -0700 Subject: [PATCH 01/15] fix canbus send config (#5585) Co-authored-by: Samuel Sieb --- esphome/components/canbus/__init__.py | 25 +++++++++++-------------- tests/test1.1.yaml | 16 ++++++++++++++++ tests/test1.yaml | 4 ++++ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/esphome/components/canbus/__init__.py b/esphome/components/canbus/__init__.py index f49398858c..76e77021ad 100644 --- a/esphome/components/canbus/__init__.py +++ b/esphome/components/canbus/__init__.py @@ -17,11 +17,12 @@ CONF_ON_FRAME = "on_frame" def validate_id(config): - can_id = config[CONF_CAN_ID] - id_ext = config[CONF_USE_EXTENDED_ID] - if not id_ext: - if can_id > 0x7FF: - raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)") + if CONF_CAN_ID in config: + can_id = config[CONF_CAN_ID] + id_ext = config[CONF_USE_EXTENDED_ID] + if not id_ext: + if can_id > 0x7FF: + raise cv.Invalid("Standard IDs must be 11 Bit (0x000-0x7ff / 0-2047)") return config @@ -151,22 +152,18 @@ async def canbus_action_to_code(config, action_id, template_arg, args): if can_id := config.get(CONF_CAN_ID): can_id = await cg.templatable(can_id, args, cg.uint32) cg.add(var.set_can_id(can_id)) - use_extended_id = await cg.templatable( - config[CONF_USE_EXTENDED_ID], args, cg.uint32 - ) - cg.add(var.set_use_extended_id(use_extended_id)) + cg.add(var.set_use_extended_id(config[CONF_USE_EXTENDED_ID])) - remote_transmission_request = await cg.templatable( - config[CONF_REMOTE_TRANSMISSION_REQUEST], args, bool + cg.add( + var.set_remote_transmission_request(config[CONF_REMOTE_TRANSMISSION_REQUEST]) ) - cg.add(var.set_remote_transmission_request(remote_transmission_request)) data = config[CONF_DATA] - if isinstance(data, bytes): - data = [int(x) for x in data] if cg.is_template(data): templ = await cg.templatable(data, args, cg.std_vector.template(cg.uint8)) cg.add(var.set_data_template(templ)) else: + if isinstance(data, bytes): + data = [int(x) for x in data] cg.add(var.set_data_static(data)) return var diff --git a/tests/test1.1.yaml b/tests/test1.1.yaml index 3bad4e0492..f4ad89897b 100644 --- a/tests/test1.1.yaml +++ b/tests/test1.1.yaml @@ -203,3 +203,19 @@ light: from: 20 to: 25 - single_light_id: ${roomname}_lights + +canbus: + - platform: esp32_can + id: esp32_internal_can + rx_pin: GPIO04 + tx_pin: GPIO05 + can_id: 4 + bit_rate: 50kbps + +button: + - platform: template + name: Canbus Actions + on_press: + - canbus.send: "abc" + - canbus.send: [0, 1, 2] + - canbus.send: !lambda return {0, 1, 2}; diff --git a/tests/test1.yaml b/tests/test1.yaml index acd119d8a5..f40dc35934 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -3214,6 +3214,10 @@ text_sensor: canbus_id: mcp2515_can can_id: 23 data: [0x10, 0x20, 0x30] + - canbus.send: + canbus_id: mcp2515_can + can_id: 23 + data: !lambda return {0x10, 0x20, 0x30}; - canbus.send: canbus_id: esp32_internal_can can_id: 23 From b898f75631d9d2ec4cc2fa7a46c5ebc6a9601b69 Mon Sep 17 00:00:00 2001 From: dentra Date: Mon, 23 Oct 2023 21:29:32 +0300 Subject: [PATCH 02/15] Allow set climate preset to NONE (#5588) --- esphome/components/climate/climate.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esphome/components/climate/climate.cpp b/esphome/components/climate/climate.cpp index 1680601279..ea24cab954 100644 --- a/esphome/components/climate/climate.cpp +++ b/esphome/components/climate/climate.cpp @@ -213,6 +213,8 @@ ClimateCall &ClimateCall::set_preset(const std::string &preset) { this->set_preset(CLIMATE_PRESET_SLEEP); } else if (str_equals_case_insensitive(preset, "ACTIVITY")) { this->set_preset(CLIMATE_PRESET_ACTIVITY); + } else if (str_equals_case_insensitive(preset, "NONE")) { + this->set_preset(CLIMATE_PRESET_NONE); } else { if (this->parent_->get_traits().supports_custom_preset(preset)) { this->custom_preset_ = preset; From eead33b6f2df61d77258aaac4a168b9a652081ee Mon Sep 17 00:00:00 2001 From: Guillermo Ruffino Date: Mon, 23 Oct 2023 16:02:29 -0300 Subject: [PATCH 03/15] update storage version from mdns (#5584) --- esphome/zeroconf.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/esphome/zeroconf.py b/esphome/zeroconf.py index 924d7253df..14dd740a96 100644 --- a/esphome/zeroconf.py +++ b/esphome/zeroconf.py @@ -17,6 +17,8 @@ from zeroconf import ( current_time_millis, ) +from esphome.storage_json import StorageJSON, ext_storage_path + _CLASS_IN = 1 _FLAGS_QR_QUERY = 0x0000 # query _TYPE_A = 1 @@ -131,6 +133,7 @@ TXT_RECORD_PROJECT_NAME = b"project_name" TXT_RECORD_PROJECT_VERSION = b"project_version" TXT_RECORD_NETWORK = b"network" TXT_RECORD_FRIENDLY_NAME = b"friendly_name" +TXT_RECORD_VERSION = b"version" @dataclass @@ -186,6 +189,10 @@ class DashboardImportDiscovery: ] if any(key not in info.properties for key in required_keys): # Not a dashboard import device + version = info.properties.get(TXT_RECORD_VERSION) + if version is not None: + version = version.decode() + self.update_device_mdns(node_name, version) return import_url = info.properties[TXT_RECORD_PACKAGE_IMPORT_URL].decode() @@ -208,6 +215,22 @@ class DashboardImportDiscovery: def cancel(self) -> None: self.service_browser.cancel() + def update_device_mdns(self, node_name: str, version: str): + storage_path = ext_storage_path(node_name + ".yaml") + storage_json = StorageJSON.load(storage_path) + + if storage_json is not None: + storage_version = storage_json.esphome_version + if version != storage_version: + storage_json.esphome_version = version + storage_json.save(storage_path) + _LOGGER.info( + "Updated %s with mdns version %s (was %s)", + node_name, + version, + storage_version, + ) + class EsphomeZeroconf(Zeroconf): def resolve_host(self, host: str, timeout=3.0): From 7e27e98bff376a237b8911e87d0d44d5cd6648be Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:02:57 +0200 Subject: [PATCH 04/15] set Nextion protocol reparse mode (#5484) --- esphome/components/nextion/nextion.h | 7 +++++++ .../components/nextion/nextion_commands.cpp | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/esphome/components/nextion/nextion.h b/esphome/components/nextion/nextion.h index 28663138d7..7518d7f4cb 100644 --- a/esphome/components/nextion/nextion.h +++ b/esphome/components/nextion/nextion.h @@ -623,6 +623,13 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe * @param True or false. Sleep=true to enter sleep mode or sleep=false to exit sleep mode. */ void sleep(bool sleep); + /** + * Sets Nextion Protocol Reparse mode between active or passive + * @param True or false. + * active_mode=true to enter active protocol reparse mode + * active_mode=false to enter passive protocol reparse mode. + */ + void set_protocol_reparse_mode(bool active_mode); // ========== INTERNAL METHODS ========== // (In most use cases you won't need these) diff --git a/esphome/components/nextion/nextion_commands.cpp b/esphome/components/nextion/nextion_commands.cpp index 806e03850f..c4caf29287 100644 --- a/esphome/components/nextion/nextion_commands.cpp +++ b/esphome/components/nextion/nextion_commands.cpp @@ -32,6 +32,25 @@ void Nextion::sleep(bool sleep) { } // End sleep safe commands +// Protocol reparse mode +void Nextion::set_protocol_reparse_mode(bool active_mode) { + const uint8_t to_send[3] = {0xFF, 0xFF, 0xFF}; + if (active_mode) { // Sets active protocol reparse mode + this->write_str( + "recmod=1"); // send_command_ cannot be used as Nextion might not be setup if incorrect reparse mode + this->write_array(to_send, sizeof(to_send)); + } else { // Sets passive protocol reparse mode + this->write_str("DRAKJHSUYDGBNCJHGJKSHBDN"); // To exit active reparse mode this sequence must be sent + this->write_array(to_send, sizeof(to_send)); + this->write_str("recmod=0"); // Sending recmode=0 twice is recommended + this->write_array(to_send, sizeof(to_send)); + this->write_str("recmod=0"); + this->write_array(to_send, sizeof(to_send)); + } + this->write_str("connect"); + this->write_array(to_send, sizeof(to_send)); +} + // Set Colors void Nextion::set_component_background_color(const char *component, uint32_t color) { this->add_no_result_to_queue_with_printf_("set_component_background_color", "%s.bco=%d", component, color); From e7d51f9c16a08d1d814e4f5fe52c9ba93dc53521 Mon Sep 17 00:00:00 2001 From: Simone Rossetto Date: Mon, 23 Oct 2023 21:05:57 +0200 Subject: [PATCH 05/15] Add address text sensor to WireGuard (#5576) --- esphome/components/wireguard/text_sensor.py | 28 +++++++++++++++++++++ esphome/components/wireguard/wireguard.cpp | 10 ++++++++ esphome/components/wireguard/wireguard.h | 12 +++++++++ tests/test10.yaml | 5 ++++ 4 files changed, 55 insertions(+) create mode 100644 esphome/components/wireguard/text_sensor.py diff --git a/esphome/components/wireguard/text_sensor.py b/esphome/components/wireguard/text_sensor.py new file mode 100644 index 0000000000..3b05f6173e --- /dev/null +++ b/esphome/components/wireguard/text_sensor.py @@ -0,0 +1,28 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import text_sensor +from esphome.const import ( + CONF_ADDRESS, + ENTITY_CATEGORY_DIAGNOSTIC, +) + +from . import Wireguard + +CONF_WIREGUARD_ID = "wireguard_id" + +DEPENDENCIES = ["wireguard"] + +CONFIG_SCHEMA = { + cv.GenerateID(CONF_WIREGUARD_ID): cv.use_id(Wireguard), + cv.Optional(CONF_ADDRESS): text_sensor.text_sensor_schema( + entity_category=ENTITY_CATEGORY_DIAGNOSTIC, + ), +} + + +async def to_code(config): + parent = await cg.get_variable(config[CONF_WIREGUARD_ID]) + + if address_config := config.get(CONF_ADDRESS): + sens = await text_sensor.new_text_sensor(address_config) + cg.add(parent.set_address_sensor(sens)) diff --git a/esphome/components/wireguard/wireguard.cpp b/esphome/components/wireguard/wireguard.cpp index 1b361cc1cc..3cd4409dda 100644 --- a/esphome/components/wireguard/wireguard.cpp +++ b/esphome/components/wireguard/wireguard.cpp @@ -54,6 +54,12 @@ void Wireguard::setup() { this->wg_peer_offline_time_ = millis(); this->srctime_->add_on_time_sync_callback(std::bind(&Wireguard::start_connection_, this)); this->defer(std::bind(&Wireguard::start_connection_, this)); // defer to avoid blocking setup + +#ifdef USE_TEXT_SENSOR + if (this->address_sensor_ != nullptr) { + this->address_sensor_->publish_state(this->address_); + } +#endif } else { ESP_LOGE(TAG, "cannot initialize WireGuard, error code %d", this->wg_initialized_); this->mark_failed(); @@ -186,6 +192,10 @@ void Wireguard::set_status_sensor(binary_sensor::BinarySensor *sensor) { this->s void Wireguard::set_handshake_sensor(sensor::Sensor *sensor) { this->handshake_sensor_ = sensor; } #endif +#ifdef USE_TEXT_SENSOR +void Wireguard::set_address_sensor(text_sensor::TextSensor *sensor) { this->address_sensor_ = sensor; } +#endif + void Wireguard::disable_auto_proceed() { this->proceed_allowed_ = false; } void Wireguard::start_connection_() { diff --git a/esphome/components/wireguard/wireguard.h b/esphome/components/wireguard/wireguard.h index cfc5fa1a27..c47d9e6603 100644 --- a/esphome/components/wireguard/wireguard.h +++ b/esphome/components/wireguard/wireguard.h @@ -17,6 +17,10 @@ #include "esphome/components/sensor/sensor.h" #endif +#ifdef USE_TEXT_SENSOR +#include "esphome/components/text_sensor/text_sensor.h" +#endif + #include namespace esphome { @@ -55,6 +59,10 @@ class Wireguard : public PollingComponent { void set_handshake_sensor(sensor::Sensor *sensor); #endif +#ifdef USE_TEXT_SENSOR + void set_address_sensor(text_sensor::TextSensor *sensor); +#endif + /// Block the setup step until peer is connected. void disable_auto_proceed(); @@ -85,6 +93,10 @@ class Wireguard : public PollingComponent { sensor::Sensor *handshake_sensor_ = nullptr; #endif +#ifdef USE_TEXT_SENSOR + text_sensor::TextSensor *address_sensor_ = nullptr; +#endif + /// Set to false to block the setup step until peer is connected. bool proceed_allowed_ = true; diff --git a/tests/test10.yaml b/tests/test10.yaml index fc74d95d84..dda7601048 100644 --- a/tests/test10.yaml +++ b/tests/test10.yaml @@ -49,3 +49,8 @@ sensor: - platform: wireguard latest_handshake: name: 'WireGuard Latest Handshake' + +text_sensor: + - platform: wireguard + address: + name: 'WireGuard Address' From 5347c9aafeb7c15f2f0a0dd664345563e5cdd902 Mon Sep 17 00:00:00 2001 From: Jimmy Hedman Date: Mon, 23 Oct 2023 21:06:23 +0200 Subject: [PATCH 06/15] Add LibreTiny hardwares to PR Template (#5575) --- .github/PULL_REQUEST_TEMPLATE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 3221b8ac5c..3bf9c4e1f6 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -19,6 +19,8 @@ - [ ] ESP32 IDF - [ ] ESP8266 - [ ] RP2040 +- [ ] BK72xx +- [ ] RTL87xx ## Example entry for `config.yaml`: