mirror of
https://github.com/esphome/esphome.git
synced 2025-10-08 04:43:46 +01:00
[zwave_proxy] Send HomeID upon client connect (#11037)
This commit is contained in:
@@ -1389,6 +1389,11 @@ void APIConnection::complete_authentication_() {
|
|||||||
this->send_time_request();
|
this->send_time_request();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_ZWAVE_PROXY
|
||||||
|
if (zwave_proxy::global_zwave_proxy != nullptr) {
|
||||||
|
zwave_proxy::global_zwave_proxy->api_connection_authenticated(this);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool APIConnection::send_hello_response(const HelloRequest &msg) {
|
bool APIConnection::send_hello_response(const HelloRequest &msg) {
|
||||||
|
@@ -101,15 +101,7 @@ void ZWaveProxy::process_uart_() {
|
|||||||
// Store the 4-byte Home ID, which starts at offset 4, and notify connected clients if it changed
|
// Store the 4-byte Home ID, which starts at offset 4, and notify connected clients if it changed
|
||||||
// The frame parser has already validated the checksum and ensured all bytes are present
|
// The frame parser has already validated the checksum and ensured all bytes are present
|
||||||
if (this->set_home_id(&this->buffer_[4])) {
|
if (this->set_home_id(&this->buffer_[4])) {
|
||||||
api::ZWaveProxyRequest msg;
|
this->send_homeid_changed_msg_();
|
||||||
msg.type = api::enums::ZWAVE_PROXY_REQUEST_TYPE_HOME_ID_CHANGE;
|
|
||||||
msg.data = this->home_id_.data();
|
|
||||||
msg.data_len = this->home_id_.size();
|
|
||||||
if (api::global_api_server != nullptr) {
|
|
||||||
// We could add code to manage a second subscription type, but, since this message is
|
|
||||||
// very infrequent and small, we simply send it to all clients
|
|
||||||
api::global_api_server->on_zwave_proxy_request(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ESP_LOGV(TAG, "Sending to client: %s", YESNO(this->api_connection_ != nullptr));
|
ESP_LOGV(TAG, "Sending to client: %s", YESNO(this->api_connection_ != nullptr));
|
||||||
@@ -135,6 +127,13 @@ void ZWaveProxy::dump_config() {
|
|||||||
format_hex_pretty(this->home_id_.data(), this->home_id_.size(), ':', false).c_str());
|
format_hex_pretty(this->home_id_.data(), this->home_id_.size(), ':', false).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ZWaveProxy::api_connection_authenticated(api::APIConnection *conn) {
|
||||||
|
if (this->home_id_ready_) {
|
||||||
|
// If a client just authenticated & HomeID is ready, send the current HomeID
|
||||||
|
this->send_homeid_changed_msg_(conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ZWaveProxy::zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type) {
|
void ZWaveProxy::zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case api::enums::ZWAVE_PROXY_REQUEST_TYPE_SUBSCRIBE:
|
case api::enums::ZWAVE_PROXY_REQUEST_TYPE_SUBSCRIBE:
|
||||||
@@ -178,6 +177,21 @@ void ZWaveProxy::send_frame(const uint8_t *data, size_t length) {
|
|||||||
this->write_array(data, length);
|
this->write_array(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ZWaveProxy::send_homeid_changed_msg_(api::APIConnection *conn) {
|
||||||
|
api::ZWaveProxyRequest msg;
|
||||||
|
msg.type = api::enums::ZWAVE_PROXY_REQUEST_TYPE_HOME_ID_CHANGE;
|
||||||
|
msg.data = this->home_id_.data();
|
||||||
|
msg.data_len = this->home_id_.size();
|
||||||
|
if (conn != nullptr) {
|
||||||
|
// Send to specific connection
|
||||||
|
conn->send_message(msg, api::ZWaveProxyRequest::MESSAGE_TYPE);
|
||||||
|
} else if (api::global_api_server != nullptr) {
|
||||||
|
// We could add code to manage a second subscription type, but, since this message is
|
||||||
|
// very infrequent and small, we simply send it to all clients
|
||||||
|
api::global_api_server->on_zwave_proxy_request(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ZWaveProxy::send_simple_command_(const uint8_t command_id) {
|
void ZWaveProxy::send_simple_command_(const uint8_t command_id) {
|
||||||
// Send a simple Z-Wave command with no parameters
|
// Send a simple Z-Wave command with no parameters
|
||||||
// Frame format: [SOF][LENGTH][TYPE][CMD][CHECKSUM]
|
// Frame format: [SOF][LENGTH][TYPE][CMD][CHECKSUM]
|
||||||
|
@@ -49,6 +49,7 @@ class ZWaveProxy : public uart::UARTDevice, public Component {
|
|||||||
float get_setup_priority() const override;
|
float get_setup_priority() const override;
|
||||||
bool can_proceed() override;
|
bool can_proceed() override;
|
||||||
|
|
||||||
|
void api_connection_authenticated(api::APIConnection *conn);
|
||||||
void zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type);
|
void zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type);
|
||||||
api::APIConnection *get_api_connection() { return this->api_connection_; }
|
api::APIConnection *get_api_connection() { return this->api_connection_; }
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ class ZWaveProxy : public uart::UARTDevice, public Component {
|
|||||||
void send_frame(const uint8_t *data, size_t length);
|
void send_frame(const uint8_t *data, size_t length);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void send_homeid_changed_msg_(api::APIConnection *conn = nullptr);
|
||||||
void send_simple_command_(uint8_t command_id);
|
void send_simple_command_(uint8_t command_id);
|
||||||
bool parse_byte_(uint8_t byte); // Returns true if frame parsing was completed (a frame is ready in the buffer)
|
bool parse_byte_(uint8_t byte); // Returns true if frame parsing was completed (a frame is ready in the buffer)
|
||||||
void parse_start_(uint8_t byte);
|
void parse_start_(uint8_t byte);
|
||||||
|
Reference in New Issue
Block a user