1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

[xiaomi_*] Use stack-based hex formatting for bindkey logging (#12798)

This commit is contained in:
J. Nick Koston
2026-01-01 20:25:12 -10:00
committed by GitHub
parent a828abf53d
commit 4e8c02b396
8 changed files with 40 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
#include "xiaomi_cgd1.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
@@ -8,11 +9,14 @@ namespace xiaomi_cgd1 {
static const char *const TAG = "xiaomi_cgd1";
static constexpr size_t CGD1_BINDKEY_SIZE = 16;
void XiaomiCGD1::dump_config() {
char bindkey_hex[format_hex_pretty_size(CGD1_BINDKEY_SIZE)];
ESP_LOGCONFIG(TAG,
"Xiaomi CGD1\n"
" Bindkey: %s",
format_hex_pretty(this->bindkey_, 16).c_str());
format_hex_pretty_to(bindkey_hex, this->bindkey_, CGD1_BINDKEY_SIZE, '.'));
LOG_SENSOR(" ", "Temperature", this->temperature_);
LOG_SENSOR(" ", "Humidity", this->humidity_);
LOG_SENSOR(" ", "Battery Level", this->battery_level_);

View File

@@ -1,4 +1,5 @@
#include "xiaomi_cgdk2.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
@@ -8,11 +9,14 @@ namespace xiaomi_cgdk2 {
static const char *const TAG = "xiaomi_cgdk2";
static constexpr size_t CGDK2_BINDKEY_SIZE = 16;
void XiaomiCGDK2::dump_config() {
char bindkey_hex[format_hex_pretty_size(CGDK2_BINDKEY_SIZE)];
ESP_LOGCONFIG(TAG,
"Xiaomi CGDK2\n"
" Bindkey: %s",
format_hex_pretty(this->bindkey_, 16).c_str());
format_hex_pretty_to(bindkey_hex, this->bindkey_, CGDK2_BINDKEY_SIZE, '.'));
LOG_SENSOR(" ", "Temperature", this->temperature_);
LOG_SENSOR(" ", "Humidity", this->humidity_);
LOG_SENSOR(" ", "Battery Level", this->battery_level_);

View File

@@ -1,4 +1,5 @@
#include "xiaomi_cgg1.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
@@ -8,11 +9,14 @@ namespace xiaomi_cgg1 {
static const char *const TAG = "xiaomi_cgg1";
static constexpr size_t CGG1_BINDKEY_SIZE = 16;
void XiaomiCGG1::dump_config() {
char bindkey_hex[format_hex_pretty_size(CGG1_BINDKEY_SIZE)];
ESP_LOGCONFIG(TAG,
"Xiaomi CGG1\n"
" Bindkey: %s",
format_hex_pretty(this->bindkey_, 16).c_str());
format_hex_pretty_to(bindkey_hex, this->bindkey_, CGG1_BINDKEY_SIZE, '.'));
LOG_SENSOR(" ", "Temperature", this->temperature_);
LOG_SENSOR(" ", "Humidity", this->humidity_);
LOG_SENSOR(" ", "Battery Level", this->battery_level_);

View File

@@ -1,4 +1,5 @@
#include "xiaomi_lywsd02mmc.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
@@ -8,11 +9,14 @@ namespace xiaomi_lywsd02mmc {
static const char *const TAG = "xiaomi_lywsd02mmc";
static constexpr size_t LYWSD02MMC_BINDKEY_SIZE = 16;
void XiaomiLYWSD02MMC::dump_config() {
char bindkey_hex[format_hex_pretty_size(LYWSD02MMC_BINDKEY_SIZE)];
ESP_LOGCONFIG(TAG,
"Xiaomi LYWSD02MMC\n"
" Bindkey: %s",
format_hex_pretty(this->bindkey_, 16).c_str());
format_hex_pretty_to(bindkey_hex, this->bindkey_, LYWSD02MMC_BINDKEY_SIZE, '.'));
LOG_SENSOR(" ", "Temperature", this->temperature_);
LOG_SENSOR(" ", "Humidity", this->humidity_);
LOG_SENSOR(" ", "Battery Level", this->battery_level_);

View File

@@ -1,4 +1,5 @@
#include "xiaomi_lywsd03mmc.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
@@ -8,11 +9,14 @@ namespace xiaomi_lywsd03mmc {
static const char *const TAG = "xiaomi_lywsd03mmc";
static constexpr size_t LYWSD03MMC_BINDKEY_SIZE = 16;
void XiaomiLYWSD03MMC::dump_config() {
char bindkey_hex[format_hex_pretty_size(LYWSD03MMC_BINDKEY_SIZE)];
ESP_LOGCONFIG(TAG,
"Xiaomi LYWSD03MMC\n"
" Bindkey: %s",
format_hex_pretty(this->bindkey_, 16).c_str());
format_hex_pretty_to(bindkey_hex, this->bindkey_, LYWSD03MMC_BINDKEY_SIZE, '.'));
LOG_SENSOR(" ", "Temperature", this->temperature_);
LOG_SENSOR(" ", "Humidity", this->humidity_);
LOG_SENSOR(" ", "Battery Level", this->battery_level_);

View File

@@ -1,4 +1,5 @@
#include "xiaomi_mhoc401.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
@@ -8,11 +9,14 @@ namespace xiaomi_mhoc401 {
static const char *const TAG = "xiaomi_mhoc401";
static constexpr size_t MHOC401_BINDKEY_SIZE = 16;
void XiaomiMHOC401::dump_config() {
char bindkey_hex[format_hex_pretty_size(MHOC401_BINDKEY_SIZE)];
ESP_LOGCONFIG(TAG,
"Xiaomi MHOC401\n"
" Bindkey: %s",
format_hex_pretty(this->bindkey_, 16).c_str());
format_hex_pretty_to(bindkey_hex, this->bindkey_, MHOC401_BINDKEY_SIZE, '.'));
LOG_SENSOR(" ", "Temperature", this->temperature_);
LOG_SENSOR(" ", "Humidity", this->humidity_);
LOG_SENSOR(" ", "Battery Level", this->battery_level_);

View File

@@ -1,4 +1,5 @@
#include "xiaomi_rtcgq02lm.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
@@ -8,9 +9,12 @@ namespace xiaomi_rtcgq02lm {
static const char *const TAG = "xiaomi_rtcgq02lm";
static constexpr size_t RTCGQ02LM_BINDKEY_SIZE = 16;
void XiaomiRTCGQ02LM::dump_config() {
char bindkey_hex[format_hex_pretty_size(RTCGQ02LM_BINDKEY_SIZE)];
ESP_LOGCONFIG(TAG, "Xiaomi RTCGQ02LM");
ESP_LOGCONFIG(TAG, " Bindkey: %s", format_hex_pretty(this->bindkey_, 16).c_str());
ESP_LOGCONFIG(TAG, " Bindkey: %s", format_hex_pretty_to(bindkey_hex, this->bindkey_, RTCGQ02LM_BINDKEY_SIZE, '.'));
#ifdef USE_BINARY_SENSOR
LOG_BINARY_SENSOR(" ", "Motion", this->motion_);
LOG_BINARY_SENSOR(" ", "Light", this->light_);

View File

@@ -1,4 +1,5 @@
#include "xiaomi_xmwsdj04mmc.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
@@ -8,9 +9,12 @@ namespace xiaomi_xmwsdj04mmc {
static const char *const TAG = "xiaomi_xmwsdj04mmc";
static constexpr size_t XMWSDJ04MMC_BINDKEY_SIZE = 16;
void XiaomiXMWSDJ04MMC::dump_config() {
char bindkey_hex[format_hex_pretty_size(XMWSDJ04MMC_BINDKEY_SIZE)];
ESP_LOGCONFIG(TAG, "Xiaomi XMWSDJ04MMC");
ESP_LOGCONFIG(TAG, " Bindkey: %s", format_hex_pretty(this->bindkey_, 16).c_str());
ESP_LOGCONFIG(TAG, " Bindkey: %s", format_hex_pretty_to(bindkey_hex, this->bindkey_, XMWSDJ04MMC_BINDKEY_SIZE, '.'));
LOG_SENSOR(" ", "Temperature", this->temperature_);
LOG_SENSOR(" ", "Humidity", this->humidity_);
LOG_SENSOR(" ", "Battery Level", this->battery_level_);