diff --git a/components/nuki_lock/nuki_lock.cpp b/components/nuki_lock/nuki_lock.cpp index ca044bd..f1ed1ff 100644 --- a/components/nuki_lock/nuki_lock.cpp +++ b/components/nuki_lock/nuki_lock.cpp @@ -294,8 +294,8 @@ bool NukiLockComponent::update_battery_report_() { 1000.0f); battery_resistance_sensor_->publish_state(batteryReport.batteryResistance / 1000.0f); - last_action_lowest_voltage_sensor_->publish_state(batteryReport.lowestVoltage / - 1000.0f); + last_action_lowest_voltage_sensor_->publish_state( + batteryReport.lowestVoltage / 1000.0f); last_action_start_voltage_sensor_->publish_state(batteryReport.startVoltage / 1000.0f); last_action_lock_distance_sensor_->publish_state(batteryReport.lockDistance); diff --git a/components/nuki_lock/nuki_lock.h b/components/nuki_lock/nuki_lock.h index 05ea6a6..174538f 100644 --- a/components/nuki_lock/nuki_lock.h +++ b/components/nuki_lock/nuki_lock.h @@ -25,7 +25,7 @@ class NukiLockComponent : public lock::Lock, restart_after_beacon_latency_(0), update_scheduled_(false), request_battery_reports_(false), - pin_set_(false){}; + pin_set_(false) {}; // Component. void setup() override; diff --git a/components/syslog/syslog.cpp b/components/syslog/syslog.cpp index e6d615b..4bc3a7f 100644 --- a/components/syslog/syslog.cpp +++ b/components/syslog/syslog.cpp @@ -3,9 +3,9 @@ #include -#include "esphome/core/log.h" -#include "esphome/core/application.h" #include "esphome/components/network/util.h" +#include "esphome/core/application.h" +#include "esphome/core/log.h" #ifdef USE_LOGGER #include "esphome/components/logger/logger.h" @@ -15,16 +15,16 @@ namespace esphome { namespace syslog { -std::string remove_ansi_colors(const std::string& input) { +std::string remove_ansi_colors(const std::string &input) { std::string result; bool escape_sequence = false; for (char c : input) { - if (c == '\033') { // Start of an escape sequence + if (c == '\033') { // Start of an escape sequence escape_sequence = true; - } else if (escape_sequence && c == 'm') { // End of an escape sequence + } else if (escape_sequence && c == 'm') { // End of an escape sequence escape_sequence = false; - } else if (!escape_sequence) { // Normal character + } else if (!escape_sequence) { // Normal character result += c; } } @@ -33,24 +33,24 @@ std::string remove_ansi_colors(const std::string& input) { } enum Priority { - EMERG = 0, /* System is unusable */ - ALERT = 1, /* Action must be taken immediately */ - CRIT = 2, /* Critical conditions */ - ERR = 3, /* Error conditions */ - WARNING = 4, /* Warning conditions */ - NOTICE = 5, /* Normal but significant conditions */ - INFO = 6, /* Informational messages */ - DEBUG = 7, /* Debug-level messages */ + EMERG = 0, /* System is unusable */ + ALERT = 1, /* Action must be taken immediately */ + CRIT = 2, /* Critical conditions */ + ERR = 3, /* Error conditions */ + WARNING = 4, /* Warning conditions */ + NOTICE = 5, /* Normal but significant conditions */ + INFO = 6, /* Informational messages */ + DEBUG = 7, /* Debug-level messages */ }; static const uint8_t esphome_to_syslog_log_levels[] = { - /* ESPHOME_LOG_LEVEL_NONE */ Priority::DEBUG, - /* ESPHOME_LOG_LEVEL_ERROR */ Priority::ERR, - /* ESPHOME_LOG_LEVEL_WARN */ Priority::WARNING, - /* ESPHOME_LOG_LEVEL_INFO */ Priority::INFO, - /* ESPHOME_LOG_LEVEL_CONFIG */ Priority::NOTICE, - /* ESPHOME_LOG_LEVEL_DEBUG */ Priority::DEBUG, - /* ESPHOME_LOG_LEVEL_VERBOSE */ Priority::DEBUG, + /* ESPHOME_LOG_LEVEL_NONE */ Priority::DEBUG, + /* ESPHOME_LOG_LEVEL_ERROR */ Priority::ERR, + /* ESPHOME_LOG_LEVEL_WARN */ Priority::WARNING, + /* ESPHOME_LOG_LEVEL_INFO */ Priority::INFO, + /* ESPHOME_LOG_LEVEL_CONFIG */ Priority::NOTICE, + /* ESPHOME_LOG_LEVEL_DEBUG */ Priority::DEBUG, + /* ESPHOME_LOG_LEVEL_VERBOSE */ Priority::DEBUG, /* ESPHOME_LOG_LEVEL_VERY_VERBOSE */ Priority::DEBUG, }; @@ -67,33 +67,34 @@ void Syslog::setup() { #ifdef USE_LOGGER if (logger::global_logger != nullptr && this->forward_logger_) { logger::global_logger->add_on_log_callback( - [this](int level, const char *tag, const char *message) { - if (level > this->min_log_level_) - return; + [this](int level, const char *tag, const char *message) { + if (level > this->min_log_level_) return; - if (this->strip_color_codes_) { - std::string clean_message = remove_ansi_colors(message); - this->log(level, tag, clean_message); - } else { - this->log(level, tag, message); - } - }); - } + if (this->strip_color_codes_) { + std::string clean_message = remove_ansi_colors(message); + this->log(level, tag, clean_message); + } else { + this->log(level, tag, message); + } + }); + } #endif -#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) +#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || \ + defined(USE_SOCKET_IMPL_LWIP_SOCKETS) this->socket_ = socket::socket(AF_INET, SOCK_DGRAM, PF_INET); // We don't expect any reply from syslog server, so there's no need to block. this->socket_->setblocking(false); this->destination_len_ = socket::set_sockaddr( - reinterpret_cast(&this->destination_), sizeof(this->destination_), - this->server_ip_address_, this->server_port_); + reinterpret_cast(&this->destination_), + sizeof(this->destination_), this->server_ip_address_, this->server_port_); if (this->destination_len_ == 0) { std::string error_message(strerror(errno)); - ESP_LOGE(TAG, "Cannot use IP address '%s' or port %d for server connection: %s", - this->server_ip_address_.c_str(), this->server_port_, - error_message.c_str()); + ESP_LOGE(TAG, + "Cannot use IP address '%s' or port %d for server connection: %s", + this->server_ip_address_.c_str(), this->server_port_, + error_message.c_str()); } #endif } @@ -108,13 +109,17 @@ void Syslog::loop() { void Syslog::dump_config() { ESP_LOGCONFIG(TAG, "Syslog:"); - ESP_LOGCONFIG(TAG, " Server IP address: %s", this->server_ip_address_.c_str()); + ESP_LOGCONFIG(TAG, " Server IP address: %s", + this->server_ip_address_.c_str()); ESP_LOGCONFIG(TAG, " Server port: %d", this->server_port_); - ESP_LOGCONFIG(TAG, " Client ID (syslog hostname): %s", this->hostname_.c_str()); + ESP_LOGCONFIG(TAG, " Client ID (syslog hostname): %s", + this->hostname_.c_str()); #ifdef USE_LOGGER ESP_LOGCONFIG(TAG, " Min log level: %d", this->min_log_level_); - ESP_LOGCONFIG(TAG, " Forward logger messages: %s", this->forward_logger_ ? "yes" : "no"); - ESP_LOGCONFIG(TAG, " Strip color codes: %s", this->strip_color_codes_ ? "yes" : "no"); + ESP_LOGCONFIG(TAG, " Forward logger messages: %s", + this->forward_logger_ ? "yes" : "no"); + ESP_LOGCONFIG(TAG, " Strip color codes: %s", + this->strip_color_codes_ ? "yes" : "no"); #endif } @@ -127,23 +132,25 @@ void Syslog::log(int level, const std::string &tag, const std::string &msg) { std::stringstream payload_stream; // rsyslog compatible protocol: - // VERSION SP TIMESTAMP SP HOSTNAME SP APP-NAME SP PROCID SP MSGID SP [SD-ID]s SP MSG - payload_stream - << "<" << static_cast(esphome_to_syslog_log_levels[level]) << ">1 - " - << this->hostname_ << " " - << App.get_name() << " - - - " << msg; + // VERSION SP TIMESTAMP SP HOSTNAME SP APP-NAME SP PROCID SP MSGID SP + // [SD-ID]s SP MSG + payload_stream << "<" << static_cast(esphome_to_syslog_log_levels[level]) + << ">1 - " << this->hostname_ << " " << App.get_name() + << " - - - " << msg; std::string payload = payload_stream.str(); ssize_t bytes_sent = 0; -#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) +#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || \ + defined(USE_SOCKET_IMPL_LWIP_SOCKETS) if (this->destination_len_ > 0) { - bytes_sent = this->socket_->sendto( - payload.c_str(), payload.length(), - 0, - reinterpret_cast(&this->destination_), this->destination_len_); + bytes_sent = + this->socket_->sendto(payload.c_str(), payload.length(), 0, + reinterpret_cast(&this->destination_), + this->destination_len_); } #else - if (this->udp_client_.beginPacket(this->server_ip_address_.c_str(), this->server_port_)) { + if (this->udp_client_.beginPacket(this->server_ip_address_.c_str(), + this->server_port_)) { bytes_sent = this->udp_client_.write(payload.c_str(), payload.length()); if (!this->udp_client_.endPacket()) { bytes_sent = 0; diff --git a/components/syslog/syslog.h b/components/syslog/syslog.h index 8a1baac..1b9a744 100644 --- a/components/syslog/syslog.h +++ b/components/syslog/syslog.h @@ -13,11 +13,12 @@ - autoretries (fixes esp8266 skipping logs at startup due to dump_config flood) */ -#include "esphome/core/component.h" #include "esphome/core/automation.h" +#include "esphome/core/component.h" #include "esphome/core/log.h" -#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) +#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || \ + defined(USE_SOCKET_IMPL_LWIP_SOCKETS) #include "esphome/components/socket/socket.h" #else #include "WiFiUdp.h" @@ -31,13 +32,17 @@ class Syslog : public Component { public: explicit Syslog(); - float get_setup_priority() const override { return setup_priority::AFTER_WIFI; } + float get_setup_priority() const override { + return setup_priority::AFTER_WIFI; + } void setup() override; void loop() override; void dump_config() override; - void set_server_ip_address(const std::string &address) { this->server_ip_address_ = address; } + void set_server_ip_address(const std::string &address) { + this->server_ip_address_ = address; + } void set_server_port(uint16_t port) { this->server_port_ = port; } void set_hostname(const std::string &hostname) { this->hostname_ = hostname; } void set_min_log_level(int log_level) { this->min_log_level_ = log_level; } @@ -54,7 +59,8 @@ class Syslog : public Component { bool forward_logger_; bool strip_color_codes_; -#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) +#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || \ + defined(USE_SOCKET_IMPL_LWIP_SOCKETS) std::unique_ptr socket_{}; struct sockaddr_storage destination_; socklen_t destination_len_; @@ -75,10 +81,8 @@ class Syslog : public Component { TEMPLATABLE_VALUE(std::string, payload) void play(Ts... x) override { - this->parent_->log( - this->level_.value(x...), - this->tag_.value(x...), - this->payload_.value(x...)); + this->parent_->log(this->level_.value(x...), this->tag_.value(x...), + this->payload_.value(x...)); } protected: @@ -86,7 +90,7 @@ class Syslog : public Component { }; }; -} // namespace syslog +} // namespace syslog -} // namespace esphome +} // namespace esphome #endif diff --git a/components/zehnder/zehnder.cpp b/components/zehnder/zehnder.cpp index 7a69298..027ad23 100644 --- a/components/zehnder/zehnder.cpp +++ b/components/zehnder/zehnder.cpp @@ -3,7 +3,7 @@ #include "esphome/components/remote_base/remote_base.h" namespace { -static const char* const TAG = __FILE__; +static const char *const TAG = __FILE__; static const uint8_t MIN_TEMPERATURE = 35; static const uint8_t MAX_TEMPERATURE = 70; static const uint8_t TEMPERATURE_LEVELS = 8; @@ -12,7 +12,8 @@ static void add_header_(esphome::remote_base::RemoteTransmitData *data) { data->item(30, 1000); } -static void add_byte_(esphome::remote_base::RemoteTransmitData *data, uint8_t value) { +static void add_byte_(esphome::remote_base::RemoteTransmitData *data, + uint8_t value) { for (int i = 0; i < 8; ++i) { data->item(30, value & 0b10000000 ? 830 : 650); value <<= 1; @@ -23,7 +24,7 @@ static void add_post_(esphome::remote_base::RemoteTransmitData *data) { data->item(30, 460); data->item(30, 650); } -} +} // namespace namespace esphome { namespace zehnder { @@ -67,9 +68,8 @@ void ZehnderComponent::setup() { } void ZehnderComponent::update() { - float target_temp = this->mode == climate::CLIMATE_MODE_HEAT ? - this->target_temperature : - 0; + float target_temp = + this->mode == climate::CLIMATE_MODE_HEAT ? this->target_temperature : 0; this->transmit_temperature_(&target_temp); } @@ -89,17 +89,16 @@ climate::ClimateTraits ZehnderComponent::traits() { traits.set_visual_current_temperature_step(0.1); } - traits.set_supported_modes({ - climate::CLIMATE_MODE_HEAT, - climate::CLIMATE_MODE_OFF - }); + traits.set_supported_modes( + {climate::CLIMATE_MODE_HEAT, climate::CLIMATE_MODE_OFF}); return traits; } void ZehnderComponent::dump_config() { ESP_LOGCONFIG(TAG, "Zehnder:"); - ESP_LOGCONFIG(TAG, " has temperature sensor: %s", this->has_temperature_sensor_ ? "yes" : "no"); + ESP_LOGCONFIG(TAG, " has temperature sensor: %s", + this->has_temperature_sensor_ ? "yes" : "no"); } bool ZehnderComponent::transmit_temperature_(float *temp) { @@ -107,20 +106,16 @@ bool ZehnderComponent::transmit_temperature_(float *temp) { if (*temp == 0) { level = 0; } else { - level = - (*temp - MIN_TEMPERATURE) * - (TEMPERATURE_LEVELS - 1) / - (MAX_TEMPERATURE - MIN_TEMPERATURE) + - 1; + level = (*temp - MIN_TEMPERATURE) * (TEMPERATURE_LEVELS - 1) / + (MAX_TEMPERATURE - MIN_TEMPERATURE) + + 1; if (level > TEMPERATURE_LEVELS) { level = TEMPERATURE_LEVELS; } - *temp = - (MAX_TEMPERATURE - MIN_TEMPERATURE) / - (TEMPERATURE_LEVELS - 1) * - (level - 1) + - MIN_TEMPERATURE; + *temp = (MAX_TEMPERATURE - MIN_TEMPERATURE) / (TEMPERATURE_LEVELS - 1) * + (level - 1) + + MIN_TEMPERATURE; } return this->transmit_level_(level); } @@ -146,17 +141,9 @@ bool ZehnderComponent::transmit_level_(uint8_t level) { data->reset(); data->set_carrier_frequency(455000); - static uint8_t mode_bytes[TEMPERATURE_LEVELS + 1] = { - 0x0D, // OFF - 0x86, - 0x95, - 0xA0, - 0xB3, - 0xCA, - 0xD9, - 0xEC, - 0xFF - }; + static uint8_t mode_bytes[TEMPERATURE_LEVELS + 1] = {0x0D, // OFF + 0x86, 0x95, 0xA0, 0xB3, + 0xCA, 0xD9, 0xEC, 0xFF}; add_header_(data); add_byte_(data, 0xB8); diff --git a/components/zehnder/zehnder.h b/components/zehnder/zehnder.h index a59ed79..c3d3b3b 100644 --- a/components/zehnder/zehnder.h +++ b/components/zehnder/zehnder.h @@ -8,10 +8,9 @@ namespace esphome { namespace zehnder { -class ZehnderComponent : public climate::Climate, - public PollingComponent { +class ZehnderComponent : public climate::Climate, public PollingComponent { public: - explicit ZehnderComponent(): Climate() {}; + explicit ZehnderComponent() : Climate() {}; // Component. void setup() override;