Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into platform/libretuya
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba2k2 committed Aug 18, 2023
2 parents 1d93164 + f16a24d commit 4b8d00b
Show file tree
Hide file tree
Showing 27 changed files with 404 additions and 159 deletions.
3 changes: 2 additions & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ esphome/components/ens210/* @itn3rd77
esphome/components/esp32/* @esphome/core
esphome/components/esp32_ble/* @jesserockz
esphome/components/esp32_ble_client/* @jesserockz
esphome/components/esp32_ble_server/* @jesserockz
esphome/components/esp32_ble_server/* @clydebarrow @jesserockz
esphome/components/esp32_camera_web_server/* @ayufan
esphome/components/esp32_can/* @Sympatron
esphome/components/esp32_improv/* @jesserockz
Expand Down Expand Up @@ -214,6 +214,7 @@ esphome/components/pid/* @OttoWinter
esphome/components/pipsolar/* @andreashergert1984
esphome/components/pm1006/* @habbie
esphome/components/pmsa003i/* @sjtrny
esphome/components/pmwcs3/* @SeByDocKy
esphome/components/pn532/* @OttoWinter @jesserockz
esphome/components/pn532_i2c/* @OttoWinter @jesserockz
esphome/components/pn532_spi/* @OttoWinter @jesserockz
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ RUN \
git=1:2.30.2-1+deb11u2 \
curl=7.74.0-1.3+deb11u7 \
openssh-client=1:8.4p1-5+deb11u1 \
python3-cffi=1.14.5-1; \
python3-cffi=1.14.5-1 \
libcairo2=1.16.0-5; \
if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
apt-get install -y --no-install-recommends \
build-essential=12.9 \
python3-dev=3.9.2-3 \
zlib1g-dev=1:1.2.11.dfsg-2+deb11u2 \
libjpeg-dev=1:2.0.6-4 \
libcairo2=1.16.0-5 \
libfreetype-dev=2.10.4+dfsg-1+deb11u1; \
fi; \
rm -rf \
Expand Down
4 changes: 0 additions & 4 deletions esphome/components/debug/debug_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
#include <esp_heap_caps.h>
#include <esp_system.h>

#if ESP_IDF_VERSION_MAJOR >= 4
#include <esp32/rom/rtc.h>
#include <esp_chip_info.h>
#else
#include <rom/rtc.h>
#endif

#endif // USE_ESP32

Expand Down
12 changes: 1 addition & 11 deletions esphome/components/esp32/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#include <esp_timer.h>
#include <soc/rtc.h>

#if ESP_IDF_VERSION_MAJOR >= 4
#include <hal/cpu_hal.h>
#endif

#ifdef USE_ARDUINO
#include <esp32-hal.h>
Expand Down Expand Up @@ -55,15 +53,7 @@ void arch_init() {
void IRAM_ATTR HOT arch_feed_wdt() { esp_task_wdt_reset(); }

uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; }
uint32_t arch_get_cpu_cycle_count() {
#if ESP_IDF_VERSION_MAJOR >= 4
return cpu_hal_get_cycle_count();
#else
uint32_t ccount;
__asm__ __volatile__("esync; rsr %0,ccount" : "=a"(ccount));
return ccount;
#endif
}
uint32_t arch_get_cpu_cycle_count() { return cpu_hal_get_cycle_count(); }
uint32_t arch_get_cpu_freq_hz() { return rtc_clk_apb_freq_get(); }

#ifdef USE_ESP_IDF
Expand Down
37 changes: 24 additions & 13 deletions esphome/components/esp32_ble/ble_advertising.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ void BLEAdvertising::remove_service_uuid(ESPBTUUID uuid) {
this->advertising_uuids_.end());
}

void BLEAdvertising::set_manufacturer_data(uint8_t *data, uint16_t size) {
this->advertising_data_.p_manufacturer_data = data;
this->advertising_data_.manufacturer_len = size;
void BLEAdvertising::set_manufacturer_data(const std::vector<uint8_t> &data) {
delete[] this->advertising_data_.p_manufacturer_data;
this->advertising_data_.p_manufacturer_data = nullptr;
this->advertising_data_.manufacturer_len = data.size();
if (!data.empty()) {
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
this->advertising_data_.p_manufacturer_data = new uint8_t[data.size()];
memcpy(this->advertising_data_.p_manufacturer_data, data.data(), data.size());
}
}

void BLEAdvertising::start() {
Expand Down Expand Up @@ -74,16 +80,21 @@ void BLEAdvertising::start() {
return;
}

memcpy(&this->scan_response_data_, &this->advertising_data_, sizeof(esp_ble_adv_data_t));
this->scan_response_data_.set_scan_rsp = true;
this->scan_response_data_.include_name = true;
this->scan_response_data_.include_txpower = true;
this->scan_response_data_.appearance = 0;
this->scan_response_data_.flag = 0;
err = esp_ble_gap_config_adv_data(&this->scan_response_data_);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_ble_gap_config_adv_data failed (Scan response): %d", err);
return;
if (this->scan_response_) {
memcpy(&this->scan_response_data_, &this->advertising_data_, sizeof(esp_ble_adv_data_t));
this->scan_response_data_.set_scan_rsp = true;
this->scan_response_data_.include_name = true;
this->scan_response_data_.include_txpower = true;
this->scan_response_data_.min_interval = 0;
this->scan_response_data_.max_interval = 0;
this->scan_response_data_.manufacturer_len = 0;
this->scan_response_data_.appearance = 0;
this->scan_response_data_.flag = 0;
err = esp_ble_gap_config_adv_data(&this->scan_response_data_);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_ble_gap_config_adv_data failed (Scan response): %d", err);
return;
}
}

if (this->advertising_data_.service_uuid_len > 0) {
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/esp32_ble/ble_advertising.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BLEAdvertising {
void remove_service_uuid(ESPBTUUID uuid);
void set_scan_response(bool scan_response) { this->scan_response_ = scan_response; }
void set_min_preferred_interval(uint16_t interval) { this->advertising_data_.min_interval = interval; }
void set_manufacturer_data(uint8_t *data, uint16_t size);
void set_manufacturer_data(const std::vector<uint8_t> &data);

void start();
void stop();
Expand Down
6 changes: 5 additions & 1 deletion esphome/components/esp32_ble_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from esphome.components.esp32 import add_idf_sdkconfig_option

AUTO_LOAD = ["esp32_ble"]
CODEOWNERS = ["@jesserockz"]
CODEOWNERS = ["@jesserockz", "@clydebarrow"]
CONFLICTS_WITH = ["esp32_ble_beacon"]
DEPENDENCIES = ["esp32"]

CONF_MANUFACTURER = "manufacturer"
CONF_MANUFACTURER_DATA = "manufacturer_data"

esp32_ble_server_ns = cg.esphome_ns.namespace("esp32_ble_server")
BLEServer = esp32_ble_server_ns.class_(
Expand All @@ -27,6 +28,7 @@
cv.GenerateID(): cv.declare_id(BLEServer),
cv.GenerateID(esp32_ble.CONF_BLE_ID): cv.use_id(esp32_ble.ESP32BLE),
cv.Optional(CONF_MANUFACTURER, default="ESPHome"): cv.string,
cv.Optional(CONF_MANUFACTURER_DATA): cv.Schema([cv.hex_uint8_t]),
cv.Optional(CONF_MODEL): cv.string,
}
).extend(cv.COMPONENT_SCHEMA)
Expand All @@ -42,6 +44,8 @@ async def to_code(config):
cg.add(var.set_parent(parent))

cg.add(var.set_manufacturer(config[CONF_MANUFACTURER]))
if CONF_MANUFACTURER_DATA in config:
cg.add(var.set_manufacturer_data(config[CONF_MANUFACTURER_DATA]))
if CONF_MODEL in config:
cg.add(var.set_model(config[CONF_MODEL]))
cg.add_define("USE_ESP32_BLE_SERVER")
Expand Down
8 changes: 8 additions & 0 deletions esphome/components/esp32_ble_server/ble_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void BLEServer::loop() {
if (this->device_information_service_->is_running()) {
this->state_ = RUNNING;
this->can_proceed_ = true;
this->restart_advertising_();
ESP_LOGD(TAG, "BLE server setup successfully");
} else if (!this->device_information_service_->is_starting()) {
this->device_information_service_->start();
Expand All @@ -77,6 +78,13 @@ void BLEServer::loop() {
}
}

void BLEServer::restart_advertising_() {
if (this->state_ == RUNNING) {
esp32_ble::global_ble->get_advertising()->set_manufacturer_data(this->manufacturer_data_);
esp32_ble::global_ble->get_advertising()->start();
}
}

bool BLEServer::create_device_characteristics_() {
if (this->model_.has_value()) {
BLECharacteristic *model =
Expand Down
6 changes: 6 additions & 0 deletions esphome/components/esp32_ble_server/ble_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class BLEServer : public Component, public GATTsEventHandler, public Parented<ES

void set_manufacturer(const std::string &manufacturer) { this->manufacturer_ = manufacturer; }
void set_model(const std::string &model) { this->model_ = model; }
void set_manufacturer_data(const std::vector<uint8_t> &data) {
this->manufacturer_data_ = data;
this->restart_advertising_();
}

std::shared_ptr<BLEService> create_service(const uint8_t *uuid, bool advertise = false);
std::shared_ptr<BLEService> create_service(uint16_t uuid, bool advertise = false);
Expand All @@ -63,6 +67,7 @@ class BLEServer : public Component, public GATTsEventHandler, public Parented<ES

protected:
bool create_device_characteristics_();
void restart_advertising_();

void add_client_(uint16_t conn_id, void *client) {
this->clients_.insert(std::pair<uint16_t, void *>(conn_id, client));
Expand All @@ -73,6 +78,7 @@ class BLEServer : public Component, public GATTsEventHandler, public Parented<ES

std::string manufacturer_;
optional<std::string> model_;
std::vector<uint8_t> manufacturer_data_;
esp_gatt_if_t gatts_if_{0};
bool registered_{false};

Expand Down
4 changes: 0 additions & 4 deletions esphome/components/esp32_touch/esp32_touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

#include <vector>

#if ESP_IDF_VERSION_MAJOR >= 4
#include <driver/touch_sensor.h>
#else
#include <driver/touch_pad.h>
#endif

namespace esphome {
namespace esp32_touch {
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/haier/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

SUPPORTED_CLIMATE_MODES_OPTIONS = {
"OFF": ClimateMode.CLIMATE_MODE_OFF, # always available
"AUTO": ClimateMode.CLIMATE_MODE_AUTO, # always available
"HEAT_COOL": ClimateMode.CLIMATE_MODE_HEAT_COOL, # always available
"COOL": ClimateMode.CLIMATE_MODE_COOL,
"HEAT": ClimateMode.CLIMATE_MODE_HEAT,
"DRY": ClimateMode.CLIMATE_MODE_DRY,
Expand Down
6 changes: 3 additions & 3 deletions esphome/components/haier/haier_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ HaierClimateBase::HaierClimateBase()
this->traits_ = climate::ClimateTraits();
this->traits_.set_supported_modes({climate::CLIMATE_MODE_OFF, climate::CLIMATE_MODE_COOL, climate::CLIMATE_MODE_HEAT,
climate::CLIMATE_MODE_FAN_ONLY, climate::CLIMATE_MODE_DRY,
climate::CLIMATE_MODE_AUTO});
climate::CLIMATE_MODE_HEAT_COOL});
this->traits_.set_supported_fan_modes(
{climate::CLIMATE_FAN_AUTO, climate::CLIMATE_FAN_LOW, climate::CLIMATE_FAN_MEDIUM, climate::CLIMATE_FAN_HIGH});
this->traits_.set_supported_swing_modes({climate::CLIMATE_SWING_OFF, climate::CLIMATE_SWING_BOTH,
Expand Down Expand Up @@ -171,8 +171,8 @@ void HaierClimateBase::set_answer_timeout(uint32_t timeout) {

void HaierClimateBase::set_supported_modes(const std::set<climate::ClimateMode> &modes) {
this->traits_.set_supported_modes(modes);
this->traits_.add_supported_mode(climate::CLIMATE_MODE_OFF); // Always available
this->traits_.add_supported_mode(climate::CLIMATE_MODE_AUTO); // Always available
this->traits_.add_supported_mode(climate::CLIMATE_MODE_OFF); // Always available
this->traits_.add_supported_mode(climate::CLIMATE_MODE_HEAT_COOL); // Always available
}

void HaierClimateBase::set_supported_presets(const std::set<climate::ClimatePreset> &presets) {
Expand Down
4 changes: 2 additions & 2 deletions esphome/components/haier/hon_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ haier_protocol::HaierMessage HonClimate::get_control_message() {
case CLIMATE_MODE_OFF:
out_data->ac_power = 0;
break;
case CLIMATE_MODE_AUTO:
case CLIMATE_MODE_HEAT_COOL:
out_data->ac_power = 1;
out_data->ac_mode = (uint8_t) hon_protocol::ConditioningMode::AUTO;
out_data->fan_mode = this->other_modes_fan_speed_;
Expand Down Expand Up @@ -758,7 +758,7 @@ haier_protocol::HandlerError HonClimate::process_status_message_(const uint8_t *
this->mode = CLIMATE_MODE_FAN_ONLY;
break;
case (uint8_t) hon_protocol::ConditioningMode::AUTO:
this->mode = CLIMATE_MODE_AUTO;
this->mode = CLIMATE_MODE_HEAT_COOL;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions esphome/components/haier/smartair2_climate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ haier_protocol::HaierMessage Smartair2Climate::get_control_message() {
out_data->ac_power = 0;
break;

case CLIMATE_MODE_AUTO:
case CLIMATE_MODE_HEAT_COOL:
out_data->ac_power = 1;
out_data->ac_mode = (uint8_t) smartair2_protocol::ConditioningMode::AUTO;
out_data->fan_mode = this->other_modes_fan_speed_;
Expand Down Expand Up @@ -487,7 +487,7 @@ haier_protocol::HandlerError Smartair2Climate::process_status_message_(const uin
this->mode = CLIMATE_MODE_FAN_ONLY;
break;
case (uint8_t) smartair2_protocol::ConditioningMode::AUTO:
this->mode = CLIMATE_MODE_AUTO;
this->mode = CLIMATE_MODE_HEAT_COOL;
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions esphome/components/pmwcs3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CODEOWNERS = ["@SeByDocKy"]
Loading

0 comments on commit 4b8d00b

Please sign in to comment.