Merge remote-tracking branch 'upstream/dev' into gsm

This commit is contained in:
oarcher 2024-08-11 17:39:43 +02:00
commit 6cd0d8f8c2
14 changed files with 67 additions and 27 deletions

View File

@ -141,7 +141,7 @@ struct ClimateDeviceRestoreState {
float target_temperature_low; float target_temperature_low;
float target_temperature_high; float target_temperature_high;
}; };
}; } __attribute__((packed));
float target_humidity; float target_humidity;
/// Convert this struct to a climate call that can be performed. /// Convert this struct to a climate call that can be performed.

View File

@ -39,8 +39,8 @@ bool HX711Sensor::read_sensor_(uint32_t *result) {
return false; return false;
} }
this->status_clear_warning();
uint32_t data = 0; uint32_t data = 0;
bool final_dout;
{ {
InterruptLock lock; InterruptLock lock;
@ -59,8 +59,17 @@ bool HX711Sensor::read_sensor_(uint32_t *result) {
this->sck_pin_->digital_write(false); this->sck_pin_->digital_write(false);
delayMicroseconds(1); delayMicroseconds(1);
} }
final_dout = this->dout_pin_->digital_read();
} }
if (!final_dout) {
ESP_LOGW(TAG, "HX711 DOUT pin not high after reading (data 0x%" PRIx32 ")!", data);
this->status_set_warning();
return false;
}
this->status_clear_warning();
if (data & 0x800000ULL) { if (data & 0x800000ULL) {
data |= 0xFF000000ULL; data |= 0xFF000000ULL;
} }

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#include "esphome/core/defines.h" #include "esphome/core/defines.h"
#ifdef USE_LVGL_BINARY_SENSOR #ifdef USE_BINARY_SENSOR
#include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/binary_sensor/binary_sensor.h"
#endif // USE_LVGL_BINARY_SENSOR #endif // USE_BINARY_SENSOR
#ifdef USE_LVGL_ROTARY_ENCODER #ifdef USE_LVGL_ROTARY_ENCODER
#include "esphome/components/rotary_encoder/rotary_encoder.h" #include "esphome/components/rotary_encoder/rotary_encoder.h"
#endif // USE_LVGL_ROTARY_ENCODER #endif // USE_LVGL_ROTARY_ENCODER

View File

@ -19,7 +19,7 @@ class LVGLNumber : public number::Number {
} }
protected: protected:
void control(float value) { void control(float value) override {
if (this->control_lambda_ != nullptr) if (this->control_lambda_ != nullptr)
this->control_lambda_(value); this->control_lambda_(value);
else else

View File

@ -19,7 +19,7 @@ class LVGLSwitch : public switch_::Switch {
} }
protected: protected:
void write_state(bool value) { void write_state(bool value) override {
if (this->state_lambda_ != nullptr) if (this->state_lambda_ != nullptr)
this->state_lambda_(value); this->state_lambda_(value);
else else

View File

@ -19,7 +19,7 @@ class LVGLText : public text::Text {
} }
protected: protected:
void control(const std::string &value) { void control(const std::string &value) override {
if (this->control_lambda_ != nullptr) if (this->control_lambda_ != nullptr)
this->control_lambda_(value); this->control_lambda_(value);
else else

View File

@ -271,6 +271,7 @@ async def set_obj_properties(w: Widget, config):
"""Generate a list of C++ statements to apply properties to an lv_obj_t""" """Generate a list of C++ statements to apply properties to an lv_obj_t"""
if layout := config.get(CONF_LAYOUT): if layout := config.get(CONF_LAYOUT):
layout_type: str = layout[CONF_TYPE] layout_type: str = layout[CONF_TYPE]
add_lv_use(layout_type)
lv_obj.set_layout(w.obj, literal(f"LV_LAYOUT_{layout_type.upper()}")) lv_obj.set_layout(w.obj, literal(f"LV_LAYOUT_{layout_type.upper()}"))
if layout_type == TYPE_GRID: if layout_type == TYPE_GRID:
wid = config[CONF_ID] wid = config[CONF_ID]
@ -334,7 +335,7 @@ async def set_obj_properties(w: Widget, config):
for key, value in states.items(): for key, value in states.items():
if isinstance(value, cv.Lambda): if isinstance(value, cv.Lambda):
lambs[key] = value lambs[key] = value
elif value == "true": elif value:
adds.add(key) adds.add(key)
else: else:
clears.add(key) clears.add(key)

View File

@ -150,12 +150,40 @@ bool MQTTComponent::send_discovery_() {
const std::string &node_area = App.get_area(); const std::string &node_area = App.get_area();
JsonObject device_info = root.createNestedObject(MQTT_DEVICE); JsonObject device_info = root.createNestedObject(MQTT_DEVICE);
device_info[MQTT_DEVICE_IDENTIFIERS] = get_mac_address(); const auto mac = get_mac_address();
device_info[MQTT_DEVICE_IDENTIFIERS] = mac;
device_info[MQTT_DEVICE_NAME] = node_friendly_name; device_info[MQTT_DEVICE_NAME] = node_friendly_name;
device_info[MQTT_DEVICE_SW_VERSION] = "esphome v" ESPHOME_VERSION " " + App.get_compilation_time(); #ifdef ESPHOME_PROJECT_NAME
device_info[MQTT_DEVICE_SW_VERSION] = ESPHOME_PROJECT_VERSION " (ESPHome " ESPHOME_VERSION ")";
const char *model = std::strchr(ESPHOME_PROJECT_NAME, '.');
if (model == nullptr) { // must never happen but check anyway
device_info[MQTT_DEVICE_MODEL] = ESPHOME_BOARD;
device_info[MQTT_DEVICE_MANUFACTURER] = ESPHOME_PROJECT_NAME;
} else {
device_info[MQTT_DEVICE_MODEL] = model + 1;
device_info[MQTT_DEVICE_MANUFACTURER] = std::string(ESPHOME_PROJECT_NAME, model - ESPHOME_PROJECT_NAME);
}
#else
device_info[MQTT_DEVICE_SW_VERSION] = ESPHOME_VERSION " (" + App.get_compilation_time() + ")";
device_info[MQTT_DEVICE_MODEL] = ESPHOME_BOARD; device_info[MQTT_DEVICE_MODEL] = ESPHOME_BOARD;
device_info[MQTT_DEVICE_MANUFACTURER] = "espressif"; #if defined(USE_ESP8266) || defined(USE_ESP32)
device_info[MQTT_DEVICE_SUGGESTED_AREA] = node_area; device_info[MQTT_DEVICE_MANUFACTURER] = "Espressif";
#elif defined(USE_RP2040)
device_info[MQTT_DEVICE_MANUFACTURER] = "Raspberry Pi";
#elif defined(USE_BK72XX)
device_info[MQTT_DEVICE_MANUFACTURER] = "Beken";
#elif defined(USE_RTL87XX)
device_info[MQTT_DEVICE_MANUFACTURER] = "Realtek";
#elif defined(USE_HOST)
device_info[MQTT_DEVICE_MANUFACTURER] = "Host";
#endif
#endif
if (!node_area.empty()) {
device_info[MQTT_DEVICE_SUGGESTED_AREA] = node_area;
}
device_info[MQTT_DEVICE_CONNECTIONS][0][0] = "mac";
device_info[MQTT_DEVICE_CONNECTIONS][0][1] = mac;
}, },
this->qos_, discovery_info.retain); this->qos_, discovery_info.retain);
} }

View File

@ -62,6 +62,7 @@ constexpr const char *const MQTT_DEVICE_MODEL = "mdl";
constexpr const char *const MQTT_DEVICE_NAME = "name"; constexpr const char *const MQTT_DEVICE_NAME = "name";
constexpr const char *const MQTT_DEVICE_SUGGESTED_AREA = "sa"; constexpr const char *const MQTT_DEVICE_SUGGESTED_AREA = "sa";
constexpr const char *const MQTT_DEVICE_SW_VERSION = "sw"; constexpr const char *const MQTT_DEVICE_SW_VERSION = "sw";
constexpr const char *const MQTT_DEVICE_HW_VERSION = "hw";
constexpr const char *const MQTT_DOCKED_TEMPLATE = "dock_tpl"; constexpr const char *const MQTT_DOCKED_TEMPLATE = "dock_tpl";
constexpr const char *const MQTT_DOCKED_TOPIC = "dock_t"; constexpr const char *const MQTT_DOCKED_TOPIC = "dock_t";
constexpr const char *const MQTT_EFFECT_COMMAND_TOPIC = "fx_cmd_t"; constexpr const char *const MQTT_EFFECT_COMMAND_TOPIC = "fx_cmd_t";
@ -322,6 +323,7 @@ constexpr const char *const MQTT_DEVICE_MODEL = "model";
constexpr const char *const MQTT_DEVICE_NAME = "name"; constexpr const char *const MQTT_DEVICE_NAME = "name";
constexpr const char *const MQTT_DEVICE_SUGGESTED_AREA = "suggested_area"; constexpr const char *const MQTT_DEVICE_SUGGESTED_AREA = "suggested_area";
constexpr const char *const MQTT_DEVICE_SW_VERSION = "sw_version"; constexpr const char *const MQTT_DEVICE_SW_VERSION = "sw_version";
constexpr const char *const MQTT_DEVICE_HW_VERSION = "hw_version";
constexpr const char *const MQTT_DOCKED_TEMPLATE = "docked_template"; constexpr const char *const MQTT_DOCKED_TEMPLATE = "docked_template";
constexpr const char *const MQTT_DOCKED_TOPIC = "docked_topic"; constexpr const char *const MQTT_DOCKED_TOPIC = "docked_topic";
constexpr const char *const MQTT_EFFECT_COMMAND_TOPIC = "effect_command_topic"; constexpr const char *const MQTT_EFFECT_COMMAND_TOPIC = "effect_command_topic";

View File

@ -13,7 +13,7 @@ class SpiLedStrip : public light::AddressableLight,
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH, spi::CLOCK_PHASE_TRAILING, public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_HIGH, spi::CLOCK_PHASE_TRAILING,
spi::DATA_RATE_1MHZ> { spi::DATA_RATE_1MHZ> {
public: public:
void setup() { this->spi_setup(); } void setup() override { this->spi_setup(); }
int32_t size() const override { return this->num_leds_; } int32_t size() const override { return this->num_leds_; }
@ -43,7 +43,7 @@ class SpiLedStrip : public light::AddressableLight,
memset(this->buf_, 0, 4); memset(this->buf_, 0, 4);
} }
void dump_config() { void dump_config() override {
esph_log_config(TAG, "SPI LED Strip:"); esph_log_config(TAG, "SPI LED Strip:");
esph_log_config(TAG, " LEDs: %d", this->num_leds_); esph_log_config(TAG, " LEDs: %d", this->num_leds_);
if (this->data_rate_ >= spi::DATA_RATE_1MHZ) if (this->data_rate_ >= spi::DATA_RATE_1MHZ)

View File

@ -647,7 +647,7 @@ void Sprinkler::set_valve_run_duration(const optional<size_t> valve_number, cons
return; return;
} }
auto call = this->valve_[valve_number.value()].run_duration_number->make_call(); auto call = this->valve_[valve_number.value()].run_duration_number->make_call();
if (this->valve_[valve_number.value()].run_duration_number->traits.get_unit_of_measurement() == min_str) { if (this->valve_[valve_number.value()].run_duration_number->traits.get_unit_of_measurement() == MIN_STR) {
call.set_value(run_duration.value() / 60.0); call.set_value(run_duration.value() / 60.0);
} else { } else {
call.set_value(run_duration.value()); call.set_value(run_duration.value());
@ -729,7 +729,7 @@ uint32_t Sprinkler::valve_run_duration(const size_t valve_number) {
return 0; return 0;
} }
if (this->valve_[valve_number].run_duration_number != nullptr) { if (this->valve_[valve_number].run_duration_number != nullptr) {
if (this->valve_[valve_number].run_duration_number->traits.get_unit_of_measurement() == min_str) { if (this->valve_[valve_number].run_duration_number->traits.get_unit_of_measurement() == MIN_STR) {
return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state * 60)); return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state * 60));
} else { } else {
return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state)); return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state));

View File

@ -11,7 +11,7 @@
namespace esphome { namespace esphome {
namespace sprinkler { namespace sprinkler {
const std::string min_str = "min"; const std::string MIN_STR = "min";
enum SprinklerState : uint8_t { enum SprinklerState : uint8_t {
// NOTE: these states are used by both SprinklerValveOperator and Sprinkler (the controller)! // NOTE: these states are used by both SprinklerValveOperator and Sprinkler (the controller)!

View File

@ -1,32 +1,32 @@
import logging
from importlib import resources from importlib import resources
import logging
from typing import Optional from typing import Optional
import tzlocal import tzlocal
from esphome import automation
from esphome.automation import Condition
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome import automation
from esphome.const import ( from esphome.const import (
CONF_ID, CONF_AT,
CONF_CRON, CONF_CRON,
CONF_DAYS_OF_MONTH, CONF_DAYS_OF_MONTH,
CONF_DAYS_OF_WEEK, CONF_DAYS_OF_WEEK,
CONF_HOUR,
CONF_HOURS, CONF_HOURS,
CONF_ID,
CONF_MINUTE,
CONF_MINUTES, CONF_MINUTES,
CONF_MONTHS, CONF_MONTHS,
CONF_ON_TIME, CONF_ON_TIME,
CONF_ON_TIME_SYNC, CONF_ON_TIME_SYNC,
CONF_SECOND,
CONF_SECONDS, CONF_SECONDS,
CONF_TIMEZONE, CONF_TIMEZONE,
CONF_TRIGGER_ID, CONF_TRIGGER_ID,
CONF_AT,
CONF_SECOND,
CONF_HOUR,
CONF_MINUTE,
) )
from esphome.core import coroutine_with_priority from esphome.core import coroutine_with_priority
from esphome.automation import Condition
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -63,7 +63,7 @@ class EntityBase {
EntityCategory entity_category_{ENTITY_CATEGORY_NONE}; EntityCategory entity_category_{ENTITY_CATEGORY_NONE};
}; };
class EntityBase_DeviceClass { class EntityBase_DeviceClass { // NOLINT(readability-identifier-naming)
public: public:
/// Get the device class, using the manual override if set. /// Get the device class, using the manual override if set.
std::string get_device_class(); std::string get_device_class();
@ -74,7 +74,7 @@ class EntityBase_DeviceClass {
const char *device_class_{nullptr}; ///< Device class override const char *device_class_{nullptr}; ///< Device class override
}; };
class EntityBase_UnitOfMeasurement { class EntityBase_UnitOfMeasurement { // NOLINT(readability-identifier-naming)
public: public:
/// Get the unit of measurement, using the manual override if set. /// Get the unit of measurement, using the manual override if set.
std::string get_unit_of_measurement(); std::string get_unit_of_measurement();