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