Merge pull request #5554 from esphome/bump-2023.10.0b4

2023.10.0b4
This commit is contained in:
Jesse Hills 2023-10-18 15:44:37 +13:00 committed by GitHub
commit e1c9418aee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 25 deletions

View file

@ -2,9 +2,9 @@
#ifdef USE_ESP32
#include "ble_uuid.h"
#include <cstring>
#include <cstdio>
#include <cstring>
#include "ble_uuid.h"
#include "esphome/core/log.h"
namespace esphome {
@ -16,8 +16,8 @@ BLEAdvertising::BLEAdvertising() {
this->advertising_data_.set_scan_rsp = false;
this->advertising_data_.include_name = true;
this->advertising_data_.include_txpower = true;
this->advertising_data_.min_interval = 0x20;
this->advertising_data_.max_interval = 0x40;
this->advertising_data_.min_interval = 0;
this->advertising_data_.max_interval = 0;
this->advertising_data_.appearance = 0x00;
this->advertising_data_.manufacturer_len = 0;
this->advertising_data_.p_manufacturer_data = nullptr;
@ -42,6 +42,17 @@ void BLEAdvertising::remove_service_uuid(ESPBTUUID uuid) {
this->advertising_uuids_.end());
}
void BLEAdvertising::set_service_data(const std::vector<uint8_t> &data) {
delete[] this->advertising_data_.p_service_data;
this->advertising_data_.p_service_data = nullptr;
this->advertising_data_.service_data_len = data.size();
if (!data.empty()) {
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
this->advertising_data_.p_service_data = new uint8_t[data.size()];
memcpy(this->advertising_data_.p_service_data, data.data(), data.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;
@ -85,8 +96,6 @@ void BLEAdvertising::start() {
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;

View file

@ -21,6 +21,7 @@ class BLEAdvertising {
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(const std::vector<uint8_t> &data);
void set_service_data(const std::vector<uint8_t> &data);
void start();
void stop();

View file

@ -189,6 +189,25 @@ void ESP32ImprovComponent::set_state_(improv::State state) {
if (state != improv::STATE_STOPPED)
this->status_->notify();
}
std::vector<uint8_t> service_data(8, 0);
service_data[0] = 0x77; // PR
service_data[1] = 0x46; // IM
service_data[2] = static_cast<uint8_t>(state);
uint8_t capabilities = 0x00;
#ifdef USE_OUTPUT
if (this->status_indicator_ != nullptr)
capabilities |= improv::CAPABILITY_IDENTIFY;
#endif
service_data[3] = capabilities;
service_data[4] = 0x00; // Reserved
service_data[5] = 0x00; // Reserved
service_data[6] = 0x00; // Reserved
service_data[7] = 0x00; // Reserved
esp32_ble::global_ble->get_advertising()->set_service_data(service_data);
esp32_ble::global_ble->get_advertising()->start();
}
void ESP32ImprovComponent::set_error_(improv::Error error) {

View file

@ -251,7 +251,7 @@ async def component_to_code(config):
# setup board config
cg.add_platformio_option("board", config[CONF_BOARD])
cg.add_build_flag("-DUSE_LIBRETINY")
cg.add_build_flag(f"-DUSE_{config[CONF_COMPONENT_ID]}")
cg.add_build_flag(f"-DUSE_{config[CONF_COMPONENT_ID].upper()}")
cg.add_build_flag(f"-DUSE_LIBRETINY_VARIANT_{config[CONF_FAMILY]}")
cg.add_define("ESPHOME_BOARD", config[CONF_BOARD])
cg.add_define("ESPHOME_VARIANT", FAMILY_FRIENDLY[config[CONF_FAMILY]])

View file

@ -88,11 +88,6 @@ uint64_t bytes_to_uint(const bytes &buffer) {
for (auto const value : buffer) {
val = (val << 8) + value;
}
// Some smart meters send 24 bit signed integers. Sign extend to 64 bit if the
// 24 bit value is negative.
if (buffer.size() == 3 && buffer[0] & 0x80) {
val |= 0xFFFFFFFFFF000000;
}
return val;
}
@ -100,19 +95,15 @@ int64_t bytes_to_int(const bytes &buffer) {
uint64_t tmp = bytes_to_uint(buffer);
int64_t val;
switch (buffer.size()) {
case 1: // int8
val = (int8_t) tmp;
break;
case 2: // int16
val = (int16_t) tmp;
break;
case 4: // int32
val = (int32_t) tmp;
break;
default: // int64
val = (int64_t) tmp;
// sign extension for abbreviations of leading ones (e.g. 3 byte transmissions, see 6.2.2 of SML protocol definition)
// see https://stackoverflow.com/questions/42534749/signed-extension-from-24-bit-to-32-bit-in-c
if (buffer.size() < 8) {
const int bits = buffer.size() * 8;
const uint64_t m = 1u << (bits - 1);
tmp = (tmp ^ m) - m;
}
val = (int64_t) tmp;
return val;
}

View file

@ -1,6 +1,6 @@
"""Constants used by esphome."""
__version__ = "2023.10.0b3"
__version__ = "2023.10.0b4"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
VALID_SUBSTITUTIONS_CHARACTERS = (