Skip to content

Commit

Permalink
Clean-up constant definitions (esphome#2148)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxan authored Aug 23, 2021
1 parent 8cc3cbb commit 5ec9bb0
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 55 deletions.
4 changes: 1 addition & 3 deletions esphome/components/api/api_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,7 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
resp.mac_address = get_mac_address_pretty();
resp.esphome_version = ESPHOME_VERSION;
resp.compilation_time = App.get_compilation_time();
#ifdef ARDUINO_BOARD
resp.model = ARDUINO_BOARD;
#endif
resp.model = ESPHOME_BOARD;
#ifdef USE_DEEP_SLEEP
resp.has_deep_sleep = deep_sleep::global_has_deep_sleep;
#endif
Expand Down
4 changes: 2 additions & 2 deletions esphome/components/bme680_bsec/bme680_bsec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static const char *const TAG = "bme680_bsec.sensor";

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() {
ESP_LOGCONFIG(TAG, "Setting up BME680 via BSEC...");
Expand Down Expand Up @@ -359,7 +359,7 @@ void BME680BSECComponent::publish_sensor_state_(sensor::Sensor *sensor, float va
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)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/bme680_bsec/bme680_bsec.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BME680BSECComponent : public Component, public i2c::I2CDevice {
int64_t get_time_ns_();

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 save_state_(uint8_t accuracy);
Expand Down
4 changes: 1 addition & 3 deletions esphome/components/esp32_ble_server/ble_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ bool BLEServer::create_device_characteristics_() {
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
model->set_value(this->model_.value());
} else {
#ifdef ARDUINO_BOARD
BLECharacteristic *model =
this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ);
model->set_value(ARDUINO_BOARD);
#endif
model->set_value(ESPHOME_BOARD);
}

BLECharacteristic *version =
Expand Down
4 changes: 1 addition & 3 deletions esphome/components/mqtt/mqtt_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ bool MQTTComponent::send_discovery_() {
device_info["identifiers"] = get_mac_address();
device_info["name"] = node_name;
device_info["sw_version"] = "esphome v" ESPHOME_VERSION " " + App.get_compilation_time();
#ifdef ARDUINO_BOARD
device_info["model"] = ARDUINO_BOARD;
#endif
device_info["model"] = ESPHOME_BOARD;
device_info["manufacturer"] = "espressif";
},
0, discovery_info.retain);
Expand Down
2 changes: 1 addition & 1 deletion esphome/components/wifi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def wifi_network(config, static_ip):
cg.add(ap.set_password(config[CONF_PASSWORD]))
if CONF_EAP in config:
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:
cg.add(ap.set_bssid([HexInt(i) for i in config[CONF_BSSID].parts]))
if CONF_HIDDEN in config:
Expand Down
14 changes: 7 additions & 7 deletions esphome/components/wifi/wifi_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void WiFiComponent::start_connecting(const WiFiAP &ap, bool two) {
ESP_LOGV(TAG, " BSSID: Not Set");
}

#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
if (ap.get_eap().has_value()) {
ESP_LOGV(TAG, " WPA2 Enterprise authentication configured:");
EAPAuth eap_config = ap.get_eap().value();
Expand All @@ -274,7 +274,7 @@ void WiFiComponent::start_connecting(const WiFiAP &ap, bool two) {
} else {
#endif
ESP_LOGV(TAG, " Password: " LOG_SECRET("'%s'"), ap.get_password().c_str());
#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
}
#endif
if (ap.get_channel().has_value()) {
Expand Down Expand Up @@ -478,7 +478,7 @@ void WiFiComponent::check_scanning_finished() {
// copy manual IP (if set)
connect_params.set_manual_ip(config.get_manual_ip());

#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
// copy EAP parameters (if set)
connect_params.set_eap(config.get_eap());
#endif
Expand Down Expand Up @@ -638,16 +638,16 @@ 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(optional<bssid_t> bssid) { this->bssid_ = bssid; }
void WiFiAP::set_password(const std::string &password) { this->password_ = password; }
#ifdef ESPHOME_WIFI_WPA2_EAP
void WiFiAP::set_eap(optional<EAPAuth> eap_auth) { this->eap_ = eap_auth; }
#ifdef USE_WIFI_WPA2_EAP
void WiFiAP::set_eap(optional<EAPAuth> eap_auth) { this->eap_ = std::move(eap_auth); }
#endif
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_hidden(bool hidden) { this->hidden_ = hidden; }
const std::string &WiFiAP::get_ssid() const { return this->ssid_; }
const optional<bssid_t> &WiFiAP::get_bssid() const { return this->bssid_; }
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_; }
#endif
const optional<uint8_t> &WiFiAP::get_channel() const { return this->channel_; }
Expand Down Expand Up @@ -679,7 +679,7 @@ bool WiFiScanResult::matches(const WiFiAP &config) {
if (config.get_bssid().has_value() && *config.get_bssid() != this->bssid_)
return false;

#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
// BSSID requires auth but no PSK or EAP credentials given
if (this->with_auth_ && (config.get_password().empty() && !config.get_eap().has_value()))
return false;
Expand Down
16 changes: 8 additions & 8 deletions esphome/components/wifi/wifi_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct ManualIP {
IPAddress dns2; ///< The second DNS server. 0.0.0.0 for default.
};

#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
struct EAPAuth {
std::string identity; // required for all auth types
std::string username;
Expand All @@ -73,7 +73,7 @@ struct EAPAuth {
const char *client_cert;
const char *client_key;
};
#endif // ESPHOME_WIFI_WPA2_EAP
#endif // USE_WIFI_WPA2_EAP

using bssid_t = std::array<uint8_t, 6>;

Expand All @@ -83,19 +83,19 @@ class WiFiAP {
void set_bssid(bssid_t bssid);
void set_bssid(optional<bssid_t> bssid);
void set_password(const std::string &password);
#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
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_priority(float priority) { priority_ = priority; }
void set_manual_ip(optional<ManualIP> manual_ip);
void set_hidden(bool hidden);
const std::string &get_ssid() const;
const optional<bssid_t> &get_bssid() const;
const std::string &get_password() const;
#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
const optional<EAPAuth> &get_eap() const;
#endif // ESPHOME_WIFI_WPA2_EAP
#endif // USE_WIFI_WPA2_EAP
const optional<uint8_t> &get_channel() const;
float get_priority() const { return priority_; }
const optional<ManualIP> &get_manual_ip() const;
Expand All @@ -105,9 +105,9 @@ class WiFiAP {
std::string ssid_;
optional<bssid_t> bssid_;
std::string password_;
#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
optional<EAPAuth> eap_;
#endif // ESPHOME_WIFI_WPA2_EAP
#endif // USE_WIFI_WPA2_EAP
optional<uint8_t> channel_;
float priority_{0};
optional<ManualIP> manual_ip_;
Expand Down
8 changes: 4 additions & 4 deletions esphome/components/wifi/wifi_component_esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <utility>
#include <algorithm>
#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
#include <esp_wpa2.h>
#endif
#include "lwip/err.h"
Expand Down Expand Up @@ -163,7 +163,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
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()) {
conf.sta.threshold.authmode = WIFI_AUTH_WPA2_ENTERPRISE;
}
Expand Down Expand Up @@ -220,7 +220,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
}

// setup enterprise authentication if required
#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
if (ap.get_eap().has_value()) {
// note: all certificates and keys have to be null terminated. Lengths are appended by +1 to include \0.
EAPAuth eap = ap.get_eap().value();
Expand Down Expand Up @@ -264,7 +264,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
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_();

Expand Down
6 changes: 3 additions & 3 deletions esphome/components/wifi/wifi_component_esp8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <utility>
#include <algorithm>
#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
#include <wpa2_enterprise.h>
#endif

Expand Down Expand Up @@ -250,7 +250,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
}

// setup enterprise authentication if required
#ifdef ESPHOME_WIFI_WPA2_EAP
#ifdef USE_WIFI_WPA2_EAP
if (ap.get_eap().has_value()) {
// note: all certificates and keys have to be null terminated. Lengths are appended by +1 to include \0.
EAPAuth eap = ap.get_eap().value();
Expand Down Expand Up @@ -293,7 +293,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
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_();

Expand Down
59 changes: 40 additions & 19 deletions esphome/core/defines.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
#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_LOGGER
#define USE_BINARY_SENSOR
#define USE_SENSOR
#define USE_SWITCH
#define USE_WIFI
#define USE_STATUS_LED
#define USE_TEXT_SENSOR
#define USE_FAN
#define USE_CAPTIVE_PORTAL
#define USE_CLIMATE
#define USE_COVER
#define USE_DEEP_SLEEP
#define USE_ESP8266_PREFERENCES_FLASH
#define USE_FAN
#define USE_HOMEASSISTANT_TIME
#define USE_I2C_MULTIPLEXER
#define USE_JSON
#define USE_LIGHT
#define USE_CLIMATE
#define USE_NUMBER
#define USE_SELECT
#define USE_LOGGER
#define USE_MDNS
#define USE_MQTT
#define USE_NUMBER
#define USE_OTA_STATE_CALLBACK
#define USE_POWER_SUPPLY
#define USE_HOMEASSISTANT_TIME
#define USE_JSON
#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
#define USE_ESP32_CAMERA
#define USE_ESP32_BLE_SERVER
#define USE_ESP32_CAMERA
#define USE_ETHERNET
#define USE_IMPROV
#endif
#define USE_TIME
#define USE_DEEP_SLEEP
#define USE_CAPTIVE_PORTAL
#define ESPHOME_BOARD "dummy_board"
#define USE_MDNS

// Disabled feature flags
//#define USE_BSEC // Requires a library with proprietary license.
8 changes: 7 additions & 1 deletion esphome/core/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#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"

0 comments on commit 5ec9bb0

Please sign in to comment.