Skip to content

Commit

Permalink
Merge branch 'esphome:dev' into krahabb3
Browse files Browse the repository at this point in the history
  • Loading branch information
krahabb authored Dec 1, 2024
2 parents 9b24bfd + 83d6834 commit 523c73d
Show file tree
Hide file tree
Showing 38 changed files with 185 additions and 131 deletions.
2 changes: 1 addition & 1 deletion esphome/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def upload_program(config, args, host):

from esphome import espota2

remote_port = ota_conf[CONF_PORT]
remote_port = int(ota_conf[CONF_PORT])
password = ota_conf.get(CONF_PASSWORD, "")

if (
Expand Down
3 changes: 2 additions & 1 deletion esphome/components/apds9306/apds9306.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ void APDS9306::update() {

this->status_clear_warning();

if (!(status &= 0b00001000)) { // No new data
status &= 0b00001000;
if (!status) { // No new data
return;
}

Expand Down
4 changes: 2 additions & 2 deletions esphome/components/deep_sleep/deep_sleep_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ void DeepSleepComponent::dump_config_platform_() {

bool DeepSleepComponent::prepare_to_sleep_() {
if (this->wakeup_pin_mode_ == WAKEUP_PIN_MODE_KEEP_AWAKE && this->wakeup_pin_ != nullptr &&
!this->sleep_duration_.has_value() && this->wakeup_pin_->digital_read()) {
this->wakeup_pin_->digital_read()) {
// Defer deep sleep until inactive
if (!this->next_enter_deep_sleep_) {
this->status_set_warning();
ESP_LOGW(TAG, "Waiting for pin_ to switch state to enter deep sleep...");
ESP_LOGW(TAG, "Waiting wakeup pin state change to enter deep sleep...");
}
this->next_enter_deep_sleep_ = true;
return false;
Expand Down
3 changes: 2 additions & 1 deletion esphome/components/dht/dht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ bool HOT IRAM_ATTR DHT::read_sensor_(float *temperature, float *humidity, bool r

// Wait for falling edge
while (this->pin_->digital_read()) {
if ((end_time = micros()) - start_time > 90) {
end_time = micros();
if (end_time - start_time > 90) {
if (i < 0) {
error_code = 3;
} else {
Expand Down
19 changes: 9 additions & 10 deletions esphome/components/esp32_ble/ble_uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ESPBTUUID ESPBTUUID::from_raw(const uint8_t *data) {
ESPBTUUID ESPBTUUID::from_raw_reversed(const uint8_t *data) {
ESPBTUUID ret;
ret.uuid_.len = ESP_UUID_LEN_128;
for (int i = 0; i < ESP_UUID_LEN_128; i++)
for (uint8_t i = 0; i < ESP_UUID_LEN_128; i++)
ret.uuid_.uuid.uuid128[ESP_UUID_LEN_128 - 1 - i] = data[i];
return ret;
}
Expand All @@ -43,30 +43,30 @@ ESPBTUUID ESPBTUUID::from_raw(const std::string &data) {
if (data.length() == 4) {
ret.uuid_.len = ESP_UUID_LEN_16;
ret.uuid_.uuid.uuid16 = 0;
for (int i = 0; i < data.length();) {
for (uint i = 0; i < data.length(); i += 2) {
uint8_t msb = data.c_str()[i];
uint8_t lsb = data.c_str()[i + 1];
uint8_t lsb_shift = i <= 2 ? (2 - i) * 4 : 0;

if (msb > '9')
msb -= 7;
if (lsb > '9')
lsb -= 7;
ret.uuid_.uuid.uuid16 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (2 - i) * 4;
i += 2;
ret.uuid_.uuid.uuid16 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << lsb_shift;
}
} else if (data.length() == 8) {
ret.uuid_.len = ESP_UUID_LEN_32;
ret.uuid_.uuid.uuid32 = 0;
for (int i = 0; i < data.length();) {
for (uint i = 0; i < data.length(); i += 2) {
uint8_t msb = data.c_str()[i];
uint8_t lsb = data.c_str()[i + 1];
uint8_t lsb_shift = i <= 6 ? (6 - i) * 4 : 0;

if (msb > '9')
msb -= 7;
if (lsb > '9')
lsb -= 7;
ret.uuid_.uuid.uuid32 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (6 - i) * 4;
i += 2;
ret.uuid_.uuid.uuid32 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << lsb_shift;
}
} else if (data.length() == 16) { // how we can have 16 byte length string reprezenting 128 bit uuid??? needs to be
// investigated (lack of time)
Expand All @@ -77,7 +77,7 @@ ESPBTUUID ESPBTUUID::from_raw(const std::string &data) {
// UUID format.
ret.uuid_.len = ESP_UUID_LEN_128;
int n = 0;
for (int i = 0; i < data.length();) {
for (uint i = 0; i < data.length(); i += 2) {
if (data.c_str()[i] == '-')
i++;
uint8_t msb = data.c_str()[i];
Expand All @@ -88,7 +88,6 @@ ESPBTUUID ESPBTUUID::from_raw(const std::string &data) {
if (lsb > '9')
lsb -= 7;
ret.uuid_.uuid.uuid128[15 - n++] = ((msb & 0x0F) << 4) | (lsb & 0x0F);
i += 2;
}
} else {
ESP_LOGE(TAG, "ERROR: UUID value not 2, 4, 16 or 36 bytes - %s", data.c_str());
Expand Down Expand Up @@ -155,7 +154,7 @@ bool ESPBTUUID::operator==(const ESPBTUUID &uuid) const {
}
break;
case ESP_UUID_LEN_128:
for (int i = 0; i < ESP_UUID_LEN_128; i++) {
for (uint8_t i = 0; i < ESP_UUID_LEN_128; i++) {
if (uuid.uuid_.uuid.uuid128[i] != this->uuid_.uuid.uuid128[i]) {
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion esphome/components/esp32_ble_tracker/esp32_ble_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void ESPBTDevice::parse_scan_rst(const esp_ble_gap_cb_param_t::ble_scan_result_e

#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
ESP_LOGVV(TAG, "Parse Result:");
const char *address_type = "";
const char *address_type;
switch (this->address_type_) {
case BLE_ADDR_TYPE_PUBLIC:
address_type = "PUBLIC";
Expand All @@ -446,6 +446,9 @@ void ESPBTDevice::parse_scan_rst(const esp_ble_gap_cb_param_t::ble_scan_result_e
case BLE_ADDR_TYPE_RPA_RANDOM:
address_type = "RPA_RANDOM";
break;
default:
address_type = "UNKNOWN";
break;
}
ESP_LOGVV(TAG, " Address: %02X:%02X:%02X:%02X:%02X:%02X (%s)", this->address_[0], this->address_[1],
this->address_[2], this->address_[3], this->address_[4], this->address_[5], address_type);
Expand Down
40 changes: 14 additions & 26 deletions esphome/components/ezo/ezo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ void EZOSensor::loop() {
if (buf[0] == 1) {
std::string payload = reinterpret_cast<char *>(&buf[1]);
if (!payload.empty()) {
auto start_location = payload.find(',');
switch (to_run->command_type) {
case EzoCommandType::EZO_READ: {
// some sensors return multiple comma-separated values, terminate string after first one
int start_location = 0;
if ((start_location = payload.find(',')) != std::string::npos) {
if (start_location != std::string::npos) {
payload.erase(start_location);
}
auto val = parse_number<float>(payload);
Expand All @@ -126,49 +126,37 @@ void EZOSensor::loop() {
}
break;
}
case EzoCommandType::EZO_LED: {
case EzoCommandType::EZO_LED:
this->led_callback_.call(payload.back() == '1');
break;
}
case EzoCommandType::EZO_DEVICE_INFORMATION: {
int start_location = 0;
if ((start_location = payload.find(',')) != std::string::npos) {
case EzoCommandType::EZO_DEVICE_INFORMATION:
if (start_location != std::string::npos) {
this->device_infomation_callback_.call(payload.substr(start_location + 1));
}
break;
}
case EzoCommandType::EZO_SLOPE: {
int start_location = 0;
if ((start_location = payload.find(',')) != std::string::npos) {
case EzoCommandType::EZO_SLOPE:
if (start_location != std::string::npos) {
this->slope_callback_.call(payload.substr(start_location + 1));
}
break;
}
case EzoCommandType::EZO_CALIBRATION: {
int start_location = 0;
if ((start_location = payload.find(',')) != std::string::npos) {
case EzoCommandType::EZO_CALIBRATION:
if (start_location != std::string::npos) {
this->calibration_callback_.call(payload.substr(start_location + 1));
}
break;
}
case EzoCommandType::EZO_T: {
int start_location = 0;
if ((start_location = payload.find(',')) != std::string::npos) {
case EzoCommandType::EZO_T:
if (start_location != std::string::npos) {
this->t_callback_.call(payload.substr(start_location + 1));
}
break;
}
case EzoCommandType::EZO_CUSTOM: {
case EzoCommandType::EZO_CUSTOM:
this->custom_callback_.call(payload);
break;
}
default: {
default:
break;
}
}
}
}

this->commands_.pop_front();
}

Expand All @@ -178,7 +166,7 @@ void EZOSensor::add_command_(const std::string &command, EzoCommandType command_
ezo_command->command_type = command_type;
ezo_command->delay_ms = delay_ms;
this->commands_.push_back(std::move(ezo_command));
};
}

void EZOSensor::set_calibration_point_(EzoCalibrationType type, float value) {
std::string payload = str_sprintf("Cal,%s,%0.2f", EZO_CALIBRATION_TYPE_STRINGS[type], value);
Expand Down
6 changes: 4 additions & 2 deletions esphome/components/hitachi_ac344/hitachi_ac344.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ bool HitachiClimate::get_swing_v_() {
}

void HitachiClimate::set_swing_h_(uint8_t position) {
if (position > HITACHI_AC344_SWINGH_LEFT_MAX)
return set_swing_h_(HITACHI_AC344_SWINGH_MIDDLE);
if (position > HITACHI_AC344_SWINGH_LEFT_MAX) {
set_swing_h_(HITACHI_AC344_SWINGH_MIDDLE);
return;
}
set_bits(&remote_state_[HITACHI_AC344_SWINGH_BYTE], HITACHI_AC344_SWINGH_OFFSET, HITACHI_AC344_SWINGH_SIZE, position);
set_button_(HITACHI_AC344_BUTTON_SWINGH);
}
Expand Down
6 changes: 4 additions & 2 deletions esphome/components/hitachi_ac424/hitachi_ac424.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ bool HitachiClimate::get_swing_v_() {
}

void HitachiClimate::set_swing_h_(uint8_t position) {
if (position > HITACHI_AC424_SWINGH_LEFT_MAX)
return set_swing_h_(HITACHI_AC424_SWINGH_MIDDLE);
if (position > HITACHI_AC424_SWINGH_LEFT_MAX) {
set_swing_h_(HITACHI_AC424_SWINGH_MIDDLE);
return;
}
set_bits(&remote_state_[HITACHI_AC424_SWINGH_BYTE], HITACHI_AC424_SWINGH_OFFSET, HITACHI_AC424_SWINGH_SIZE, position);
set_button_(HITACHI_AC424_BUTTON_SWINGH);
}
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/hx711/hx711.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool HX711Sensor::read_sensor_(uint32_t *result) {
}

// Cycle clock pin for gain setting
for (uint8_t i = 0; i < this->gain_; i++) {
for (uint8_t i = 0; i < static_cast<uint8_t>(this->gain_); i++) {
this->sck_pin_->digital_write(true);
delayMicroseconds(1);
this->sck_pin_->digital_write(false);
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/hx711/hx711.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace esphome {
namespace hx711 {

enum HX711Gain {
enum HX711Gain : uint8_t {
HX711_GAIN_128 = 1,
HX711_GAIN_32 = 2,
HX711_GAIN_64 = 3,
Expand Down
5 changes: 3 additions & 2 deletions esphome/components/ili9xxx/ili9xxx_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ void ILI9XXXDisplay::draw_pixels_at(int x_start, int y_start, int w, int h, cons
// do color conversion pixel-by-pixel into the buffer and draw it later. If this is happening the user has not
// configured the renderer well.
if (this->rotation_ != display::DISPLAY_ROTATION_0_DEGREES || bitness != display::COLOR_BITNESS_565 || !big_endian) {
return display::Display::draw_pixels_at(x_start, y_start, w, h, ptr, order, bitness, big_endian, x_offset, y_offset,
x_pad);
display::Display::draw_pixels_at(x_start, y_start, w, h, ptr, order, bitness, big_endian, x_offset, y_offset,
x_pad);
return;
}
this->set_addr_window_(x_start, y_start, x_start + w - 1, y_start + h - 1);
// x_ and y_offset are offsets into the source buffer, unrelated to our own offsets into the display.
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void Logger::write_header_(int level, const char *tag, int line) {
if (current_task == main_task_) {
this->printf_to_buffer_("%s[%s][%s:%03u]: ", color, letter, tag, line);
} else {
const char *thread_name = "";
const char *thread_name = ""; // NOLINT(clang-analyzer-deadcode.DeadStores)
#if defined(USE_ESP32)
thread_name = pcTaskGetName(current_task);
#elif defined(USE_LIBRETINY)
Expand Down
8 changes: 7 additions & 1 deletion esphome/components/lvgl/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from esphome import codegen as cg, config_validation as cv
from esphome.const import CONF_ITEMS
from esphome.core import Lambda
from esphome.core import ID, Lambda
from esphome.cpp_generator import LambdaExpression, MockObj
from esphome.cpp_types import uint32
from esphome.schema_extractors import SCHEMA_EXTRACT, schema_extractor
Expand Down Expand Up @@ -72,6 +72,12 @@ async def process(self, value, args=()):
)
if self.retmapper is not None:
return self.retmapper(value)
if isinstance(value, ID):
return await cg.get_variable(value)
if isinstance(value, list):
value = [
await cg.get_variable(x) if isinstance(x, ID) else x for x in value
]
return cg.safe_exp(value)


Expand Down
11 changes: 8 additions & 3 deletions esphome/components/lvgl/lv_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Union

import esphome.codegen as cg
from esphome.components import image
from esphome.components.color import CONF_HEX, ColorStruct, from_rgbw
from esphome.components.font import Font
from esphome.components.image import Image_
Expand Down Expand Up @@ -31,7 +32,7 @@
literal,
)
from .helpers import add_lv_use, esphome_fonts_used, lv_fonts_used, requires_component
from .types import lv_font_t, lv_gradient_t, lv_img_t
from .types import lv_font_t, lv_gradient_t

opacity_consts = LvConstant("LV_OPA_", "TRANSP", "COVER")

Expand Down Expand Up @@ -332,8 +333,12 @@ def image_validator(value):

lv_image = LValidator(
image_validator,
lv_img_t,
retmapper=lambda x: MockObj(x, "->").get_lv_img_dsc(),
image.Image_.operator("ptr"),
requires="image",
)
lv_image_list = LValidator(
cv.ensure_list(image_validator),
cg.std_vector.template(image.Image_.operator("ptr")),
requires="image",
)
lv_bool = LValidator(cv.boolean, cg.bool_, retmapper=literal)
Expand Down
16 changes: 16 additions & 0 deletions esphome/components/lvgl/lvgl_esphome.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ inline void lv_img_set_src(lv_obj_t *obj, esphome::image::Image *image) {
lv_img_set_src(obj, image->get_lv_img_dsc());
}
#endif // USE_LVGL_IMAGE
#ifdef USE_LVGL_ANIMIMG
inline void lv_animimg_set_src(lv_obj_t *img, std::vector<image::Image *> images) {
auto *dsc = static_cast<std::vector<lv_img_dsc_t *> *>(lv_obj_get_user_data(img));
if (dsc == nullptr) {
// object will be lazily allocated but never freed.
dsc = new std::vector<lv_img_dsc_t *>(images.size()); // NOLINT
lv_obj_set_user_data(img, dsc);
}
dsc->clear();
for (auto &image : images) {
dsc->push_back(image->get_lv_img_dsc());
}
lv_animimg_set_src(img, (const void **) dsc->data(), dsc->size());
}

#endif // USE_LVGL_ANIMIMG

// Parent class for things that wrap an LVGL object
class LvCompound {
Expand Down
Loading

0 comments on commit 523c73d

Please sign in to comment.