mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 07:58:09 +01:00
Allow setting creator project name and version into code (#1872)
This commit is contained in:
parent
b80f3fdec9
commit
5cf18235e3
9 changed files with 113 additions and 51 deletions
|
@ -176,6 +176,10 @@ message DeviceInfoResponse {
|
||||||
string model = 6;
|
string model = 6;
|
||||||
|
|
||||||
bool has_deep_sleep = 7;
|
bool has_deep_sleep = 7;
|
||||||
|
|
||||||
|
// The esphome project details if set
|
||||||
|
string project_name = 8;
|
||||||
|
string project_version = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListEntitiesRequest {
|
message ListEntitiesRequest {
|
||||||
|
|
|
@ -664,6 +664,10 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
|
||||||
#endif
|
#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
|
||||||
|
#ifdef ESPHOME_PROJECT_NAME
|
||||||
|
resp.project_name = ESPHOME_PROJECT_NAME;
|
||||||
|
resp.project_version = ESPHOME_PROJECT_VERSION;
|
||||||
#endif
|
#endif
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -360,6 +360,14 @@ bool DeviceInfoResponse::decode_length(uint32_t field_id, ProtoLengthDelimited v
|
||||||
this->model = value.as_string();
|
this->model = value.as_string();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case 8: {
|
||||||
|
this->project_name = value.as_string();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
case 9: {
|
||||||
|
this->project_version = value.as_string();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -372,6 +380,8 @@ void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const {
|
||||||
buffer.encode_string(5, this->compilation_time);
|
buffer.encode_string(5, this->compilation_time);
|
||||||
buffer.encode_string(6, this->model);
|
buffer.encode_string(6, this->model);
|
||||||
buffer.encode_bool(7, this->has_deep_sleep);
|
buffer.encode_bool(7, this->has_deep_sleep);
|
||||||
|
buffer.encode_string(8, this->project_name);
|
||||||
|
buffer.encode_string(9, this->project_version);
|
||||||
}
|
}
|
||||||
void DeviceInfoResponse::dump_to(std::string &out) const {
|
void DeviceInfoResponse::dump_to(std::string &out) const {
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
|
@ -403,6 +413,14 @@ void DeviceInfoResponse::dump_to(std::string &out) const {
|
||||||
out.append(" has_deep_sleep: ");
|
out.append(" has_deep_sleep: ");
|
||||||
out.append(YESNO(this->has_deep_sleep));
|
out.append(YESNO(this->has_deep_sleep));
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
|
|
||||||
|
out.append(" project_name: ");
|
||||||
|
out.append("'").append(this->project_name).append("'");
|
||||||
|
out.append("\n");
|
||||||
|
|
||||||
|
out.append(" project_version: ");
|
||||||
|
out.append("'").append(this->project_version).append("'");
|
||||||
|
out.append("\n");
|
||||||
out.append("}");
|
out.append("}");
|
||||||
}
|
}
|
||||||
void ListEntitiesRequest::encode(ProtoWriteBuffer buffer) const {}
|
void ListEntitiesRequest::encode(ProtoWriteBuffer buffer) const {}
|
||||||
|
|
|
@ -184,6 +184,8 @@ class DeviceInfoResponse : public ProtoMessage {
|
||||||
std::string compilation_time{};
|
std::string compilation_time{};
|
||||||
std::string model{};
|
std::string model{};
|
||||||
bool has_deep_sleep{false};
|
bool has_deep_sleep{false};
|
||||||
|
std::string project_name{};
|
||||||
|
std::string project_version{};
|
||||||
void encode(ProtoWriteBuffer buffer) const override;
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
void dump_to(std::string &out) const override;
|
void dump_to(std::string &out) const override;
|
||||||
|
|
||||||
|
@ -697,23 +699,23 @@ class CameraImageRequest : public ProtoMessage {
|
||||||
};
|
};
|
||||||
class ListEntitiesClimateResponse : public ProtoMessage {
|
class ListEntitiesClimateResponse : public ProtoMessage {
|
||||||
public:
|
public:
|
||||||
std::string object_id{}; // NOLINT
|
std::string object_id{};
|
||||||
uint32_t key{0}; // NOLINT
|
uint32_t key{0};
|
||||||
std::string name{}; // NOLINT
|
std::string name{};
|
||||||
std::string unique_id{}; // NOLINT
|
std::string unique_id{};
|
||||||
bool supports_current_temperature{false}; // NOLINT
|
bool supports_current_temperature{false};
|
||||||
bool supports_two_point_target_temperature{false}; // NOLINT
|
bool supports_two_point_target_temperature{false};
|
||||||
std::vector<enums::ClimateMode> supported_modes{}; // NOLINT
|
std::vector<enums::ClimateMode> supported_modes{};
|
||||||
float visual_min_temperature{0.0f}; // NOLINT
|
float visual_min_temperature{0.0f};
|
||||||
float visual_max_temperature{0.0f}; // NOLINT
|
float visual_max_temperature{0.0f};
|
||||||
float visual_temperature_step{0.0f}; // NOLINT
|
float visual_temperature_step{0.0f};
|
||||||
bool supports_away{false}; // NOLINT
|
bool supports_away{false};
|
||||||
bool supports_action{false}; // NOLINT
|
bool supports_action{false};
|
||||||
std::vector<enums::ClimateFanMode> supported_fan_modes{}; // NOLINT
|
std::vector<enums::ClimateFanMode> supported_fan_modes{};
|
||||||
std::vector<enums::ClimateSwingMode> supported_swing_modes{}; // NOLINT
|
std::vector<enums::ClimateSwingMode> supported_swing_modes{};
|
||||||
std::vector<std::string> supported_custom_fan_modes{}; // NOLINT
|
std::vector<std::string> supported_custom_fan_modes{};
|
||||||
std::vector<enums::ClimatePreset> supported_presets{}; // NOLINT
|
std::vector<enums::ClimatePreset> supported_presets{};
|
||||||
std::vector<std::string> supported_custom_presets{}; // NOLINT
|
std::vector<std::string> supported_custom_presets{};
|
||||||
void encode(ProtoWriteBuffer buffer) const override;
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
void dump_to(std::string &out) const override;
|
void dump_to(std::string &out) const override;
|
||||||
|
|
||||||
|
@ -724,19 +726,19 @@ class ListEntitiesClimateResponse : public ProtoMessage {
|
||||||
};
|
};
|
||||||
class ClimateStateResponse : public ProtoMessage {
|
class ClimateStateResponse : public ProtoMessage {
|
||||||
public:
|
public:
|
||||||
uint32_t key{0}; // NOLINT
|
uint32_t key{0};
|
||||||
enums::ClimateMode mode{}; // NOLINT
|
enums::ClimateMode mode{};
|
||||||
float current_temperature{0.0f}; // NOLINT
|
float current_temperature{0.0f};
|
||||||
float target_temperature{0.0f}; // NOLINT
|
float target_temperature{0.0f};
|
||||||
float target_temperature_low{0.0f}; // NOLINT
|
float target_temperature_low{0.0f};
|
||||||
float target_temperature_high{0.0f}; // NOLINT
|
float target_temperature_high{0.0f};
|
||||||
bool away{false}; // NOLINT
|
bool away{false};
|
||||||
enums::ClimateAction action{}; // NOLINT
|
enums::ClimateAction action{};
|
||||||
enums::ClimateFanMode fan_mode{}; // NOLINT
|
enums::ClimateFanMode fan_mode{};
|
||||||
enums::ClimateSwingMode swing_mode{}; // NOLINT
|
enums::ClimateSwingMode swing_mode{};
|
||||||
std::string custom_fan_mode{}; // NOLINT
|
std::string custom_fan_mode{};
|
||||||
enums::ClimatePreset preset{}; // NOLINT
|
enums::ClimatePreset preset{};
|
||||||
std::string custom_preset{}; // NOLINT
|
std::string custom_preset{};
|
||||||
void encode(ProtoWriteBuffer buffer) const override;
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
void dump_to(std::string &out) const override;
|
void dump_to(std::string &out) const override;
|
||||||
|
|
||||||
|
@ -747,27 +749,27 @@ class ClimateStateResponse : public ProtoMessage {
|
||||||
};
|
};
|
||||||
class ClimateCommandRequest : public ProtoMessage {
|
class ClimateCommandRequest : public ProtoMessage {
|
||||||
public:
|
public:
|
||||||
uint32_t key{0}; // NOLINT
|
uint32_t key{0};
|
||||||
bool has_mode{false}; // NOLINT
|
bool has_mode{false};
|
||||||
enums::ClimateMode mode{}; // NOLINT
|
enums::ClimateMode mode{};
|
||||||
bool has_target_temperature{false}; // NOLINT
|
bool has_target_temperature{false};
|
||||||
float target_temperature{0.0f}; // NOLINT
|
float target_temperature{0.0f};
|
||||||
bool has_target_temperature_low{false}; // NOLINT
|
bool has_target_temperature_low{false};
|
||||||
float target_temperature_low{0.0f}; // NOLINT
|
float target_temperature_low{0.0f};
|
||||||
bool has_target_temperature_high{false}; // NOLINT
|
bool has_target_temperature_high{false};
|
||||||
float target_temperature_high{0.0f}; // NOLINT
|
float target_temperature_high{0.0f};
|
||||||
bool has_away{false}; // NOLINT
|
bool has_away{false};
|
||||||
bool away{false}; // NOLINT
|
bool away{false};
|
||||||
bool has_fan_mode{false}; // NOLINT
|
bool has_fan_mode{false};
|
||||||
enums::ClimateFanMode fan_mode{}; // NOLINT
|
enums::ClimateFanMode fan_mode{};
|
||||||
bool has_swing_mode{false}; // NOLINT
|
bool has_swing_mode{false};
|
||||||
enums::ClimateSwingMode swing_mode{}; // NOLINT
|
enums::ClimateSwingMode swing_mode{};
|
||||||
bool has_custom_fan_mode{false}; // NOLINT
|
bool has_custom_fan_mode{false};
|
||||||
std::string custom_fan_mode{}; // NOLINT
|
std::string custom_fan_mode{};
|
||||||
bool has_preset{false}; // NOLINT
|
bool has_preset{false};
|
||||||
enums::ClimatePreset preset{}; // NOLINT
|
enums::ClimatePreset preset{};
|
||||||
bool has_custom_preset{false}; // NOLINT
|
bool has_custom_preset{false};
|
||||||
std::string custom_preset{}; // NOLINT
|
std::string custom_preset{};
|
||||||
void encode(ProtoWriteBuffer buffer) const override;
|
void encode(ProtoWriteBuffer buffer) const override;
|
||||||
void dump_to(std::string &out) const override;
|
void dump_to(std::string &out) const override;
|
||||||
|
|
||||||
|
|
|
@ -459,6 +459,7 @@ CONF_PRESET_ECO = "preset_eco"
|
||||||
CONF_PRESET_SLEEP = "preset_sleep"
|
CONF_PRESET_SLEEP = "preset_sleep"
|
||||||
CONF_PRESSURE = "pressure"
|
CONF_PRESSURE = "pressure"
|
||||||
CONF_PRIORITY = "priority"
|
CONF_PRIORITY = "priority"
|
||||||
|
CONF_PROJECT = "project"
|
||||||
CONF_PROTOCOL = "protocol"
|
CONF_PROTOCOL = "protocol"
|
||||||
CONF_PULL_MODE = "pull_mode"
|
CONF_PULL_MODE = "pull_mode"
|
||||||
CONF_PULSE_LENGTH = "pulse_length"
|
CONF_PULSE_LENGTH = "pulse_length"
|
||||||
|
@ -616,6 +617,7 @@ CONF_UUID = "uuid"
|
||||||
CONF_VALUE = "value"
|
CONF_VALUE = "value"
|
||||||
CONF_VARIABLES = "variables"
|
CONF_VARIABLES = "variables"
|
||||||
CONF_VARIANT = "variant"
|
CONF_VARIANT = "variant"
|
||||||
|
CONF_VERSION = "version"
|
||||||
CONF_VISUAL = "visual"
|
CONF_VISUAL = "visual"
|
||||||
CONF_VOLTAGE = "voltage"
|
CONF_VOLTAGE = "voltage"
|
||||||
CONF_VOLTAGE_ATTENUATION = "voltage_attenuation"
|
CONF_VOLTAGE_ATTENUATION = "voltage_attenuation"
|
||||||
|
|
|
@ -103,6 +103,9 @@ void Application::loop() {
|
||||||
if (this->dump_config_at_ >= 0 && this->dump_config_at_ < this->components_.size()) {
|
if (this->dump_config_at_ >= 0 && this->dump_config_at_ < this->components_.size()) {
|
||||||
if (this->dump_config_at_ == 0) {
|
if (this->dump_config_at_ == 0) {
|
||||||
ESP_LOGI(TAG, "ESPHome version " ESPHOME_VERSION " compiled on %s", this->compilation_time_.c_str());
|
ESP_LOGI(TAG, "ESPHome version " ESPHOME_VERSION " compiled on %s", this->compilation_time_.c_str());
|
||||||
|
#ifdef ESPHOME_PROJECT_NAME
|
||||||
|
ESP_LOGI(TAG, "Project " ESPHOME_PROJECT_NAME " version " ESPHOME_PROJECT_VERSION);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
this->components_[this->dump_config_at_]->dump_config();
|
this->components_[this->dump_config_at_]->dump_config();
|
||||||
|
|
|
@ -21,10 +21,12 @@ from esphome.const import (
|
||||||
CONF_PLATFORM,
|
CONF_PLATFORM,
|
||||||
CONF_PLATFORMIO_OPTIONS,
|
CONF_PLATFORMIO_OPTIONS,
|
||||||
CONF_PRIORITY,
|
CONF_PRIORITY,
|
||||||
|
CONF_PROJECT,
|
||||||
CONF_TRIGGER_ID,
|
CONF_TRIGGER_ID,
|
||||||
CONF_ESP8266_RESTORE_FROM_FLASH,
|
CONF_ESP8266_RESTORE_FROM_FLASH,
|
||||||
ARDUINO_VERSION_ESP8266,
|
ARDUINO_VERSION_ESP8266,
|
||||||
ARDUINO_VERSION_ESP32,
|
ARDUINO_VERSION_ESP32,
|
||||||
|
CONF_VERSION,
|
||||||
ESP_PLATFORMS,
|
ESP_PLATFORMS,
|
||||||
)
|
)
|
||||||
from esphome.core import CORE, coroutine_with_priority
|
from esphome.core import CORE, coroutine_with_priority
|
||||||
|
@ -144,6 +146,15 @@ def valid_include(value):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def valid_project_name(value: str):
|
||||||
|
if value.count(".") != 1:
|
||||||
|
raise cv.Invalid("project name needs to have a namespace")
|
||||||
|
|
||||||
|
value = value.replace(" ", "_")
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.Schema(
|
CONFIG_SCHEMA = cv.Schema(
|
||||||
{
|
{
|
||||||
cv.Required(CONF_NAME): cv.valid_name,
|
cv.Required(CONF_NAME): cv.valid_name,
|
||||||
|
@ -184,6 +195,12 @@ CONFIG_SCHEMA = cv.Schema(
|
||||||
cv.Optional(CONF_INCLUDES, default=[]): cv.ensure_list(valid_include),
|
cv.Optional(CONF_INCLUDES, default=[]): cv.ensure_list(valid_include),
|
||||||
cv.Optional(CONF_LIBRARIES, default=[]): cv.ensure_list(cv.string_strict),
|
cv.Optional(CONF_LIBRARIES, default=[]): cv.ensure_list(cv.string_strict),
|
||||||
cv.Optional(CONF_NAME_ADD_MAC_SUFFIX, default=False): cv.boolean,
|
cv.Optional(CONF_NAME_ADD_MAC_SUFFIX, default=False): cv.boolean,
|
||||||
|
cv.Optional(CONF_PROJECT): cv.Schema(
|
||||||
|
{
|
||||||
|
cv.Required(CONF_NAME): cv.All(cv.string_strict, valid_project_name),
|
||||||
|
cv.Required(CONF_VERSION): cv.string_strict,
|
||||||
|
}
|
||||||
|
),
|
||||||
cv.Optional("esphome_core_version"): cv.invalid(
|
cv.Optional("esphome_core_version"): cv.invalid(
|
||||||
"The esphome_core_version option has been "
|
"The esphome_core_version option has been "
|
||||||
"removed in 1.13 - the esphome core source "
|
"removed in 1.13 - the esphome core source "
|
||||||
|
@ -331,3 +348,7 @@ async def to_code(config):
|
||||||
|
|
||||||
if config[CONF_INCLUDES]:
|
if config[CONF_INCLUDES]:
|
||||||
CORE.add_job(add_includes, config[CONF_INCLUDES])
|
CORE.add_job(add_includes, config[CONF_INCLUDES])
|
||||||
|
|
||||||
|
if CONF_PROJECT in config:
|
||||||
|
cg.add_define("ESPHOME_PROJECT_NAME", config[CONF_PROJECT][CONF_NAME])
|
||||||
|
cg.add_define("ESPHOME_PROJECT_VERSION", config[CONF_PROJECT][CONF_VERSION])
|
||||||
|
|
|
@ -94,6 +94,11 @@ void network_setup_mdns(IPAddress address, int interface) {
|
||||||
MDNS.addServiceTxt("esphomelib", "tcp", "version", ESPHOME_VERSION);
|
MDNS.addServiceTxt("esphomelib", "tcp", "version", ESPHOME_VERSION);
|
||||||
MDNS.addServiceTxt("esphomelib", "tcp", "address", network_get_address().c_str());
|
MDNS.addServiceTxt("esphomelib", "tcp", "address", network_get_address().c_str());
|
||||||
MDNS.addServiceTxt("esphomelib", "tcp", "mac", get_mac_address().c_str());
|
MDNS.addServiceTxt("esphomelib", "tcp", "mac", get_mac_address().c_str());
|
||||||
|
|
||||||
|
#ifdef ESPHOME_PROJECT_NAME
|
||||||
|
MDNS.addServiceTxt("esphomelib", "tcp", "project_name", ESPHOME_PROJECT_NAME);
|
||||||
|
MDNS.addServiceTxt("esphomelib", "tcp", "project_version", ESPHOME_PROJECT_VERSION);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
// Publish "http" service if not using native API nor the webserver component
|
// Publish "http" service if not using native API nor the webserver component
|
||||||
|
|
|
@ -3,6 +3,9 @@ esphome:
|
||||||
platform: ESP32
|
platform: ESP32
|
||||||
board: nodemcu-32s
|
board: nodemcu-32s
|
||||||
build_path: build/test5
|
build_path: build/test5
|
||||||
|
project:
|
||||||
|
name: esphome.test5_project
|
||||||
|
version: "1.0.0"
|
||||||
|
|
||||||
wifi:
|
wifi:
|
||||||
networks:
|
networks:
|
||||||
|
|
Loading…
Reference in a new issue