mirror of
https://github.com/esphome/esphome.git
synced 2025-09-25 06:32:22 +01:00
🏗 Merge C++ into python codebase (#504)
## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
This commit is contained in:
85
esphome/components/logger/logger.h
Normal file
85
esphome/components/logger/logger.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/defines.h"
|
||||
|
||||
namespace esphome {
|
||||
|
||||
namespace logger {
|
||||
|
||||
/** Enum for logging UART selection
|
||||
*
|
||||
* Advanced configuration (pin selection, etc) is not supported.
|
||||
*/
|
||||
enum UARTSelection {
|
||||
UART_SELECTION_UART0 = 0,
|
||||
UART_SELECTION_UART1,
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
UART_SELECTION_UART2
|
||||
#endif
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
UART_SELECTION_UART0_SWAP
|
||||
#endif
|
||||
};
|
||||
|
||||
class Logger : public Component {
|
||||
public:
|
||||
explicit Logger(uint32_t baud_rate, size_t tx_buffer_size, UARTSelection uart);
|
||||
|
||||
/// Manually set the baud rate for serial, set to 0 to disable.
|
||||
void set_baud_rate(uint32_t baud_rate);
|
||||
|
||||
/// Set the buffer size that's used for constructing log messages. Log messages longer than this will be truncated.
|
||||
void set_tx_buffer_size(size_t tx_buffer_size);
|
||||
|
||||
/// Get the UART used by the logger.
|
||||
UARTSelection get_uart() const;
|
||||
|
||||
/// Set the global log level. Note: Use the ESPHOME_LOG_LEVEL define to also remove the logs from the build.
|
||||
void set_global_log_level(int log_level);
|
||||
int get_global_log_level() const { return this->global_log_level_; }
|
||||
|
||||
/// Set the log level of the specified tag.
|
||||
void set_log_level(const std::string &tag, int log_level);
|
||||
|
||||
// ========== INTERNAL METHODS ==========
|
||||
// (In most use cases you won't need these)
|
||||
/// Set up this component.
|
||||
void pre_setup();
|
||||
void dump_config() override;
|
||||
|
||||
int level_for(const char *tag);
|
||||
|
||||
/// Register a callback that will be called for every log message sent
|
||||
void add_on_log_callback(std::function<void(int, const char *, const char *)> &&callback);
|
||||
|
||||
float get_setup_priority() const override;
|
||||
|
||||
int log_vprintf_(int level, const char *tag, const char *format, va_list args); // NOLINT
|
||||
#ifdef USE_STORE_LOG_STR_IN_FLASH
|
||||
int log_vprintf_(int level, const char *tag, const __FlashStringHelper *format, va_list args); // NOLINT
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void log_message_(int level, const char *tag, char *msg, int ret);
|
||||
|
||||
uint32_t baud_rate_;
|
||||
std::vector<char> tx_buffer_;
|
||||
int global_log_level_{ESPHOME_LOG_LEVEL};
|
||||
UARTSelection uart_{UART_SELECTION_UART0};
|
||||
HardwareSerial *hw_serial_{nullptr};
|
||||
struct LogLevelOverride {
|
||||
std::string tag;
|
||||
int level;
|
||||
};
|
||||
std::vector<LogLevelOverride> log_levels_;
|
||||
CallbackManager<void(int, const char *, const char *)> log_callback_{};
|
||||
};
|
||||
|
||||
extern Logger *global_logger;
|
||||
|
||||
} // namespace logger
|
||||
|
||||
} // namespace esphome
|
Reference in New Issue
Block a user