1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-28 16:12:24 +01:00

Merge branch 'sha256_ota' into integration

This commit is contained in:
J. Nick Koston
2025-09-25 20:36:20 -05:00
8 changed files with 40 additions and 38 deletions

View File

@@ -58,7 +58,7 @@ jobs:
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@192325c86100d080feab897ff886c34abd4c83a3 # v3.30.3 uses: github/codeql-action/init@303c0aef88fc2fe5ff6d63d3b1596bfd83dfa1f9 # v3.30.4
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }} build-mode: ${{ matrix.build-mode }}
@@ -86,6 +86,6 @@ jobs:
exit 1 exit 1
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@192325c86100d080feab897ff886c34abd4c83a3 # v3.30.3 uses: github/codeql-action/analyze@303c0aef88fc2fe5ff6d63d3b1596bfd83dfa1f9 # v3.30.4
with: with:
category: "/language:${{matrix.language}}" category: "/language:${{matrix.language}}"

View File

@@ -11,7 +11,7 @@ ci:
repos: repos:
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version. # Ruff version.
rev: v0.13.1 rev: v0.13.2
hooks: hooks:
# Run the linter. # Run the linter.
- id: ruff - id: ruff

View File

@@ -15,6 +15,7 @@
#include "esphome/components/ota/ota_backend_esp_idf.h" #include "esphome/components/ota/ota_backend_esp_idf.h"
#include "esphome/core/application.h" #include "esphome/core/application.h"
#include "esphome/core/hal.h" #include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/util.h" #include "esphome/core/util.h"
@@ -528,14 +529,6 @@ void ESPHomeOTAComponent::log_auth_warning_(const LogString *action, const LogSt
ESP_LOGW(TAG, "Auth: %s %s failed", LOG_STR_ARG(action), LOG_STR_ARG(hash_name)); ESP_LOGW(TAG, "Auth: %s %s failed", LOG_STR_ARG(action), LOG_STR_ARG(hash_name));
} }
// Helper to convert uint32 to big-endian bytes
static inline void uint32_to_bytes(uint32_t value, uint8_t *bytes) {
bytes[0] = (value >> 24) & 0xFF;
bytes[1] = (value >> 16) & 0xFF;
bytes[2] = (value >> 8) & 0xFF;
bytes[3] = value & 0xFF;
}
// Non-template function definition to reduce binary size // Non-template function definition to reduce binary size
bool ESPHomeOTAComponent::perform_hash_auth_(HashBase *hasher, const std::string &password, uint8_t auth_request, bool ESPHomeOTAComponent::perform_hash_auth_(HashBase *hasher, const std::string &password, uint8_t auth_request,
const LogString *name, char *buf) { const LogString *name, char *buf) {
@@ -553,10 +546,10 @@ bool ESPHomeOTAComponent::perform_hash_auth_(HashBase *hasher, const std::string
hasher->init(); hasher->init();
// Generate nonce seed bytes // Generate nonce seed bytes using random_bytes
uint32_to_bytes(random_uint32(), nonce_bytes); if (!random_bytes(nonce_bytes, nonce_len)) {
if (nonce_len > 4) { this->log_auth_warning_(LOG_STR("Random bytes generation failed"), name);
uint32_to_bytes(random_uint32(), nonce_bytes + 4); return false;
} }
hasher->add(nonce_bytes, nonce_len); hasher->add(nonce_bytes, nonce_len);
hasher->calculate(); hasher->calculate();

View File

@@ -9,8 +9,8 @@ static const char *const TAG = "htu21d";
static const uint8_t HTU21D_ADDRESS = 0x40; static const uint8_t HTU21D_ADDRESS = 0x40;
static const uint8_t HTU21D_REGISTER_RESET = 0xFE; static const uint8_t HTU21D_REGISTER_RESET = 0xFE;
static const uint8_t HTU21D_REGISTER_TEMPERATURE = 0xF3; static const uint8_t HTU21D_REGISTER_TEMPERATURE = 0xE3;
static const uint8_t HTU21D_REGISTER_HUMIDITY = 0xF5; static const uint8_t HTU21D_REGISTER_HUMIDITY = 0xE5;
static const uint8_t HTU21D_WRITERHT_REG_CMD = 0xE6; /**< Write RH/T User Register 1 */ static const uint8_t HTU21D_WRITERHT_REG_CMD = 0xE6; /**< Write RH/T User Register 1 */
static const uint8_t HTU21D_REGISTER_STATUS = 0xE7; static const uint8_t HTU21D_REGISTER_STATUS = 0xE7;
static const uint8_t HTU21D_WRITEHEATER_REG_CMD = 0x51; /**< Write Heater Control Register */ static const uint8_t HTU21D_WRITEHEATER_REG_CMD = 0x51; /**< Write Heater Control Register */
@@ -57,7 +57,6 @@ void HTU21DComponent::update() {
if (this->temperature_ != nullptr) if (this->temperature_ != nullptr)
this->temperature_->publish_state(temperature); this->temperature_->publish_state(temperature);
this->status_clear_warning();
if (this->write(&HTU21D_REGISTER_HUMIDITY, 1) != i2c::ERROR_OK) { if (this->write(&HTU21D_REGISTER_HUMIDITY, 1) != i2c::ERROR_OK) {
this->status_set_warning(); this->status_set_warning();
@@ -79,10 +78,11 @@ void HTU21DComponent::update() {
if (this->humidity_ != nullptr) if (this->humidity_ != nullptr)
this->humidity_->publish_state(humidity); this->humidity_->publish_state(humidity);
int8_t heater_level; this->status_clear_warning();
// HTU21D does have a heater module but does not have heater level // HTU21D does have a heater module but does not have heater level
// Setting heater level to 1 in case the heater is ON // Setting heater level to 1 in case the heater is ON
uint8_t heater_level = 0;
if (this->sensor_model_ == HTU21D_SENSOR_MODEL_HTU21D) { if (this->sensor_model_ == HTU21D_SENSOR_MODEL_HTU21D) {
if (this->is_heater_enabled()) { if (this->is_heater_enabled()) {
heater_level = 1; heater_level = 1;
@@ -97,34 +97,30 @@ void HTU21DComponent::update() {
if (this->heater_ != nullptr) if (this->heater_ != nullptr)
this->heater_->publish_state(heater_level); this->heater_->publish_state(heater_level);
this->status_clear_warning();
}); });
}); });
} }
bool HTU21DComponent::is_heater_enabled() { bool HTU21DComponent::is_heater_enabled() {
uint8_t raw_heater; uint8_t raw_heater;
if (this->read_register(HTU21D_REGISTER_STATUS, reinterpret_cast<uint8_t *>(&raw_heater), 2) != i2c::ERROR_OK) { if (this->read_register(HTU21D_REGISTER_STATUS, &raw_heater, 1) != i2c::ERROR_OK) {
this->status_set_warning(); this->status_set_warning();
return false; return false;
} }
raw_heater = i2c::i2ctohs(raw_heater); return (bool) ((raw_heater >> HTU21D_REG_HTRE_BIT) & 0x01);
return (bool) (((raw_heater) >> (HTU21D_REG_HTRE_BIT)) & 0x01);
} }
void HTU21DComponent::set_heater(bool status) { void HTU21DComponent::set_heater(bool status) {
uint8_t raw_heater; uint8_t raw_heater;
if (this->read_register(HTU21D_REGISTER_STATUS, reinterpret_cast<uint8_t *>(&raw_heater), 2) != i2c::ERROR_OK) { if (this->read_register(HTU21D_REGISTER_STATUS, &raw_heater, 1) != i2c::ERROR_OK) {
this->status_set_warning(); this->status_set_warning();
return; return;
} }
raw_heater = i2c::i2ctohs(raw_heater);
if (status) { if (status) {
raw_heater |= (1 << (HTU21D_REG_HTRE_BIT)); raw_heater |= (1 << HTU21D_REG_HTRE_BIT);
} else { } else {
raw_heater &= ~(1 << (HTU21D_REG_HTRE_BIT)); raw_heater &= ~(1 << HTU21D_REG_HTRE_BIT);
} }
if (this->write_register(HTU21D_WRITERHT_REG_CMD, &raw_heater, 1) != i2c::ERROR_OK) { if (this->write_register(HTU21D_WRITERHT_REG_CMD, &raw_heater, 1) != i2c::ERROR_OK) {
this->status_set_warning(); this->status_set_warning();
return; return;
@@ -138,14 +134,13 @@ void HTU21DComponent::set_heater_level(uint8_t level) {
} }
} }
int8_t HTU21DComponent::get_heater_level() { uint8_t HTU21DComponent::get_heater_level() {
int8_t raw_heater; uint8_t raw_heater;
if (this->read_register(HTU21D_READHEATER_REG_CMD, reinterpret_cast<uint8_t *>(&raw_heater), 2) != i2c::ERROR_OK) { if (this->read_register(HTU21D_READHEATER_REG_CMD, &raw_heater, 1) != i2c::ERROR_OK) {
this->status_set_warning(); this->status_set_warning();
return 0; return 0;
} }
raw_heater = i2c::i2ctohs(raw_heater); return raw_heater & 0xF;
return raw_heater;
} }
float HTU21DComponent::get_setup_priority() const { return setup_priority::DATA; } float HTU21DComponent::get_setup_priority() const { return setup_priority::DATA; }

View File

@@ -26,7 +26,7 @@ class HTU21DComponent : public PollingComponent, public i2c::I2CDevice {
bool is_heater_enabled(); bool is_heater_enabled();
void set_heater(bool status); void set_heater(bool status);
void set_heater_level(uint8_t level); void set_heater_level(uint8_t level);
int8_t get_heater_level(); uint8_t get_heater_level();
float get_setup_priority() const override; float get_setup_priority() const override;

View File

@@ -123,7 +123,9 @@
#define USE_ONLINE_IMAGE_PNG_SUPPORT #define USE_ONLINE_IMAGE_PNG_SUPPORT
#define USE_ONLINE_IMAGE_JPEG_SUPPORT #define USE_ONLINE_IMAGE_JPEG_SUPPORT
#define USE_OTA #define USE_OTA
#define USE_OTA_MD5
#define USE_OTA_PASSWORD #define USE_OTA_PASSWORD
#define USE_OTA_SHA256
#define USE_OTA_STATE_CALLBACK #define USE_OTA_STATE_CALLBACK
#define USE_OTA_VERSION 2 #define USE_OTA_VERSION 2
#define USE_TIME_TIMEZONE #define USE_TIME_TIMEZONE

View File

@@ -283,11 +283,23 @@ class EsphomeCommandWebSocket(tornado.websocket.WebSocketHandler):
def _stdout_thread(self) -> None: def _stdout_thread(self) -> None:
if not self._use_popen: if not self._use_popen:
return return
line = b""
cr = False
while True: while True:
data = self._proc.stdout.readline() data = self._proc.stdout.read(1)
if data: if data:
data = data.replace(b"\r", b"") if data == b"\r":
self._queue.put_nowait(data) cr = True
elif data == b"\n":
self._queue.put_nowait(line + b"\n")
line = b""
cr = False
elif cr:
self._queue.put_nowait(line + b"\r")
line = data
cr = False
else:
line += data
if self._proc.poll() is not None: if self._proc.poll() is not None:
break break
self._proc.wait(1.0) self._proc.wait(1.0)

View File

@@ -1,6 +1,6 @@
pylint==3.3.8 pylint==3.3.8
flake8==7.3.0 # also change in .pre-commit-config.yaml when updating flake8==7.3.0 # also change in .pre-commit-config.yaml when updating
ruff==0.13.1 # also change in .pre-commit-config.yaml when updating ruff==0.13.2 # also change in .pre-commit-config.yaml when updating
pyupgrade==3.20.0 # also change in .pre-commit-config.yaml when updating pyupgrade==3.20.0 # also change in .pre-commit-config.yaml when updating
pre-commit pre-commit