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

This commit is contained in:
J. Nick Koston
2026-02-22 21:46:44 -06:00
7 changed files with 38 additions and 40 deletions

View File

@@ -9,6 +9,7 @@ from esphome.const import (
CONF_DATA,
CONF_FREQUENCY,
CONF_ID,
CONF_OUTPUT_POWER,
CONF_VALUE,
CONF_WAIT_TIME,
)
@@ -22,7 +23,6 @@ ns = cg.esphome_ns.namespace("cc1101")
CC1101Component = ns.class_("CC1101Component", cg.Component, spi.SPIDevice)
# Config keys
CONF_OUTPUT_POWER = "output_power"
CONF_RX_ATTENUATION = "rx_attenuation"
CONF_DC_BLOCKING_FILTER = "dc_blocking_filter"
CONF_IF_FREQUENCY = "if_frequency"

View File

@@ -35,9 +35,9 @@ void OpenThreadComponent::dump_config() {
#elif CONFIG_OPENTHREAD_MTD
ESP_LOGCONFIG(TAG, " Device Type: MTD");
// TBD: Synchronized Sleepy End Device
if (this->poll_period > 0) {
if (this->poll_period_ > 0) {
ESP_LOGCONFIG(TAG, " Device is configured as Sleepy End Device (SED)");
uint32_t duration = this->poll_period / 1000;
uint32_t duration = this->poll_period_ / 1000;
ESP_LOGCONFIG(TAG, " Poll Period: %" PRIu32 "s", duration);
} else {
ESP_LOGCONFIG(TAG, " Device is configured as Minimal End Device (MED)");

View File

@@ -36,22 +36,22 @@ class OpenThreadComponent : public Component {
const char *get_use_address() const;
void set_use_address(const char *use_address);
#if CONFIG_OPENTHREAD_MTD
void set_poll_period(uint32_t poll_period) { this->poll_period = poll_period; }
void set_poll_period(uint32_t poll_period) { this->poll_period_ = poll_period; }
#endif
protected:
std::optional<otIp6Address> get_omr_address_(InstanceLock &lock);
std::function<void()> factory_reset_external_callback_;
#if CONFIG_OPENTHREAD_MTD
uint32_t poll_period_{0};
#endif
bool teardown_started_{false};
bool teardown_complete_{false};
std::function<void()> factory_reset_external_callback_;
private:
// Stores a pointer to a string literal (static storage duration).
// ONLY set from Python-generated code with string literals - never dynamic strings.
const char *use_address_{""};
#if CONFIG_OPENTHREAD_MTD
uint32_t poll_period{0};
#endif
};
extern OpenThreadComponent *global_openthread_component; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

View File

@@ -81,9 +81,11 @@ void OpenThreadComponent::ot_main() {
// Initialize the OpenThread stack
// otLoggingSetLevel(OT_LOG_LEVEL_DEBG);
ESP_ERROR_CHECK(esp_openthread_init(&config));
// Fetch OT instance once to avoid repeated call into OT stack
otInstance *instance = esp_openthread_get_instance();
#if CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE
ESP_ERROR_CHECK(esp_openthread_state_indicator_init(esp_openthread_get_instance()));
ESP_ERROR_CHECK(esp_openthread_state_indicator_init(instance));
#endif
#if CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC
@@ -104,34 +106,37 @@ void OpenThreadComponent::ot_main() {
esp_cli_custom_command_init();
#endif // CONFIG_OPENTHREAD_CLI_ESP_EXTENSION
ESP_LOGD(TAG, "Thread Version: %" PRIu16, otThreadGetVersion());
otLinkModeConfig link_mode_config{};
#if CONFIG_OPENTHREAD_FTD
link_mode_config.mRxOnWhenIdle = true;
link_mode_config.mDeviceType = true;
link_mode_config.mNetworkData = true;
#elif CONFIG_OPENTHREAD_MTD
if (this->poll_period > 0) {
if (otLinkSetPollPeriod(esp_openthread_get_instance(), this->poll_period) != OT_ERROR_NONE) {
ESP_LOGE(TAG, "Failed to set OpenThread pollperiod.");
if (this->poll_period_ > 0) {
if (otLinkSetPollPeriod(instance, this->poll_period_) != OT_ERROR_NONE) {
ESP_LOGE(TAG, "Failed to set pollperiod");
}
uint32_t link_polling_period = otLinkGetPollPeriod(esp_openthread_get_instance());
ESP_LOGD(TAG, "Link Polling Period: %" PRIu32, link_polling_period);
ESP_LOGD(TAG, "Link Polling Period: %" PRIu32, otLinkGetPollPeriod(instance));
}
link_mode_config.mRxOnWhenIdle = this->poll_period == 0;
link_mode_config.mRxOnWhenIdle = this->poll_period_ == 0;
link_mode_config.mDeviceType = false;
link_mode_config.mNetworkData = false;
#endif
if (otThreadSetLinkMode(esp_openthread_get_instance(), link_mode_config) != OT_ERROR_NONE) {
ESP_LOGE(TAG, "Failed to set OpenThread linkmode.");
if (otThreadSetLinkMode(instance, link_mode_config) != OT_ERROR_NONE) {
ESP_LOGE(TAG, "Failed to set linkmode");
}
link_mode_config = otThreadGetLinkMode(esp_openthread_get_instance());
#ifdef ESPHOME_LOG_HAS_DEBUG // Fetch link mode from OT only when DEBUG
link_mode_config = otThreadGetLinkMode(instance);
ESP_LOGD(TAG,
"Link Mode Device Type: %s\n"
"Link Mode Network Data: %s\n"
"Link Mode RX On When Idle: %s",
link_mode_config.mDeviceType ? "true" : "false", link_mode_config.mNetworkData ? "true" : "false",
link_mode_config.mRxOnWhenIdle ? "true" : "false");
TRUEFALSE(link_mode_config.mDeviceType), TRUEFALSE(link_mode_config.mNetworkData),
TRUEFALSE(link_mode_config.mRxOnWhenIdle));
#endif
// Run the main loop
#if CONFIG_OPENTHREAD_CLI
@@ -142,7 +147,7 @@ void OpenThreadComponent::ot_main() {
#ifndef USE_OPENTHREAD_FORCE_DATASET
// Check if openthread has a valid dataset from a previous execution
otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset);
otError error = otDatasetGetActiveTlvs(instance, &dataset);
if (error != OT_ERROR_NONE) {
// Make sure the length is 0 so we fallback to the configuration
dataset.mLength = 0;

View File

@@ -25,7 +25,7 @@ class OpenThreadInstancePollingComponent : public PollingComponent {
virtual void update_instance(otInstance *instance) = 0;
};
class IPAddressOpenThreadInfo : public PollingComponent, public text_sensor::TextSensor {
class IPAddressOpenThreadInfo final : public PollingComponent, public text_sensor::TextSensor {
public:
void update() override {
std::optional<otIp6Address> address = openthread::global_openthread_component->get_omr_address();
@@ -48,7 +48,7 @@ class IPAddressOpenThreadInfo : public PollingComponent, public text_sensor::Tex
std::string last_ip_;
};
class RoleOpenThreadInfo : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
class RoleOpenThreadInfo final : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
public:
void update_instance(otInstance *instance) override {
otDeviceRole role = otThreadGetDeviceRole(instance);
@@ -64,7 +64,7 @@ class RoleOpenThreadInfo : public OpenThreadInstancePollingComponent, public tex
otDeviceRole last_role_;
};
class Rloc16OpenThreadInfo : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
class Rloc16OpenThreadInfo final : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
public:
void update_instance(otInstance *instance) override {
uint16_t rloc16 = otThreadGetRloc16(instance);
@@ -75,14 +75,13 @@ class Rloc16OpenThreadInfo : public OpenThreadInstancePollingComponent, public t
this->publish_state(buf);
}
}
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
void dump_config() override;
protected:
uint16_t last_rloc16_;
};
class ExtAddrOpenThreadInfo : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
class ExtAddrOpenThreadInfo final : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
public:
void update_instance(otInstance *instance) override {
const auto *extaddr = otLinkGetExtendedAddress(instance);
@@ -93,14 +92,13 @@ class ExtAddrOpenThreadInfo : public OpenThreadInstancePollingComponent, public
this->publish_state(buf);
}
}
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
void dump_config() override;
protected:
std::array<uint8_t, 8> last_extaddr_{};
};
class Eui64OpenThreadInfo : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
class Eui64OpenThreadInfo final : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
public:
void update_instance(otInstance *instance) override {
otExtAddress addr;
@@ -113,14 +111,13 @@ class Eui64OpenThreadInfo : public OpenThreadInstancePollingComponent, public te
this->publish_state(buf);
}
}
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
void dump_config() override;
protected:
std::array<uint8_t, 8> last_eui64_{};
};
class ChannelOpenThreadInfo : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
class ChannelOpenThreadInfo final : public OpenThreadInstancePollingComponent, public text_sensor::TextSensor {
public:
void update_instance(otInstance *instance) override {
uint8_t channel = otLinkGetChannel(instance);
@@ -131,7 +128,6 @@ class ChannelOpenThreadInfo : public OpenThreadInstancePollingComponent, public
this->publish_state(buf);
}
}
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
void dump_config() override;
protected:
@@ -153,7 +149,7 @@ class DatasetOpenThreadInfo : public OpenThreadInstancePollingComponent {
virtual void update_dataset(otOperationalDataset *dataset) = 0;
};
class NetworkNameOpenThreadInfo : public DatasetOpenThreadInfo, public text_sensor::TextSensor {
class NetworkNameOpenThreadInfo final : public DatasetOpenThreadInfo, public text_sensor::TextSensor {
public:
void update_dataset(otOperationalDataset *dataset) override {
if (this->last_network_name_ != dataset->mNetworkName.m8) {
@@ -161,14 +157,13 @@ class NetworkNameOpenThreadInfo : public DatasetOpenThreadInfo, public text_sens
this->publish_state(this->last_network_name_);
}
}
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
void dump_config() override;
protected:
std::string last_network_name_;
};
class NetworkKeyOpenThreadInfo : public DatasetOpenThreadInfo, public text_sensor::TextSensor {
class NetworkKeyOpenThreadInfo final : public DatasetOpenThreadInfo, public text_sensor::TextSensor {
public:
void update_dataset(otOperationalDataset *dataset) override {
if (!std::equal(this->last_key_.begin(), this->last_key_.end(), dataset->mNetworkKey.m8)) {
@@ -178,14 +173,13 @@ class NetworkKeyOpenThreadInfo : public DatasetOpenThreadInfo, public text_senso
this->publish_state(buf);
}
}
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
void dump_config() override;
protected:
std::array<uint8_t, 16> last_key_{};
};
class PanIdOpenThreadInfo : public DatasetOpenThreadInfo, public text_sensor::TextSensor {
class PanIdOpenThreadInfo final : public DatasetOpenThreadInfo, public text_sensor::TextSensor {
public:
void update_dataset(otOperationalDataset *dataset) override {
uint16_t panid = dataset->mPanId;
@@ -196,14 +190,13 @@ class PanIdOpenThreadInfo : public DatasetOpenThreadInfo, public text_sensor::Te
this->publish_state(buf);
}
}
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
void dump_config() override;
protected:
uint16_t last_panid_;
};
class ExtPanIdOpenThreadInfo : public DatasetOpenThreadInfo, public text_sensor::TextSensor {
class ExtPanIdOpenThreadInfo final : public DatasetOpenThreadInfo, public text_sensor::TextSensor {
public:
void update_dataset(otOperationalDataset *dataset) override {
if (!std::equal(this->last_extpanid_.begin(), this->last_extpanid_.end(), dataset->mExtendedPanId.m8)) {
@@ -214,7 +207,6 @@ class ExtPanIdOpenThreadInfo : public DatasetOpenThreadInfo, public text_sensor:
}
}
float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
void dump_config() override;
protected:

View File

@@ -42,6 +42,7 @@ from esphome.const import (
CONF_ON_CONNECT,
CONF_ON_DISCONNECT,
CONF_ON_ERROR,
CONF_OUTPUT_POWER,
CONF_PASSWORD,
CONF_POWER_SAVE_MODE,
CONF_PRIORITY,
@@ -344,7 +345,6 @@ def _validate(config):
return config
CONF_OUTPUT_POWER = "output_power"
CONF_PASSIVE_SCAN = "passive_scan"
CONFIG_SCHEMA = cv.All(
cv.Schema(

View File

@@ -748,6 +748,7 @@ CONF_OTA = "ota"
CONF_OUTDOOR_TEMPERATURE = "outdoor_temperature"
CONF_OUTPUT = "output"
CONF_OUTPUT_ID = "output_id"
CONF_OUTPUT_POWER = "output_power"
CONF_OUTPUT_SPEAKER = "output_speaker"
CONF_OUTPUTS = "outputs"
CONF_OVERSAMPLING = "oversampling"