Merge branch 'integration' into memory_api

This commit is contained in:
J. Nick Koston
2025-11-05 11:27:55 -06:00
32 changed files with 54 additions and 40 deletions

View File

@@ -37,8 +37,6 @@ MDNS_STATIC_CONST_CHAR(SERVICE_TCP, "_tcp");
MDNS_STATIC_CONST_CHAR(VALUE_VERSION, ESPHOME_VERSION);
void MDNSComponent::compile_records_(StaticVector<MDNSService, MDNS_SERVICE_COUNT> &services) {
this->hostname_ = App.get_name();
// IMPORTANT: The #ifdef blocks below must match COMPONENTS_WITH_MDNS_SERVICES
// in mdns/__init__.py. If you add a new service here, update both locations.
@@ -179,7 +177,7 @@ void MDNSComponent::dump_config() {
ESP_LOGCONFIG(TAG,
"mDNS:\n"
" Hostname: %s",
this->hostname_.c_str());
App.get_name().c_str());
#ifdef USE_MDNS_STORE_SERVICES
ESP_LOGV(TAG, " Services:");
for (const auto &service : this->services_) {

View File

@@ -76,7 +76,6 @@ class MDNSComponent : public Component {
#ifdef USE_MDNS_STORE_SERVICES
StaticVector<MDNSService, MDNS_SERVICE_COUNT> services_{};
#endif
std::string hostname_;
void compile_records_(StaticVector<MDNSService, MDNS_SERVICE_COUNT> &services);
};

View File

@@ -2,6 +2,7 @@
#if defined(USE_ESP32) && defined(USE_MDNS)
#include <mdns.h>
#include "esphome/core/application.h"
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
#include "mdns_component.h"
@@ -27,8 +28,9 @@ void MDNSComponent::setup() {
return;
}
mdns_hostname_set(this->hostname_.c_str());
mdns_instance_name_set(this->hostname_.c_str());
const char *hostname = App.get_name().c_str();
mdns_hostname_set(hostname);
mdns_instance_name_set(hostname);
for (const auto &service : services) {
auto txt_records = std::make_unique<mdns_txt_item_t[]>(service.txt_records.size());

View File

@@ -4,6 +4,7 @@
#include <ESP8266mDNS.h>
#include "esphome/components/network/ip_address.h"
#include "esphome/components/network/util.h"
#include "esphome/core/application.h"
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
#include "mdns_component.h"
@@ -20,7 +21,7 @@ void MDNSComponent::setup() {
this->compile_records_(services);
#endif
MDNS.begin(this->hostname_.c_str());
MDNS.begin(App.get_name().c_str());
for (const auto &service : services) {
// Strip the leading underscore from the proto and service_type. While it is

View File

@@ -3,6 +3,7 @@
#include "esphome/components/network/ip_address.h"
#include "esphome/components/network/util.h"
#include "esphome/core/application.h"
#include "esphome/core/log.h"
#include "mdns_component.h"
@@ -20,7 +21,7 @@ void MDNSComponent::setup() {
this->compile_records_(services);
#endif
MDNS.begin(this->hostname_.c_str());
MDNS.begin(App.get_name().c_str());
for (const auto &service : services) {
// Strip the leading underscore from the proto and service_type. While it is

View File

@@ -3,6 +3,7 @@
#include "esphome/components/network/ip_address.h"
#include "esphome/components/network/util.h"
#include "esphome/core/application.h"
#include "esphome/core/log.h"
#include "mdns_component.h"
@@ -20,7 +21,7 @@ void MDNSComponent::setup() {
this->compile_records_(services);
#endif
MDNS.begin(this->hostname_.c_str());
MDNS.begin(App.get_name().c_str());
for (const auto &service : services) {
// Strip the leading underscore from the proto and service_type. While it is

View File

@@ -30,10 +30,11 @@ MQTTBinarySensorComponent::MQTTBinarySensorComponent(binary_sensor::BinarySensor
}
void MQTTBinarySensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
const auto device_class = this->binary_sensor_->get_device_class_ref();
if (!device_class.empty())
if (!device_class.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_DEVICE_CLASS] = device_class;
}
if (this->binary_sensor_->is_status_binary_sensor())
root[MQTT_PAYLOAD_ON] = mqtt::global_mqtt_client->get_availability().payload_available;
if (this->binary_sensor_->is_status_binary_sensor())

View File

@@ -90,8 +90,10 @@ bool MQTTComponent::send_discovery_() {
if (this->is_disabled_by_default_())
root[MQTT_ENABLED_BY_DEFAULT] = false;
const auto icon_ref = this->get_icon_ref_();
if (!icon_ref.empty())
if (!icon_ref.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_ICON] = icon_ref;
}
const auto entity_category = this->get_entity()->get_entity_category();
switch (entity_category) {

View File

@@ -67,10 +67,11 @@ void MQTTCoverComponent::dump_config() {
}
}
void MQTTCoverComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
const auto device_class = this->cover_->get_device_class_ref();
if (!device_class.empty())
if (!device_class.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_DEVICE_CLASS] = device_class;
}
auto traits = this->cover_->get_traits();
if (traits.get_is_assumed_state()) {

View File

@@ -22,8 +22,10 @@ void MQTTEventComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConf
event_types.add(event_type);
const auto device_class = this->event_->get_device_class_ref();
if (!device_class.empty())
if (!device_class.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_DEVICE_CLASS] = device_class;
}
config.command_topic = false;
}

View File

@@ -45,8 +45,10 @@ void MQTTNumberComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCon
root[MQTT_MAX] = traits.get_max_value();
root[MQTT_STEP] = traits.get_step();
const auto unit_of_measurement = this->number_->traits.get_unit_of_measurement_ref();
if (!unit_of_measurement.empty())
if (!unit_of_measurement.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_UNIT_OF_MEASUREMENT] = unit_of_measurement;
}
switch (this->number_->traits.get_mode()) {
case NUMBER_MODE_AUTO:
break;
@@ -58,8 +60,10 @@ void MQTTNumberComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryCon
break;
}
const auto device_class = this->number_->traits.get_device_class_ref();
if (!device_class.empty())
if (!device_class.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_DEVICE_CLASS] = device_class;
}
config.command_topic = true;
}

View File

@@ -44,15 +44,17 @@ void MQTTSensorComponent::set_expire_after(uint32_t expire_after) { this->expire
void MQTTSensorComponent::disable_expire_after() { this->expire_after_ = 0; }
void MQTTSensorComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
const auto device_class = this->sensor_->get_device_class_ref();
if (!device_class.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_DEVICE_CLASS] = device_class;
}
const auto unit_of_measurement = this->sensor_->get_unit_of_measurement_ref();
if (!unit_of_measurement.empty())
if (!unit_of_measurement.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_UNIT_OF_MEASUREMENT] = unit_of_measurement;
}
if (this->get_expire_after() > 0)
root[MQTT_EXPIRE_AFTER] = this->get_expire_after() / 1000;

View File

@@ -15,9 +15,9 @@ using namespace esphome::text_sensor;
MQTTTextSensor::MQTTTextSensor(TextSensor *sensor) : sensor_(sensor) {}
void MQTTTextSensor::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
const auto device_class = this->sensor_->get_device_class_ref();
if (!device_class.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_DEVICE_CLASS] = device_class;
}
config.command_topic = false;

View File

@@ -49,9 +49,9 @@ void MQTTValveComponent::dump_config() {
}
}
void MQTTValveComponent::send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
const auto device_class = this->valve_->get_device_class_ref();
if (!device_class.empty()) {
// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) false positive with ArduinoJson
root[MQTT_DEVICE_CLASS] = device_class;
}

View File

@@ -49,7 +49,7 @@ struct SensorInfo {
uint8_t store_index;
};
class TemplateAlarmControlPanel : public alarm_control_panel::AlarmControlPanel, public Component {
class TemplateAlarmControlPanel final : public alarm_control_panel::AlarmControlPanel, public Component {
public:
TemplateAlarmControlPanel();
void dump_config() override;

View File

@@ -7,7 +7,7 @@
namespace esphome {
namespace template_ {
class TemplateBinarySensor : public Component, public binary_sensor::BinarySensor {
class TemplateBinarySensor final : public Component, public binary_sensor::BinarySensor {
public:
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }

View File

@@ -5,7 +5,7 @@
namespace esphome {
namespace template_ {
class TemplateButton : public button::Button {
class TemplateButton final : public button::Button {
public:
// Implements the abstract `press_action` but the `on_press` trigger already handles the press.
void press_action() override{};

View File

@@ -14,7 +14,7 @@ enum TemplateCoverRestoreMode {
COVER_RESTORE_AND_CALL,
};
class TemplateCover : public cover::Cover, public Component {
class TemplateCover final : public cover::Cover, public Component {
public:
TemplateCover();

View File

@@ -14,7 +14,7 @@
namespace esphome {
namespace template_ {
class TemplateDate : public datetime::DateEntity, public PollingComponent {
class TemplateDate final : public datetime::DateEntity, public PollingComponent {
public:
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }

View File

@@ -14,7 +14,7 @@
namespace esphome {
namespace template_ {
class TemplateDateTime : public datetime::DateTimeEntity, public PollingComponent {
class TemplateDateTime final : public datetime::DateTimeEntity, public PollingComponent {
public:
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }

View File

@@ -14,7 +14,7 @@
namespace esphome {
namespace template_ {
class TemplateTime : public datetime::TimeEntity, public PollingComponent {
class TemplateTime final : public datetime::TimeEntity, public PollingComponent {
public:
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }

View File

@@ -6,7 +6,7 @@
namespace esphome {
namespace template_ {
class TemplateEvent : public Component, public event::Event {};
class TemplateEvent final : public Component, public event::Event {};
} // namespace template_
} // namespace esphome

View File

@@ -6,7 +6,7 @@
namespace esphome {
namespace template_ {
class TemplateFan : public Component, public fan::Fan {
class TemplateFan final : public Component, public fan::Fan {
public:
TemplateFan() {}
void setup() override;

View File

@@ -8,7 +8,7 @@
namespace esphome {
namespace template_ {
class TemplateLock : public lock::Lock, public Component {
class TemplateLock final : public lock::Lock, public Component {
public:
TemplateLock();

View File

@@ -9,7 +9,7 @@
namespace esphome {
namespace template_ {
class TemplateNumber : public number::Number, public PollingComponent {
class TemplateNumber final : public number::Number, public PollingComponent {
public:
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }

View File

@@ -7,7 +7,7 @@
namespace esphome {
namespace template_ {
class TemplateBinaryOutput : public output::BinaryOutput {
class TemplateBinaryOutput final : public output::BinaryOutput {
public:
Trigger<bool> *get_trigger() const { return trigger_; }
@@ -17,7 +17,7 @@ class TemplateBinaryOutput : public output::BinaryOutput {
Trigger<bool> *trigger_ = new Trigger<bool>();
};
class TemplateFloatOutput : public output::FloatOutput {
class TemplateFloatOutput final : public output::FloatOutput {
public:
Trigger<float> *get_trigger() const { return trigger_; }

View File

@@ -9,7 +9,7 @@
namespace esphome {
namespace template_ {
class TemplateSelect : public select::Select, public PollingComponent {
class TemplateSelect final : public select::Select, public PollingComponent {
public:
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }

View File

@@ -7,7 +7,7 @@
namespace esphome {
namespace template_ {
class TemplateSensor : public sensor::Sensor, public PollingComponent {
class TemplateSensor final : public sensor::Sensor, public PollingComponent {
public:
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }

View File

@@ -8,7 +8,7 @@
namespace esphome {
namespace template_ {
class TemplateSwitch : public switch_::Switch, public Component {
class TemplateSwitch final : public switch_::Switch, public Component {
public:
TemplateSwitch();

View File

@@ -60,7 +60,7 @@ template<uint8_t SZ> class TextSaver : public TemplateTextSaverBase {
}
};
class TemplateText : public text::Text, public PollingComponent {
class TemplateText final : public text::Text, public PollingComponent {
public:
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }

View File

@@ -8,7 +8,7 @@
namespace esphome {
namespace template_ {
class TemplateTextSensor : public text_sensor::TextSensor, public PollingComponent {
class TemplateTextSensor final : public text_sensor::TextSensor, public PollingComponent {
public:
template<typename F> void set_template(F &&f) { this->f_.set(std::forward<F>(f)); }

View File

@@ -14,7 +14,7 @@ enum TemplateValveRestoreMode {
VALVE_RESTORE_AND_CALL,
};
class TemplateValve : public valve::Valve, public Component {
class TemplateValve final : public valve::Valve, public Component {
public:
TemplateValve();