Merge branch 'esphome:dev' into dev

This commit is contained in:
CptSkippy 2024-06-04 06:16:49 -07:00 committed by GitHub
commit d90a51507b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 147 additions and 43 deletions

View file

@ -167,7 +167,8 @@ esphome/components/homeassistant/* @OttoWinter
esphome/components/honeywell_hih_i2c/* @Benichou34 esphome/components/honeywell_hih_i2c/* @Benichou34
esphome/components/honeywellabp/* @RubyBailey esphome/components/honeywellabp/* @RubyBailey
esphome/components/honeywellabp2_i2c/* @jpfaff esphome/components/honeywellabp2_i2c/* @jpfaff
esphome/components/host/* @esphome/core esphome/components/host/* @clydebarrow @esphome/core
esphome/components/host/time/* @clydebarrow
esphome/components/hrxl_maxsonar_wr/* @netmikey esphome/components/hrxl_maxsonar_wr/* @netmikey
esphome/components/hte501/* @Stock-M esphome/components/hte501/* @Stock-M
esphome/components/htu31d/* @betterengineering esphome/components/htu31d/* @betterengineering

View file

@ -100,6 +100,9 @@ RUN --mount=type=tmpfs,target=/root/.cargo if [ "$TARGETARCH$TARGETVARIANT" = "a
--break-system-packages --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \ --break-system-packages --no-cache-dir -r /requirements.txt -r /requirements_optional.txt \
&& /platformio_install_deps.py /platformio.ini --libraries && /platformio_install_deps.py /platformio.ini --libraries
# Avoid unsafe git error when container user and file config volume permissions don't match
RUN git config --system --add safe.directory '/config/*'
# ======================= docker-type image ======================= # ======================= docker-type image =======================
FROM base AS docker FROM base AS docker

View file

@ -28,6 +28,13 @@ EthernetComponent *global_eth_component; // NOLINT(cppcoreguidelines-avoid-non-
return; \ return; \
} }
#define ESPHL_ERROR_CHECK_RET(err, message, ret) \
if ((err) != ESP_OK) { \
ESP_LOGE(TAG, message ": (%d) %s", err, esp_err_to_name(err)); \
this->mark_failed(); \
return ret; \
}
EthernetComponent::EthernetComponent() { global_eth_component = this; } EthernetComponent::EthernetComponent() { global_eth_component = this; }
void EthernetComponent::setup() { void EthernetComponent::setup() {
@ -498,22 +505,9 @@ void EthernetComponent::dump_connect_params_() {
} }
#endif /* USE_NETWORK_IPV6 */ #endif /* USE_NETWORK_IPV6 */
esp_err_t err; ESP_LOGCONFIG(TAG, " MAC Address: %s", this->get_eth_mac_address_pretty().c_str());
ESP_LOGCONFIG(TAG, " Is Full Duplex: %s", YESNO(this->get_duplex_mode() == ETH_DUPLEX_FULL));
uint8_t mac[6]; ESP_LOGCONFIG(TAG, " Link Speed: %u", this->get_link_speed() == ETH_SPEED_100M ? 100 : 10);
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_MAC_ADDR, &mac);
ESPHL_ERROR_CHECK(err, "ETH_CMD_G_MAC error");
ESP_LOGCONFIG(TAG, " MAC Address: %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
eth_duplex_t duplex_mode;
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_DUPLEX_MODE, &duplex_mode);
ESPHL_ERROR_CHECK(err, "ETH_CMD_G_DUPLEX_MODE error");
ESP_LOGCONFIG(TAG, " Is Full Duplex: %s", YESNO(duplex_mode == ETH_DUPLEX_FULL));
eth_speed_t speed;
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_SPEED, &speed);
ESPHL_ERROR_CHECK(err, "ETH_CMD_G_SPEED error");
ESP_LOGCONFIG(TAG, " Link Speed: %u", speed == ETH_SPEED_100M ? 100 : 10);
} }
#ifdef USE_ETHERNET_SPI #ifdef USE_ETHERNET_SPI
@ -546,6 +540,34 @@ std::string EthernetComponent::get_use_address() const {
void EthernetComponent::set_use_address(const std::string &use_address) { this->use_address_ = use_address; } void EthernetComponent::set_use_address(const std::string &use_address) { this->use_address_ = use_address; }
void EthernetComponent::get_eth_mac_address_raw(uint8_t *mac) {
esp_err_t err;
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_MAC_ADDR, mac);
ESPHL_ERROR_CHECK(err, "ETH_CMD_G_MAC error");
}
std::string EthernetComponent::get_eth_mac_address_pretty() {
uint8_t mac[6];
get_mac_address_raw(mac);
return str_snprintf("%02X:%02X:%02X:%02X:%02X:%02X", 17, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
eth_duplex_t EthernetComponent::get_duplex_mode() {
esp_err_t err;
eth_duplex_t duplex_mode;
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_DUPLEX_MODE, &duplex_mode);
ESPHL_ERROR_CHECK_RET(err, "ETH_CMD_G_DUPLEX_MODE error", ETH_DUPLEX_HALF);
return duplex_mode;
}
eth_speed_t EthernetComponent::get_link_speed() {
esp_err_t err;
eth_speed_t speed;
err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_SPEED, &speed);
ESPHL_ERROR_CHECK_RET(err, "ETH_CMD_G_SPEED error", ETH_SPEED_10M);
return speed;
}
bool EthernetComponent::powerdown() { bool EthernetComponent::powerdown() {
ESP_LOGI(TAG, "Powering down ethernet PHY"); ESP_LOGI(TAG, "Powering down ethernet PHY");
if (this->phy_ == nullptr) { if (this->phy_ == nullptr) {

View file

@ -74,6 +74,10 @@ class EthernetComponent : public Component {
network::IPAddress get_dns_address(uint8_t num); network::IPAddress get_dns_address(uint8_t num);
std::string get_use_address() const; std::string get_use_address() const;
void set_use_address(const std::string &use_address); void set_use_address(const std::string &use_address);
void get_eth_mac_address_raw(uint8_t *mac);
std::string get_eth_mac_address_pretty();
eth_duplex_t get_duplex_mode();
eth_speed_t get_link_speed();
bool powerdown(); bool powerdown();
protected: protected:

View file

@ -10,6 +10,7 @@ static const char *const TAG = "ethernet_info";
void IPAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo IPAddress", this); } void IPAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo IPAddress", this); }
void DNSAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo DNS Address", this); } void DNSAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo DNS Address", this); }
void MACAddressEthernetInfo::dump_config() { LOG_TEXT_SENSOR("", "EthernetInfo MAC Address", this); }
} // namespace ethernet_info } // namespace ethernet_info
} // namespace esphome } // namespace esphome

View file

@ -59,6 +59,13 @@ class DNSAddressEthernetInfo : public PollingComponent, public text_sensor::Text
std::string last_results_; std::string last_results_;
}; };
class MACAddressEthernetInfo : public Component, public text_sensor::TextSensor {
public:
void setup() override { this->publish_state(ethernet::global_eth_component->get_eth_mac_address_pretty()); }
std::string unique_id() override { return get_mac_address() + "-ethernetinfo-mac"; }
void dump_config() override;
};
} // namespace ethernet_info } // namespace ethernet_info
} // namespace esphome } // namespace esphome

View file

@ -4,6 +4,7 @@ from esphome.components import text_sensor
from esphome.const import ( from esphome.const import (
CONF_IP_ADDRESS, CONF_IP_ADDRESS,
CONF_DNS_ADDRESS, CONF_DNS_ADDRESS,
CONF_MAC_ADDRESS,
ENTITY_CATEGORY_DIAGNOSTIC, ENTITY_CATEGORY_DIAGNOSTIC,
) )
@ -19,6 +20,10 @@ DNSAddressEthernetInfo = ethernet_info_ns.class_(
"DNSAddressEthernetInfo", text_sensor.TextSensor, cg.PollingComponent "DNSAddressEthernetInfo", text_sensor.TextSensor, cg.PollingComponent
) )
MACAddressEthernetInfo = ethernet_info_ns.class_(
"MACAddressEthernetInfo", text_sensor.TextSensor, cg.PollingComponent
)
CONFIG_SCHEMA = cv.Schema( CONFIG_SCHEMA = cv.Schema(
{ {
cv.Optional(CONF_IP_ADDRESS): text_sensor.text_sensor_schema( cv.Optional(CONF_IP_ADDRESS): text_sensor.text_sensor_schema(
@ -36,6 +41,9 @@ CONFIG_SCHEMA = cv.Schema(
cv.Optional(CONF_DNS_ADDRESS): text_sensor.text_sensor_schema( cv.Optional(CONF_DNS_ADDRESS): text_sensor.text_sensor_schema(
DNSAddressEthernetInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC DNSAddressEthernetInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC
).extend(cv.polling_component_schema("1s")), ).extend(cv.polling_component_schema("1s")),
cv.Optional(CONF_MAC_ADDRESS): text_sensor.text_sensor_schema(
MACAddressEthernetInfo, entity_category=ENTITY_CATEGORY_DIAGNOSTIC
),
} }
) )
@ -51,3 +59,6 @@ async def to_code(config):
if conf := config.get(CONF_DNS_ADDRESS): if conf := config.get(CONF_DNS_ADDRESS):
dns_info = await text_sensor.new_text_sensor(config[CONF_DNS_ADDRESS]) dns_info = await text_sensor.new_text_sensor(config[CONF_DNS_ADDRESS])
await cg.register_component(dns_info, config[CONF_DNS_ADDRESS]) await cg.register_component(dns_info, config[CONF_DNS_ADDRESS])
if conf := config.get(CONF_MAC_ADDRESS):
mac_info = await text_sensor.new_text_sensor(config[CONF_MAC_ADDRESS])
await cg.register_component(mac_info, config[CONF_MAC_ADDRESS])

View file

@ -16,7 +16,7 @@ from .const import KEY_HOST
# force import gpio to register pin schema # force import gpio to register pin schema
from .gpio import host_pin_to_code # noqa from .gpio import host_pin_to_code # noqa
CODEOWNERS = ["@esphome/core"] CODEOWNERS = ["@esphome/core", "@clydebarrow"]
AUTO_LOAD = ["network"] AUTO_LOAD = ["network"]

View file

@ -0,0 +1,20 @@
import esphome.codegen as cg
from esphome.const import CONF_ID
import esphome.config_validation as cv
from esphome.components import time as time_
CODEOWNERS = ["@clydebarrow"]
time_ns = cg.esphome_ns.namespace("host")
HostTime = time_ns.class_("HostTime", time_.RealTimeClock)
CONFIG_SCHEMA = time_.TIME_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(HostTime),
}
).extend(cv.COMPONENT_SCHEMA)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await time_.register_time(var, config)

View file

@ -0,0 +1,15 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/time/real_time_clock.h"
namespace esphome {
namespace host {
class HostTime : public time::RealTimeClock {
public:
void update() override {}
};
} // namespace host
} // namespace esphome

View file

@ -109,6 +109,7 @@ void ImprovSerialComponent::write_data_(std::vector<uint8_t> &data) {
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3)
case logger::UART_SELECTION_USB_SERIAL_JTAG: case logger::UART_SELECTION_USB_SERIAL_JTAG:
usb_serial_jtag_write_bytes((char *) data.data(), data.size(), 20 / portTICK_PERIOD_MS); usb_serial_jtag_write_bytes((char *) data.data(), data.size(), 20 / portTICK_PERIOD_MS);
usb_serial_jtag_ll_txfifo_flush(); // fixes for issue in IDF 4.4.7
break; break;
#endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32S3 #endif // USE_ESP32_VARIANT_ESP32C3 || USE_ESP32_VARIANT_ESP32S3
default: default:

View file

@ -17,6 +17,7 @@
#if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \ #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S3) || \
defined(USE_ESP32_VARIANT_ESP32H2) defined(USE_ESP32_VARIANT_ESP32H2)
#include <driver/usb_serial_jtag.h> #include <driver/usb_serial_jtag.h>
#include <hal/usb_serial_jtag_ll.h>
#endif #endif
#if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) #if defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3)
#include <esp_private/usb_console.h> #include <esp_private/usb_console.h>

View file

@ -20,7 +20,6 @@ namespace sntp {
static const char *const TAG = "sntp"; static const char *const TAG = "sntp";
void SNTPComponent::setup() { void SNTPComponent::setup() {
#ifndef USE_HOST
ESP_LOGCONFIG(TAG, "Setting up SNTP..."); ESP_LOGCONFIG(TAG, "Setting up SNTP...");
#if defined(USE_ESP_IDF) #if defined(USE_ESP_IDF)
if (esp_sntp_enabled()) { if (esp_sntp_enabled()) {
@ -44,7 +43,6 @@ void SNTPComponent::setup() {
#endif #endif
sntp_init(); sntp_init();
#endif
} }
void SNTPComponent::dump_config() { void SNTPComponent::dump_config() {
ESP_LOGCONFIG(TAG, "SNTP Time:"); ESP_LOGCONFIG(TAG, "SNTP Time:");
@ -54,7 +52,7 @@ void SNTPComponent::dump_config() {
ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str()); ESP_LOGCONFIG(TAG, " Timezone: '%s'", this->timezone_.c_str());
} }
void SNTPComponent::update() { void SNTPComponent::update() {
#if !defined(USE_ESP_IDF) && !defined(USE_HOST) #if !defined(USE_ESP_IDF)
// force resync // force resync
if (sntp_enabled()) { if (sntp_enabled()) {
sntp_stop(); sntp_stop();

View file

@ -2,24 +2,41 @@ from esphome.components import time as time_
import esphome.config_validation as cv import esphome.config_validation as cv
import esphome.codegen as cg import esphome.codegen as cg
from esphome.core import CORE from esphome.core import CORE
from esphome.const import CONF_ID, CONF_SERVERS from esphome.const import (
CONF_ID,
CONF_SERVERS,
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_RP2040,
PLATFORM_RTL87XX,
PLATFORM_BK72XX,
)
DEPENDENCIES = ["network"] DEPENDENCIES = ["network"]
sntp_ns = cg.esphome_ns.namespace("sntp") sntp_ns = cg.esphome_ns.namespace("sntp")
SNTPComponent = sntp_ns.class_("SNTPComponent", time_.RealTimeClock) SNTPComponent = sntp_ns.class_("SNTPComponent", time_.RealTimeClock)
DEFAULT_SERVERS = ["0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org"] DEFAULT_SERVERS = ["0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org"]
CONFIG_SCHEMA = time_.TIME_SCHEMA.extend( CONFIG_SCHEMA = cv.All(
{ time_.TIME_SCHEMA.extend(
cv.GenerateID(): cv.declare_id(SNTPComponent), {
cv.Optional(CONF_SERVERS, default=DEFAULT_SERVERS): cv.All( cv.GenerateID(): cv.declare_id(SNTPComponent),
cv.ensure_list(cv.Any(cv.domain, cv.hostname)), cv.Length(min=1, max=3) cv.Optional(CONF_SERVERS, default=DEFAULT_SERVERS): cv.All(
), cv.ensure_list(cv.Any(cv.domain, cv.hostname)), cv.Length(min=1, max=3)
} ),
).extend(cv.COMPONENT_SCHEMA) }
).extend(cv.COMPONENT_SCHEMA),
cv.only_on(
[
PLATFORM_ESP32,
PLATFORM_ESP8266,
PLATFORM_RP2040,
PLATFORM_BK72XX,
PLATFORM_RTL87XX,
]
),
)
async def to_code(config): async def to_code(config):

View file

@ -7,7 +7,10 @@ from esphome.const import (
CONF_TIME_ID, CONF_TIME_ID,
CONF_ADDRESS, CONF_ADDRESS,
CONF_REBOOT_TIMEOUT, CONF_REBOOT_TIMEOUT,
KEY_CORE,
KEY_FRAMEWORK_VERSION,
) )
from esphome.components.esp32 import CORE, add_idf_sdkconfig_option
from esphome.components import time from esphome.components import time
from esphome.core import TimePeriod from esphome.core import TimePeriod
from esphome import automation from esphome import automation
@ -117,6 +120,13 @@ async def to_code(config):
if config[CONF_REQUIRE_CONNECTION_TO_PROCEED]: if config[CONF_REQUIRE_CONNECTION_TO_PROCEED]:
cg.add(var.disable_auto_proceed()) cg.add(var.disable_auto_proceed())
# Workaround for crash on IDF 5+
# See https://github.com/trombik/esp_wireguard/issues/33#issuecomment-1568503651
if CORE.using_esp_idf and CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION] >= cv.Version(
5, 0, 0
):
add_idf_sdkconfig_option("CONFIG_LWIP_PPP_SUPPORT", True)
# This flag is added here because the esp_wireguard library statically # This flag is added here because the esp_wireguard library statically
# set the size of its allowed_ips list at compile time using this value; # set the size of its allowed_ips list at compile time using this value;
# the '+1' modifier is relative to the device's own address that will # the '+1' modifier is relative to the device's own address that will

View file

@ -13,11 +13,6 @@ if [ ! -n "$DEVCONTAINER" ] && [ ! -n "$VIRTUAL_ENV" ] && [ ! "$ESPHOME_NO_VENV"
source $location source $location
fi fi
# Avoid unsafe git error when running inside devcontainer
if [ -n "$DEVCONTAINER" ]; then
git config --global --add safe.directory "$PWD"
fi
pip3 install -r requirements.txt -r requirements_optional.txt -r requirements_test.txt -r requirements_dev.txt pip3 install -r requirements.txt -r requirements_optional.txt -r requirements_test.txt -r requirements_dev.txt
pip3 install setuptools wheel pip3 install setuptools wheel
pip3 install -e ".[dev,test,displays]" --config-settings editable_mode=compat pip3 install -e ".[dev,test,displays]" --config-settings editable_mode=compat

View file

@ -17,3 +17,5 @@ text_sensor:
name: IP Address name: IP Address
dns_address: dns_address:
name: DNS Address name: DNS Address
mac_address:
name: MAC Address

View file

@ -1,15 +1,10 @@
time: time:
- platform: sntp - platform: host
id: esptime id: esptime
timezone: Australia/Sydney timezone: Australia/Sydney
logger: logger:
level: VERBOSE level: VERBOSE
logs:
lvgl: INFO
display: DEBUG
sensor: INFO
vnc: DEBUG
host: host:
mac_address: "62:23:45:AF:B3:DD" mac_address: "62:23:45:AF:B3:DD"

View file

@ -0,0 +1 @@
<<: !include common.yaml