diff --git a/esphome/components/openthread/__init__.py b/esphome/components/openthread/__init__.py index ac5b9c24b8..9919f93a59 100644 --- a/esphome/components/openthread/__init__.py +++ b/esphome/components/openthread/__init__.py @@ -21,6 +21,7 @@ CONF_PANID = "panid" CONF_EXTPANID = "extpanid" CONF_MDNS_ID = "mdns_id" CONF_SRP_ID = "srp_id" +CONF_FORCE_DATASET = "force_dataset" def set_sdkconfig_options(config): @@ -79,6 +80,7 @@ CONFIG_SCHEMA = cv.All( cv.Optional(CONF_EXTPANID): cv.string_strict, cv.Optional(CONF_NETWORK_NAME): cv.string_strict, cv.Optional(CONF_PSKC): cv.string_strict, + cv.Optional(CONF_FORCE_DATASET): cv.boolean, } ), ) diff --git a/esphome/components/openthread/openthread_esp.cpp b/esphome/components/openthread/openthread_esp.cpp index 6f79299818..f7601c69f5 100644 --- a/esphome/components/openthread/openthread_esp.cpp +++ b/esphome/components/openthread/openthread_esp.cpp @@ -114,9 +114,13 @@ void OpenThreadComponent::ot_main() { #endif ESP_LOGI(TAG, "Activating dataset..."); otOperationalDatasetTlvs dataset; + +#ifdef CONFIG_OPENTHREAD_FORCE_DATASET + ESP_ERROR_CHECK(esp_openthread_auto_start(NULL)); +#else otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset); ESP_ERROR_CHECK(esp_openthread_auto_start((error == OT_ERROR_NONE) ? &dataset : NULL)); - +#endif esp_openthread_launch_mainloop(); // Clean up diff --git a/tests/components/openthread/test-ot.yaml b/tests/components/openthread/test-ot.yaml index 80a4110abb..483367516f 100644 --- a/tests/components/openthread/test-ot.yaml +++ b/tests/components/openthread/test-ot.yaml @@ -22,6 +22,7 @@ openthread: panid: 0x8f28 extpanid: d63e8e3e495ebbc3 pskc: c23a76e98f1a6483639b1ac1271e2e27 + force_dataset: true text_sensor: - platform: openthread_info