ESPHome 2026.1.0-dev
Loading...
Searching...
No Matches
zwave_proxy.h
Go to the documentation of this file.
1#pragma once
2
4#ifdef USE_API
5
11
12#include <array>
13
14namespace esphome::zwave_proxy {
15
16static constexpr size_t MAX_ZWAVE_FRAME_SIZE = 257; // Maximum Z-Wave frame size
17static constexpr size_t ZWAVE_HOME_ID_SIZE = 4; // Z-Wave Home ID size in bytes
18
27
40
41enum ZWaveProxyFeature : uint32_t {
43};
44
45class ZWaveProxy : public uart::UARTDevice, public Component {
46 public:
47 ZWaveProxy();
48
49 void setup() override;
50 void loop() override;
51 void dump_config() override;
52 float get_setup_priority() const override;
53 bool can_proceed() override;
54
58
60 uint32_t get_home_id() {
61 return encode_uint32(this->home_id_[0], this->home_id_[1], this->home_id_[2], this->home_id_[3]);
62 }
63 bool set_home_id(const uint8_t *new_home_id); // Store a new home ID. Returns true if it changed.
64
65 void send_frame(const uint8_t *data, size_t length);
66
67 protected:
68 void send_homeid_changed_msg_(api::APIConnection *conn = nullptr);
69 void send_simple_command_(uint8_t command_id);
70 bool parse_byte_(uint8_t byte); // Returns true if frame parsing was completed (a frame is ready in the buffer)
71 void parse_start_(uint8_t byte);
72 bool response_handler_();
73 void process_uart_(); // Process all available UART data
74
75 // Pre-allocated message - always ready to send
77 std::array<uint8_t, MAX_ZWAVE_FRAME_SIZE> buffer_; // Fixed buffer for incoming data
78 std::array<uint8_t, ZWAVE_HOME_ID_SIZE> home_id_{}; // Fixed buffer for home ID
79
80 // Pointers and 32-bit values (aligned together)
81 api::APIConnection *api_connection_{nullptr}; // Current subscribed client
82 uint32_t setup_time_{0}; // Time when setup() was called
83
84 // 8-bit values (grouped together to minimize padding)
85 uint8_t buffer_index_{0}; // Index for populating the data buffer
86 uint8_t end_frame_after_{0}; // Payload reception ends after this index
87 uint8_t last_response_{0}; // Last response type sent
89 bool in_bootloader_{false}; // True if the device is detected to be in bootloader mode
90 bool home_id_ready_{false}; // True when home ID has been received from Z-Wave module
91};
92
93extern ZWaveProxy *global_zwave_proxy; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
94
95} // namespace esphome::zwave_proxy
96
97#endif // USE_API
void zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type)
api::ZWaveProxyFrame outgoing_proto_msg_
Definition zwave_proxy.h:76
void send_frame(const uint8_t *data, size_t length)
uint32_t get_feature_flags() const
Definition zwave_proxy.h:59
void send_homeid_changed_msg_(api::APIConnection *conn=nullptr)
void send_simple_command_(uint8_t command_id)
bool set_home_id(const uint8_t *new_home_id)
void api_connection_authenticated(api::APIConnection *conn)
api::APIConnection * get_api_connection()
Definition zwave_proxy.h:57
ZWaveParsingState parsing_state_
Definition zwave_proxy.h:88
std::array< uint8_t, MAX_ZWAVE_FRAME_SIZE > buffer_
Definition zwave_proxy.h:77
api::APIConnection * api_connection_
Definition zwave_proxy.h:81
float get_setup_priority() const override
std::array< uint8_t, ZWAVE_HOME_ID_SIZE > home_id_
Definition zwave_proxy.h:78
uint16_t type
ZWaveProxy * global_zwave_proxy
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
Definition helpers.h:428
uint16_t length
Definition tt21100.cpp:0