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