From df73170e5ae387960baeb8a27c14d962bad00119 Mon Sep 17 00:00:00 2001 From: Javier Peletier Date: Sun, 24 Jul 2022 22:06:18 +0200 Subject: [PATCH 1/6] modbus: fix queue deduplicator erasing custom commands (#3650) --- .../modbus_controller/modbus_controller.cpp | 12 ++++++++++-- .../components/modbus_controller/modbus_controller.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/esphome/components/modbus_controller/modbus_controller.cpp b/esphome/components/modbus_controller/modbus_controller.cpp index 91e0dcc45f..b7fde157d8 100644 --- a/esphome/components/modbus_controller/modbus_controller.cpp +++ b/esphome/components/modbus_controller/modbus_controller.cpp @@ -108,8 +108,7 @@ void ModbusController::queue_command(const ModbusCommandItem &command) { // check if this commmand is already qeued. // not very effective but the queue is never really large for (auto &item : command_queue_) { - if (item->register_address == command.register_address && item->register_count == command.register_count && - item->register_type == command.register_type && item->function_code == command.function_code) { + if (item->is_equal(command)) { ESP_LOGW(TAG, "Duplicate modbus command found: type=0x%x address=%u count=%u", static_cast(command.register_type), command.register_address, command.register_count); // update the payload of the queued command @@ -489,6 +488,15 @@ bool ModbusCommandItem::send() { return true; } +bool ModbusCommandItem::is_equal(const ModbusCommandItem &other) { + // for custom commands we have to check for identical payloads, since + // address/count/type fields will be set to zero + return this->function_code == ModbusFunctionCode::CUSTOM + ? this->payload == other.payload + : other.register_address == this->register_address && other.register_count == this->register_count && + other.register_type == this->register_type && other.function_code == this->function_code; +} + void number_to_payload(std::vector &data, int64_t value, SensorValueType value_type) { switch (value_type) { case SensorValueType::U_WORD: diff --git a/esphome/components/modbus_controller/modbus_controller.h b/esphome/components/modbus_controller/modbus_controller.h index 6aecf7f8a4..f67242a68e 100644 --- a/esphome/components/modbus_controller/modbus_controller.h +++ b/esphome/components/modbus_controller/modbus_controller.h @@ -395,6 +395,8 @@ class ModbusCommandItem { ModbusController *modbusdevice, const std::vector &values, std::function &data)> &&handler = nullptr); + + bool is_equal(const ModbusCommandItem &other); }; /** Modbus controller class. From 311980e0e478612a01020758d2b71bec2cd02fdc Mon Sep 17 00:00:00 2001 From: Samuel Sieb Date: Sun, 31 Jul 2022 18:08:19 -0700 Subject: [PATCH 2/6] Update inkbird_ibsth1_mini.cpp (#3664) --- esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp b/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp index 76013e28ff..94c22ae84d 100644 --- a/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp +++ b/esphome/components/inkbird_ibsth1_mini/inkbird_ibsth1_mini.cpp @@ -55,7 +55,7 @@ bool InkbirdIbstH1Mini::parse_device(const esp32_ble_tracker::ESPBTDevice &devic ESP_LOGVV(TAG, "parse_device(): manufacturer data element length is expected to be of length 7"); return false; } - if (mnf_data.data[6] != 8) { + if ((mnf_data.data[6] != 8) && (mnf_data.data[6] != 6)) { ESP_LOGVV(TAG, "parse_device(): unexpected data"); return false; } From eb878710c1e6f750c0ca532ee4d258447bac30d6 Mon Sep 17 00:00:00 2001 From: Bryan Berg Date: Mon, 1 Aug 2022 16:32:02 -0700 Subject: [PATCH 3/6] Add CO device class to binary_sensor (#3656) --- esphome/components/binary_sensor/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esphome/components/binary_sensor/__init__.py b/esphome/components/binary_sensor/__init__.py index 40f95d72f9..63fd34c7d5 100644 --- a/esphome/components/binary_sensor/__init__.py +++ b/esphome/components/binary_sensor/__init__.py @@ -29,6 +29,7 @@ from esphome.const import ( DEVICE_CLASS_EMPTY, DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY_CHARGING, + DEVICE_CLASS_CARBON_MONOXIDE, DEVICE_CLASS_COLD, DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, @@ -63,6 +64,7 @@ DEVICE_CLASSES = [ DEVICE_CLASS_EMPTY, DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY_CHARGING, + DEVICE_CLASS_CARBON_MONOXIDE, DEVICE_CLASS_COLD, DEVICE_CLASS_CONNECTIVITY, DEVICE_CLASS_DOOR, From 50f32a3aa59cf31cf55abc73543ee7f09fa7d96e Mon Sep 17 00:00:00 2001 From: Samuel Sieb Date: Mon, 1 Aug 2022 22:07:32 -0700 Subject: [PATCH 4/6] Use application/json instead of text/json (#3671) --- esphome/components/web_server/web_server.cpp | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/esphome/components/web_server/web_server.cpp b/esphome/components/web_server/web_server.cpp index 18374d606b..f0a7efd12f 100644 --- a/esphome/components/web_server/web_server.cpp +++ b/esphome/components/web_server/web_server.cpp @@ -353,7 +353,7 @@ void WebServer::handle_sensor_request(AsyncWebServerRequest *request, const UrlM if (obj->get_object_id() != match.id) continue; std::string data = this->sensor_json(obj, obj->state, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); return; } request->send(404); @@ -377,7 +377,7 @@ void WebServer::handle_text_sensor_request(AsyncWebServerRequest *request, const if (obj->get_object_id() != match.id) continue; std::string data = this->text_sensor_json(obj, obj->state, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); return; } request->send(404); @@ -406,7 +406,7 @@ void WebServer::handle_switch_request(AsyncWebServerRequest *request, const UrlM if (request->method() == HTTP_GET) { std::string data = this->switch_json(obj, obj->state, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); } else if (match.method == "toggle") { this->defer([obj]() { obj->toggle(); }); request->send(200); @@ -462,7 +462,7 @@ void WebServer::handle_binary_sensor_request(AsyncWebServerRequest *request, con if (obj->get_object_id() != match.id) continue; std::string data = this->binary_sensor_json(obj, obj->state, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); return; } request->send(404); @@ -490,7 +490,7 @@ void WebServer::handle_fan_request(AsyncWebServerRequest *request, const UrlMatc if (request->method() == HTTP_GET) { std::string data = this->fan_json(obj, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); } else if (match.method == "toggle") { this->defer([obj]() { obj->toggle().perform(); }); request->send(200); @@ -551,7 +551,7 @@ void WebServer::handle_light_request(AsyncWebServerRequest *request, const UrlMa if (request->method() == HTTP_GET) { std::string data = this->light_json(obj, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); } else if (match.method == "toggle") { this->defer([obj]() { obj->toggle().perform(); }); request->send(200); @@ -630,7 +630,7 @@ void WebServer::handle_cover_request(AsyncWebServerRequest *request, const UrlMa if (request->method() == HTTP_GET) { std::string data = this->cover_json(obj, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); continue; } @@ -687,7 +687,7 @@ void WebServer::handle_number_request(AsyncWebServerRequest *request, const UrlM if (request->method() == HTTP_GET) { std::string data = this->number_json(obj, obj->state, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); return; } if (match.method != "set") { @@ -741,7 +741,7 @@ void WebServer::handle_select_request(AsyncWebServerRequest *request, const UrlM if (request->method() == HTTP_GET) { std::string data = this->select_json(obj, obj->state, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); return; } @@ -788,7 +788,7 @@ void WebServer::handle_climate_request(AsyncWebServerRequest *request, const Url if (request->method() == HTTP_GET) { std::string data = this->climate_json(obj, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); return; } @@ -926,7 +926,7 @@ void WebServer::handle_lock_request(AsyncWebServerRequest *request, const UrlMat if (request->method() == HTTP_GET) { std::string data = this->lock_json(obj, obj->state, DETAIL_STATE); - request->send(200, "text/json", data.c_str()); + request->send(200, "application/json", data.c_str()); } else if (match.method == "lock") { this->defer([obj]() { obj->lock(); }); request->send(200); From e5eaf7a3fecfbb9818890aed7ef7a56cce41ae0e Mon Sep 17 00:00:00 2001 From: Samuel Sieb Date: Mon, 1 Aug 2022 22:09:17 -0700 Subject: [PATCH 5/6] Use correct struct members. (#3672) --- esphome/components/remote_base/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/remote_base/__init__.py b/esphome/components/remote_base/__init__.py index 165da95d67..5ccfc500cf 100644 --- a/esphome/components/remote_base/__init__.py +++ b/esphome/components/remote_base/__init__.py @@ -744,7 +744,8 @@ def rc6_binary_sensor(var, config): var.set_data( cg.StructInitializer( RC6Data, - ("device", config[CONF_DEVICE]), + ("mode", 0), + ("toggle", 0), ("address", config[CONF_ADDRESS]), ("command", config[CONF_COMMAND]), ) From bf8eddb13b4a5846c1e6bd21fb574e97e7bce684 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Mon, 8 Aug 2022 08:24:12 +1200 Subject: [PATCH 6/6] Bump version to 2022.6.3 --- esphome/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/const.py b/esphome/const.py index f7b593b541..f95628735d 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -1,6 +1,6 @@ """Constants used by esphome.""" -__version__ = "2022.6.2" +__version__ = "2022.6.3" ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"