From ebe64e24f1b2344b49e64177f90ba47a3a45b8b2 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Mon, 3 Jun 2019 16:07:15 +0200 Subject: [PATCH] Move ESPHome version define (#607) * Move ESPHome version define * Lint --- esphome/components/api/api_server.cpp | 1 + esphome/components/debug/debug_component.cpp | 3 ++- esphome/components/mqtt/mqtt_component.cpp | 1 + esphome/components/version/version_text_sensor.cpp | 1 + esphome/core/application.cpp | 1 + esphome/core/defines.h | 2 -- esphome/core/util.cpp | 1 + esphome/core/version.h | 3 +++ esphome/core_config.py | 3 +-- esphome/writer.py | 9 ++++++++- 10 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 esphome/core/version.h diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index 375ff35a02..cde6f1e875 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -6,6 +6,7 @@ #include "esphome/core/application.h" #include "esphome/core/util.h" #include "esphome/core/defines.h" +#include "esphome/core/version.h" #ifdef USE_DEEP_SLEEP #include "esphome/components/deep_sleep/deep_sleep_component.h" diff --git a/esphome/components/debug/debug_component.cpp b/esphome/components/debug/debug_component.cpp index 9cb3ec9cef..4ffc034d50 100644 --- a/esphome/components/debug/debug_component.cpp +++ b/esphome/components/debug/debug_component.cpp @@ -2,6 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/helpers.h" #include "esphome/core/defines.h" +#include "esphome/core/version.h" #ifdef ARDUINO_ARCH_ESP32 #include @@ -19,7 +20,7 @@ void DebugComponent::dump_config() { return; #endif - ESP_LOGD(TAG, "ESPHome Core version %s", ESPHOME_VERSION); + ESP_LOGD(TAG, "ESPHome version %s", ESPHOME_VERSION); this->free_heap_ = ESP.getFreeHeap(); ESP_LOGD(TAG, "Free Heap Size: %u bytes", this->free_heap_); diff --git a/esphome/components/mqtt/mqtt_component.cpp b/esphome/components/mqtt/mqtt_component.cpp index 042e362f75..53c4e89e98 100644 --- a/esphome/components/mqtt/mqtt_component.cpp +++ b/esphome/components/mqtt/mqtt_component.cpp @@ -2,6 +2,7 @@ #include "esphome/core/log.h" #include "esphome/core/application.h" #include "esphome/core/helpers.h" +#include "esphome/core/version.h" namespace esphome { namespace mqtt { diff --git a/esphome/components/version/version_text_sensor.cpp b/esphome/components/version/version_text_sensor.cpp index 1e59deff96..6aedfdedcd 100644 --- a/esphome/components/version/version_text_sensor.cpp +++ b/esphome/components/version/version_text_sensor.cpp @@ -1,6 +1,7 @@ #include "version_text_sensor.h" #include "esphome/core/log.h" #include "esphome/core/application.h" +#include "esphome/core/version.h" namespace esphome { namespace version { diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index fc6ed732be..f865643f57 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -1,5 +1,6 @@ #include "esphome/core/application.h" #include "esphome/core/log.h" +#include "esphome/core/version.h" #ifdef USE_STATUS_LED #include "esphome/components/status_led/status_led.h" diff --git a/esphome/core/defines.h b/esphome/core/defines.h index af9de1b421..c52a4390dc 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -1,8 +1,6 @@ #pragma once // This file is auto-generated! Do not edit! -#define ESPHOME_VERSION "dev" - #define USE_API #define USE_LOGGER #define USE_BINARY_SENSOR diff --git a/esphome/core/util.cpp b/esphome/core/util.cpp index 9e70f8b6e4..4a2985e516 100644 --- a/esphome/core/util.cpp +++ b/esphome/core/util.cpp @@ -1,6 +1,7 @@ #include "esphome/core/util.h" #include "esphome/core/defines.h" #include "esphome/core/application.h" +#include "esphome/core/version.h" #ifdef USE_WIFI #include "esphome/components/wifi/wifi_component.h" diff --git a/esphome/core/version.h b/esphome/core/version.h new file mode 100644 index 0000000000..0942c3e52f --- /dev/null +++ b/esphome/core/version.h @@ -0,0 +1,3 @@ +#pragma once +// This file is auto-generated! Do not edit! +#define ESPHOME_VERSION "dev" diff --git a/esphome/core_config.py b/esphome/core_config.py index 4061582266..55ea02e8ee 100644 --- a/esphome/core_config.py +++ b/esphome/core_config.py @@ -10,7 +10,7 @@ from esphome.const import ARDUINO_VERSION_ESP32_DEV, ARDUINO_VERSION_ESP8266_DEV CONF_ESPHOME, CONF_INCLUDES, CONF_LIBRARIES, \ CONF_NAME, CONF_ON_BOOT, CONF_ON_LOOP, CONF_ON_SHUTDOWN, CONF_PLATFORM, \ CONF_PLATFORMIO_OPTIONS, CONF_PRIORITY, CONF_TRIGGER_ID, \ - CONF_ESP8266_RESTORE_FROM_FLASH, __version__, ARDUINO_VERSION_ESP8266_2_3_0, \ + CONF_ESP8266_RESTORE_FROM_FLASH, ARDUINO_VERSION_ESP8266_2_3_0, \ ARDUINO_VERSION_ESP8266_2_5_0, ARDUINO_VERSION_ESP8266_2_5_1, ARDUINO_VERSION_ESP8266_2_5_2 from esphome.core import CORE, coroutine_with_priority from esphome.helpers import copy_file_if_changed, walk_files @@ -201,7 +201,6 @@ def add_includes(includes): @coroutine_with_priority(100.0) def to_code(config): cg.add_global(cg.global_ns.namespace('esphome').using) - cg.add_define('ESPHOME_VERSION', __version__) cg.add(cg.App.pre_setup(config[CONF_NAME], cg.RawExpression('__DATE__ ", " __TIME__'))) for conf in config.get(CONF_ON_BOOT, []): diff --git a/esphome/writer.py b/esphome/writer.py index 0f27530766..5edf68abb4 100644 --- a/esphome/writer.py +++ b/esphome/writer.py @@ -6,7 +6,7 @@ import re from esphome.config import iter_components from esphome.const import CONF_BOARD_FLASH_MODE, CONF_ESPHOME, CONF_PLATFORMIO_OPTIONS, \ - HEADER_FILE_EXTENSIONS, SOURCE_FILE_EXTENSIONS + HEADER_FILE_EXTENSIONS, SOURCE_FILE_EXTENSIONS, __version__ from esphome.core import CORE, EsphomeError from esphome.helpers import mkdir_p, read_file, write_file_if_changed, walk_files from esphome.storage_json import StorageJSON, storage_path @@ -268,7 +268,12 @@ DEFINES_H_FORMAT = ESPHOME_H_FORMAT = u"""\ #pragma once {} """ +VERSION_H_FORMAT = u"""\ +#pragma once +#define ESPHOME_VERSION "{}" +""" DEFINES_H_TARGET = 'esphome/core/defines.h' +VERSION_H_TARGET = 'esphome/core/version.h' ESPHOME_README_TXT = u""" THIS DIRECTORY IS AUTO-GENERATED, DO NOT MODIFY @@ -335,6 +340,8 @@ def copy_src_tree(): CORE.relative_src_path('esphome', 'README.txt')) write_file_if_changed(ESPHOME_H_FORMAT.format(include_s), CORE.relative_src_path('esphome.h')) + write_file_if_changed(VERSION_H_FORMAT.format(__version__), + CORE.relative_src_path('esphome' 'core', 'version.h')) def generate_defines_h():