Clean-up constant definitions (#2148)

This commit is contained in:
Oxan van Leeuwen 2021-08-23 09:21:30 +02:00 committed by GitHub
parent 8cc3cbb22e
commit 5ec9bb0fb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 77 additions and 56 deletions

View file

@ -745,9 +745,7 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
resp.mac_address = get_mac_address_pretty(); resp.mac_address = get_mac_address_pretty();
resp.esphome_version = ESPHOME_VERSION; resp.esphome_version = ESPHOME_VERSION;
resp.compilation_time = App.get_compilation_time(); resp.compilation_time = App.get_compilation_time();
#ifdef ARDUINO_BOARD resp.model = ESPHOME_BOARD;
resp.model = ARDUINO_BOARD;
#endif
#ifdef USE_DEEP_SLEEP #ifdef USE_DEEP_SLEEP
resp.has_deep_sleep = deep_sleep::global_has_deep_sleep; resp.has_deep_sleep = deep_sleep::global_has_deep_sleep;
#endif #endif

View file

@ -10,7 +10,7 @@ static const char *const TAG = "bme680_bsec.sensor";
static const std::string IAQ_ACCURACY_STATES[4] = {"Stabilizing", "Uncertain", "Calibrating", "Calibrated"}; static const std::string IAQ_ACCURACY_STATES[4] = {"Stabilizing", "Uncertain", "Calibrating", "Calibrated"};
BME680BSECComponent *BME680BSECComponent::instance; BME680BSECComponent *BME680BSECComponent::instance; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
void BME680BSECComponent::setup() { void BME680BSECComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up BME680 via BSEC..."); ESP_LOGCONFIG(TAG, "Setting up BME680 via BSEC...");
@ -359,7 +359,7 @@ void BME680BSECComponent::publish_sensor_state_(sensor::Sensor *sensor, float va
sensor->publish_state(value); sensor->publish_state(value);
} }
void BME680BSECComponent::publish_sensor_state_(text_sensor::TextSensor *sensor, std::string value) { void BME680BSECComponent::publish_sensor_state_(text_sensor::TextSensor *sensor, const std::string &value) {
if (!sensor || (sensor->has_state() && sensor->state == value)) { if (!sensor || (sensor->has_state() && sensor->state == value)) {
return; return;
} }

View file

@ -70,7 +70,7 @@ class BME680BSECComponent : public Component, public i2c::I2CDevice {
int64_t get_time_ns_(); int64_t get_time_ns_();
void publish_sensor_state_(sensor::Sensor *sensor, float value, bool change_only = false); void publish_sensor_state_(sensor::Sensor *sensor, float value, bool change_only = false);
void publish_sensor_state_(text_sensor::TextSensor *sensor, std::string value); void publish_sensor_state_(text_sensor::TextSensor *sensor, const std::string &value);
void load_state_(); void load_state_();
void save_state_(uint8_t accuracy); void save_state_(uint8_t accuracy);

View file

@ -82,11 +82,9 @@ bool BLEServer::create_device_characteristics_() {
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ); this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
model->set_value(this->model_.value()); model->set_value(this->model_.value());
} else { } else {
#ifdef ARDUINO_BOARD
BLECharacteristic *model = BLECharacteristic *model =
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ); this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
model->set_value(ARDUINO_BOARD); model->set_value(ESPHOME_BOARD);
#endif
} }
BLECharacteristic *version = BLECharacteristic *version =

View file

@ -102,9 +102,7 @@ bool MQTTComponent::send_discovery_() {
device_info["identifiers"] = get_mac_address(); device_info["identifiers"] = get_mac_address();
device_info["name"] = node_name; device_info["name"] = node_name;
device_info["sw_version"] = "esphome v" ESPHOME_VERSION " " + App.get_compilation_time(); device_info["sw_version"] = "esphome v" ESPHOME_VERSION " " + App.get_compilation_time();
#ifdef ARDUINO_BOARD device_info["model"] = ESPHOME_BOARD;
device_info["model"] = ARDUINO_BOARD;
#endif
device_info["manufacturer"] = "espressif"; device_info["manufacturer"] = "espressif";
}, },
0, discovery_info.retain); 0, discovery_info.retain);

View file

@ -305,7 +305,7 @@ def wifi_network(config, static_ip):
cg.add(ap.set_password(config[CONF_PASSWORD])) cg.add(ap.set_password(config[CONF_PASSWORD]))
if CONF_EAP in config: if CONF_EAP in config:
cg.add(ap.set_eap(eap_auth(config[CONF_EAP]))) cg.add(ap.set_eap(eap_auth(config[CONF_EAP])))
cg.add_define("ESPHOME_WIFI_WPA2_EAP") cg.add_define("USE_WIFI_WPA2_EAP")
if CONF_BSSID in config: if CONF_BSSID in config:
cg.add(ap.set_bssid([HexInt(i) for i in config[CONF_BSSID].parts])) cg.add(ap.set_bssid([HexInt(i) for i in config[CONF_BSSID].parts]))
if CONF_HIDDEN in config: if CONF_HIDDEN in config:

View file

@ -258,7 +258,7 @@ void WiFiComponent::start_connecting(const WiFiAP &ap, bool two) {
ESP_LOGV(TAG, " BSSID: Not Set"); ESP_LOGV(TAG, " BSSID: Not Set");
} }
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
if (ap.get_eap().has_value()) { if (ap.get_eap().has_value()) {
ESP_LOGV(TAG, " WPA2 Enterprise authentication configured:"); ESP_LOGV(TAG, " WPA2 Enterprise authentication configured:");
EAPAuth eap_config = ap.get_eap().value(); EAPAuth eap_config = ap.get_eap().value();
@ -274,7 +274,7 @@ void WiFiComponent::start_connecting(const WiFiAP &ap, bool two) {
} else { } else {
#endif #endif
ESP_LOGV(TAG, " Password: " LOG_SECRET("'%s'"), ap.get_password().c_str()); ESP_LOGV(TAG, " Password: " LOG_SECRET("'%s'"), ap.get_password().c_str());
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
} }
#endif #endif
if (ap.get_channel().has_value()) { if (ap.get_channel().has_value()) {
@ -478,7 +478,7 @@ void WiFiComponent::check_scanning_finished() {
// copy manual IP (if set) // copy manual IP (if set)
connect_params.set_manual_ip(config.get_manual_ip()); connect_params.set_manual_ip(config.get_manual_ip());
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
// copy EAP parameters (if set) // copy EAP parameters (if set)
connect_params.set_eap(config.get_eap()); connect_params.set_eap(config.get_eap());
#endif #endif
@ -638,8 +638,8 @@ void WiFiAP::set_ssid(const std::string &ssid) { this->ssid_ = ssid; }
void WiFiAP::set_bssid(bssid_t bssid) { this->bssid_ = bssid; } void WiFiAP::set_bssid(bssid_t bssid) { this->bssid_ = bssid; }
void WiFiAP::set_bssid(optional<bssid_t> bssid) { this->bssid_ = bssid; } void WiFiAP::set_bssid(optional<bssid_t> bssid) { this->bssid_ = bssid; }
void WiFiAP::set_password(const std::string &password) { this->password_ = password; } void WiFiAP::set_password(const std::string &password) { this->password_ = password; }
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
void WiFiAP::set_eap(optional<EAPAuth> eap_auth) { this->eap_ = eap_auth; } void WiFiAP::set_eap(optional<EAPAuth> eap_auth) { this->eap_ = std::move(eap_auth); }
#endif #endif
void WiFiAP::set_channel(optional<uint8_t> channel) { this->channel_ = channel; } void WiFiAP::set_channel(optional<uint8_t> channel) { this->channel_ = channel; }
void WiFiAP::set_manual_ip(optional<ManualIP> manual_ip) { this->manual_ip_ = std::move(manual_ip); } void WiFiAP::set_manual_ip(optional<ManualIP> manual_ip) { this->manual_ip_ = std::move(manual_ip); }
@ -647,7 +647,7 @@ void WiFiAP::set_hidden(bool hidden) { this->hidden_ = hidden; }
const std::string &WiFiAP::get_ssid() const { return this->ssid_; } const std::string &WiFiAP::get_ssid() const { return this->ssid_; }
const optional<bssid_t> &WiFiAP::get_bssid() const { return this->bssid_; } const optional<bssid_t> &WiFiAP::get_bssid() const { return this->bssid_; }
const std::string &WiFiAP::get_password() const { return this->password_; } const std::string &WiFiAP::get_password() const { return this->password_; }
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
const optional<EAPAuth> &WiFiAP::get_eap() const { return this->eap_; } const optional<EAPAuth> &WiFiAP::get_eap() const { return this->eap_; }
#endif #endif
const optional<uint8_t> &WiFiAP::get_channel() const { return this->channel_; } const optional<uint8_t> &WiFiAP::get_channel() const { return this->channel_; }
@ -679,7 +679,7 @@ bool WiFiScanResult::matches(const WiFiAP &config) {
if (config.get_bssid().has_value() && *config.get_bssid() != this->bssid_) if (config.get_bssid().has_value() && *config.get_bssid() != this->bssid_)
return false; return false;
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
// BSSID requires auth but no PSK or EAP credentials given // BSSID requires auth but no PSK or EAP credentials given
if (this->with_auth_ && (config.get_password().empty() && !config.get_eap().has_value())) if (this->with_auth_ && (config.get_password().empty() && !config.get_eap().has_value()))
return false; return false;

View file

@ -63,7 +63,7 @@ struct ManualIP {
IPAddress dns2; ///< The second DNS server. 0.0.0.0 for default. IPAddress dns2; ///< The second DNS server. 0.0.0.0 for default.
}; };
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
struct EAPAuth { struct EAPAuth {
std::string identity; // required for all auth types std::string identity; // required for all auth types
std::string username; std::string username;
@ -73,7 +73,7 @@ struct EAPAuth {
const char *client_cert; const char *client_cert;
const char *client_key; const char *client_key;
}; };
#endif // ESPHOME_WIFI_WPA2_EAP #endif // USE_WIFI_WPA2_EAP
using bssid_t = std::array<uint8_t, 6>; using bssid_t = std::array<uint8_t, 6>;
@ -83,9 +83,9 @@ class WiFiAP {
void set_bssid(bssid_t bssid); void set_bssid(bssid_t bssid);
void set_bssid(optional<bssid_t> bssid); void set_bssid(optional<bssid_t> bssid);
void set_password(const std::string &password); void set_password(const std::string &password);
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
void set_eap(optional<EAPAuth> eap_auth); void set_eap(optional<EAPAuth> eap_auth);
#endif // ESPHOME_WIFI_WPA2_EAP #endif // USE_WIFI_WPA2_EAP
void set_channel(optional<uint8_t> channel); void set_channel(optional<uint8_t> channel);
void set_priority(float priority) { priority_ = priority; } void set_priority(float priority) { priority_ = priority; }
void set_manual_ip(optional<ManualIP> manual_ip); void set_manual_ip(optional<ManualIP> manual_ip);
@ -93,9 +93,9 @@ class WiFiAP {
const std::string &get_ssid() const; const std::string &get_ssid() const;
const optional<bssid_t> &get_bssid() const; const optional<bssid_t> &get_bssid() const;
const std::string &get_password() const; const std::string &get_password() const;
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
const optional<EAPAuth> &get_eap() const; const optional<EAPAuth> &get_eap() const;
#endif // ESPHOME_WIFI_WPA2_EAP #endif // USE_WIFI_WPA2_EAP
const optional<uint8_t> &get_channel() const; const optional<uint8_t> &get_channel() const;
float get_priority() const { return priority_; } float get_priority() const { return priority_; }
const optional<ManualIP> &get_manual_ip() const; const optional<ManualIP> &get_manual_ip() const;
@ -105,9 +105,9 @@ class WiFiAP {
std::string ssid_; std::string ssid_;
optional<bssid_t> bssid_; optional<bssid_t> bssid_;
std::string password_; std::string password_;
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
optional<EAPAuth> eap_; optional<EAPAuth> eap_;
#endif // ESPHOME_WIFI_WPA2_EAP #endif // USE_WIFI_WPA2_EAP
optional<uint8_t> channel_; optional<uint8_t> channel_;
float priority_{0}; float priority_{0};
optional<ManualIP> manual_ip_; optional<ManualIP> manual_ip_;

View file

@ -6,7 +6,7 @@
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
#include <esp_wpa2.h> #include <esp_wpa2.h>
#endif #endif
#include "lwip/err.h" #include "lwip/err.h"
@ -163,7 +163,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
conf.sta.threshold.authmode = WIFI_AUTH_WPA_WPA2_PSK; conf.sta.threshold.authmode = WIFI_AUTH_WPA_WPA2_PSK;
} }
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
if (ap.get_eap().has_value()) { if (ap.get_eap().has_value()) {
conf.sta.threshold.authmode = WIFI_AUTH_WPA2_ENTERPRISE; conf.sta.threshold.authmode = WIFI_AUTH_WPA2_ENTERPRISE;
} }
@ -220,7 +220,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
} }
// setup enterprise authentication if required // setup enterprise authentication if required
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
if (ap.get_eap().has_value()) { if (ap.get_eap().has_value()) {
// note: all certificates and keys have to be null terminated. Lengths are appended by +1 to include \0. // note: all certificates and keys have to be null terminated. Lengths are appended by +1 to include \0.
EAPAuth eap = ap.get_eap().value(); EAPAuth eap = ap.get_eap().value();
@ -264,7 +264,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
ESP_LOGV(TAG, "esp_wifi_sta_wpa2_ent_enable failed! %d", err); ESP_LOGV(TAG, "esp_wifi_sta_wpa2_ent_enable failed! %d", err);
} }
} }
#endif // ESPHOME_WIFI_WPA2_EAP #endif // USE_WIFI_WPA2_EAP
this->wifi_apply_hostname_(); this->wifi_apply_hostname_();

View file

@ -7,7 +7,7 @@
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
#include <wpa2_enterprise.h> #include <wpa2_enterprise.h>
#endif #endif
@ -250,7 +250,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
} }
// setup enterprise authentication if required // setup enterprise authentication if required
#ifdef ESPHOME_WIFI_WPA2_EAP #ifdef USE_WIFI_WPA2_EAP
if (ap.get_eap().has_value()) { if (ap.get_eap().has_value()) {
// note: all certificates and keys have to be null terminated. Lengths are appended by +1 to include \0. // note: all certificates and keys have to be null terminated. Lengths are appended by +1 to include \0.
EAPAuth eap = ap.get_eap().value(); EAPAuth eap = ap.get_eap().value();
@ -293,7 +293,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
ESP_LOGV(TAG, "esp_wifi_sta_wpa2_ent_enable failed! %d", ret); ESP_LOGV(TAG, "esp_wifi_sta_wpa2_ent_enable failed! %d", ret);
} }
} }
#endif // ESPHOME_WIFI_WPA2_EAP #endif // USE_WIFI_WPA2_EAP
this->wifi_apply_hostname_(); this->wifi_apply_hostname_();

View file

@ -1,31 +1,52 @@
#pragma once #pragma once
// This file is auto-generated! Do not edit!
// This file is not used by the runtime, instead, a version is generated during
// compilation with only the relevant feature flags for the current build.
//
// This file is only used by static analyzers and IDEs.
// Informative flags
#define ESPHOME_BOARD "dummy_board"
#define ESPHOME_PROJECT_NAME "dummy project"
#define ESPHOME_PROJECT_VERSION "v2"
// Feature flags
#define USE_ADC_SENSOR_VCC
#define USE_API #define USE_API
#define USE_LOGGER
#define USE_BINARY_SENSOR #define USE_BINARY_SENSOR
#define USE_SENSOR #define USE_CAPTIVE_PORTAL
#define USE_SWITCH
#define USE_WIFI
#define USE_STATUS_LED
#define USE_TEXT_SENSOR
#define USE_FAN
#define USE_COVER
#define USE_LIGHT
#define USE_CLIMATE #define USE_CLIMATE
#define USE_NUMBER #define USE_COVER
#define USE_SELECT #define USE_DEEP_SLEEP
#define USE_MQTT #define USE_ESP8266_PREFERENCES_FLASH
#define USE_POWER_SUPPLY #define USE_FAN
#define USE_HOMEASSISTANT_TIME #define USE_HOMEASSISTANT_TIME
#define USE_I2C_MULTIPLEXER
#define USE_JSON #define USE_JSON
#define USE_LIGHT
#define USE_LOGGER
#define USE_MDNS
#define USE_MQTT
#define USE_NUMBER
#define USE_OTA_STATE_CALLBACK
#define USE_POWER_SUPPLY
#define USE_PROMETHEUS
#define USE_SELECT
#define USE_SENSOR
#define USE_STATUS_LED
#define USE_SWITCH
#define USE_TEXT_SENSOR
#define USE_TFT_UPLOAD
#define USE_TIME
#define USE_WIFI
#define USE_WIFI_WPA2_EAP
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
#define USE_ESP32_CAMERA
#define USE_ESP32_BLE_SERVER #define USE_ESP32_BLE_SERVER
#define USE_ESP32_CAMERA
#define USE_ETHERNET
#define USE_IMPROV #define USE_IMPROV
#endif #endif
#define USE_TIME
#define USE_DEEP_SLEEP // Disabled feature flags
#define USE_CAPTIVE_PORTAL //#define USE_BSEC // Requires a library with proprietary license.
#define ESPHOME_BOARD "dummy_board"
#define USE_MDNS

View file

@ -1,3 +1,9 @@
#pragma once #pragma once
// This file is auto-generated! Do not edit!
// This file is not used by the runtime, instead, a version is generated during
// compilation with only the version for the current build. This is kept in its
// own file so that not all files have to be recompiled for each new release.
//
// This file is only used by static analyzers and IDEs.
#define ESPHOME_VERSION "dev" #define ESPHOME_VERSION "dev"