22#include " esphome/core/log.h"
33#include " esphome/core/version.h"
44
5- #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025, 12, 0)
6- #define ADDR_STR (x ) x
7- #else
8- #define ADDR_STR (x ) (x).c_str()
9- #endif
10-
11- #ifdef USE_ESP32
12-
135namespace esphome {
146namespace atorch_dl24 {
157
168static const char *const TAG = " atorch_dl24" ;
179
18- static const uint16_t DL24_SERVICE_UUID = 0xFFE0 ;
19- static const uint16_t DL24_REPORT_CHARACTERISTIC_UUID = 0xFFE1 ;
20- static const uint16_t DL24_COMMAND_CHARACTERISTIC_UUID = 0xFFE2 ;
21-
2210static const uint8_t START_OF_FRAME_BYTE1 = 0xFF ;
2311static const uint8_t START_OF_FRAME_BYTE2 = 0x55 ;
2412
2513static const uint8_t MESSAGE_TYPE_REPORT = 0x01 ;
2614static const uint8_t MESSAGE_TYPE_REPLY = 0x02 ;
27- static const uint8_t MESSAGE_TYPE_COMMAND = 0x11 ;
2815
2916static const uint8_t DEVICE_TYPE_AC_METER = 0x01 ;
3017static const uint8_t DEVICE_TYPE_DC_METER = 0x02 ;
@@ -34,6 +21,19 @@ static const uint8_t COMMAND_SUCCESS = 0x01;
3421static const uint8_t COMMAND_FAILED = 0x02 ;
3522static const uint8_t COMMAND_UNSUPPORTED = 0x03 ;
3623
24+ #ifdef USE_ESP32
25+ static const uint16_t DL24_SERVICE_UUID = 0xFFE0 ;
26+ static const uint16_t DL24_REPORT_CHARACTERISTIC_UUID = 0xFFE1 ;
27+ static const uint16_t DL24_COMMAND_CHARACTERISTIC_UUID = 0xFFE2 ;
28+ static const uint8_t MESSAGE_TYPE_COMMAND = 0x11 ;
29+
30+ #if ESPHOME_VERSION_CODE >= VERSION_CODE(2025, 12, 0)
31+ #define ADDR_STR (x ) x
32+ #else
33+ #define ADDR_STR (x ) (x).c_str()
34+ #endif
35+ #endif
36+
3737uint8_t crc (const uint8_t data[], const uint16_t len) {
3838 uint8_t crc = 0 ;
3939
@@ -45,6 +45,7 @@ uint8_t crc(const uint8_t data[], const uint16_t len) {
4545}
4646
4747bool AtorchDL24::write_register (uint8_t device_type, uint8_t address, uint32_t value) {
48+ #ifdef USE_ESP32
4849 uint8_t frame[10 ];
4950 frame[0 ] = START_OF_FRAME_BYTE1 ;
5051 frame[1 ] = START_OF_FRAME_BYTE2 ;
@@ -66,6 +67,9 @@ bool AtorchDL24::write_register(uint8_t device_type, uint8_t address, uint32_t v
6667 ESP_LOGW (TAG , " [%s] esp_ble_gattc_write_char failed, status=%d" , ADDR_STR (this ->parent_ ->address_str ()), status);
6768
6869 return (status == 0 );
70+ #else
71+ return false ;
72+ #endif
6973}
7074
7175void AtorchDL24::dump_config () {
@@ -87,6 +91,7 @@ void AtorchDL24::dump_config() {
8791 LOG_TEXT_SENSOR (" " , " Runtime Formatted" , this ->runtime_formatted_text_sensor_ );
8892}
8993
94+ #ifdef USE_ESP32
9095void AtorchDL24::gattc_event_handler (esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
9196 esp_ble_gattc_cb_param_t *param) {
9297 switch (event) {
@@ -169,6 +174,7 @@ void AtorchDL24::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t g
169174 break ;
170175 }
171176}
177+ #endif
172178
173179// AC Meter
174180//
@@ -483,5 +489,3 @@ void AtorchDL24::publish_state_(text_sensor::TextSensor *text_sensor, const std:
483489
484490} // namespace atorch_dl24
485491} // namespace esphome
486-
487- #endif
0 commit comments