mirror of
https://github.com/esphome/esphome.git
synced 2025-09-16 10:12:21 +01:00
Consolidate subscribe/unsubscribe messages
This commit is contained in:
@@ -71,8 +71,7 @@ service APIConnection {
|
|||||||
rpc alarm_control_panel_command (AlarmControlPanelCommandRequest) returns (void) {}
|
rpc alarm_control_panel_command (AlarmControlPanelCommandRequest) returns (void) {}
|
||||||
|
|
||||||
rpc zwave_proxy_frame(ZWaveProxyFrame) returns (void) {}
|
rpc zwave_proxy_frame(ZWaveProxyFrame) returns (void) {}
|
||||||
rpc zwave_proxy_subscribe(ZWaveProxySubscribeRequest) returns (void) {}
|
rpc zwave_proxy_request(ZWaveProxyRequest) returns (void) {}
|
||||||
rpc zwave_proxy_unsubscribe(ZWaveProxyUnsubscribeRequest) returns (void) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2296,16 +2295,14 @@ message ZWaveProxyFrame {
|
|||||||
bytes data = 1 [(fixed_array_size) = 257];
|
bytes data = 1 [(fixed_array_size) = 257];
|
||||||
}
|
}
|
||||||
|
|
||||||
message ZWaveProxySubscribeRequest {
|
enum ZWaveProxyRequestType {
|
||||||
|
ZWAVE_PROXY_REQUEST_TYPE_SUBSCRIBE = 0;
|
||||||
|
ZWAVE_PROXY_REQUEST_TYPE_UNSUBSCRIBE = 1;
|
||||||
|
}
|
||||||
|
message ZWaveProxyRequest {
|
||||||
option (id) = 129;
|
option (id) = 129;
|
||||||
option (source) = SOURCE_CLIENT;
|
option (source) = SOURCE_CLIENT;
|
||||||
option (ifdef) = "USE_ZWAVE_PROXY";
|
option (ifdef) = "USE_ZWAVE_PROXY";
|
||||||
|
|
||||||
uint32 flags = 1;
|
ZWaveProxyRequestType type = 1;
|
||||||
}
|
|
||||||
|
|
||||||
message ZWaveProxyUnsubscribeRequest {
|
|
||||||
option (id) = 130;
|
|
||||||
option (source) = SOURCE_CLIENT;
|
|
||||||
option (ifdef) = "USE_ZWAVE_PROXY";
|
|
||||||
}
|
}
|
||||||
|
@@ -1217,12 +1217,8 @@ void APIConnection::zwave_proxy_frame(const ZWaveProxyFrame &msg) {
|
|||||||
zwave_proxy::global_zwave_proxy->send_frame(msg.data, msg.data_len);
|
zwave_proxy::global_zwave_proxy->send_frame(msg.data, msg.data_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIConnection::zwave_proxy_subscribe(const ZWaveProxySubscribeRequest &msg) {
|
void APIConnection::zwave_proxy_request(const ZWaveProxyRequest &msg) {
|
||||||
zwave_proxy::global_zwave_proxy->subscribe_api_connection(this, msg.flags);
|
zwave_proxy::global_zwave_proxy->zwave_proxy_request(this, msg.type);
|
||||||
}
|
|
||||||
|
|
||||||
void APIConnection::zwave_proxy_unsubscribe(const ZWaveProxyUnsubscribeRequest &msg) {
|
|
||||||
zwave_proxy::global_zwave_proxy->unsubscribe_api_connection(this);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -173,8 +173,7 @@ class APIConnection final : public APIServerConnection {
|
|||||||
|
|
||||||
#ifdef USE_ZWAVE_PROXY
|
#ifdef USE_ZWAVE_PROXY
|
||||||
void zwave_proxy_frame(const ZWaveProxyFrame &msg) override;
|
void zwave_proxy_frame(const ZWaveProxyFrame &msg) override;
|
||||||
void zwave_proxy_subscribe(const ZWaveProxySubscribeRequest &msg) override;
|
void zwave_proxy_request(const ZWaveProxyRequest &msg) override;
|
||||||
void zwave_proxy_unsubscribe(const ZWaveProxyUnsubscribeRequest &msg) override;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_ALARM_CONTROL_PANEL
|
#ifdef USE_ALARM_CONTROL_PANEL
|
||||||
|
@@ -3044,10 +3044,10 @@ bool ZWaveProxyFrame::decode_length(uint32_t field_id, ProtoLengthDelimited valu
|
|||||||
}
|
}
|
||||||
void ZWaveProxyFrame::encode(ProtoWriteBuffer buffer) const { buffer.encode_bytes(1, this->data, this->data_len); }
|
void ZWaveProxyFrame::encode(ProtoWriteBuffer buffer) const { buffer.encode_bytes(1, this->data, this->data_len); }
|
||||||
void ZWaveProxyFrame::calculate_size(ProtoSize &size) const { size.add_length(1, this->data_len); }
|
void ZWaveProxyFrame::calculate_size(ProtoSize &size) const { size.add_length(1, this->data_len); }
|
||||||
bool ZWaveProxySubscribeRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
bool ZWaveProxyRequest::decode_varint(uint32_t field_id, ProtoVarInt value) {
|
||||||
switch (field_id) {
|
switch (field_id) {
|
||||||
case 1:
|
case 1:
|
||||||
this->flags = value.as_uint32();
|
this->type = static_cast<enums::ZWaveProxyRequestType>(value.as_uint32());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@@ -276,6 +276,12 @@ enum UpdateCommand : uint32_t {
|
|||||||
UPDATE_COMMAND_CHECK = 2,
|
UPDATE_COMMAND_CHECK = 2,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_ZWAVE_PROXY
|
||||||
|
enum ZWaveProxyRequestType : uint32_t {
|
||||||
|
ZWAVE_PROXY_REQUEST_TYPE_SUBSCRIBE = 0,
|
||||||
|
ZWAVE_PROXY_REQUEST_TYPE_UNSUBSCRIBE = 1,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace enums
|
} // namespace enums
|
||||||
|
|
||||||
@@ -2937,14 +2943,14 @@ class ZWaveProxyFrame final : public ProtoDecodableMessage {
|
|||||||
protected:
|
protected:
|
||||||
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||||
};
|
};
|
||||||
class ZWaveProxySubscribeRequest final : public ProtoDecodableMessage {
|
class ZWaveProxyRequest final : public ProtoDecodableMessage {
|
||||||
public:
|
public:
|
||||||
static constexpr uint8_t MESSAGE_TYPE = 129;
|
static constexpr uint8_t MESSAGE_TYPE = 129;
|
||||||
static constexpr uint8_t ESTIMATED_SIZE = 4;
|
static constexpr uint8_t ESTIMATED_SIZE = 2;
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
const char *message_name() const override { return "z_wave_proxy_subscribe_request"; }
|
const char *message_name() const override { return "z_wave_proxy_request"; }
|
||||||
#endif
|
#endif
|
||||||
uint32_t flags{0};
|
enums::ZWaveProxyRequestType type{};
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
void dump_to(std::string &out) const override;
|
void dump_to(std::string &out) const override;
|
||||||
#endif
|
#endif
|
||||||
@@ -2952,19 +2958,6 @@ class ZWaveProxySubscribeRequest final : public ProtoDecodableMessage {
|
|||||||
protected:
|
protected:
|
||||||
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
bool decode_varint(uint32_t field_id, ProtoVarInt value) override;
|
||||||
};
|
};
|
||||||
class ZWaveProxyUnsubscribeRequest final : public ProtoMessage {
|
|
||||||
public:
|
|
||||||
static constexpr uint8_t MESSAGE_TYPE = 130;
|
|
||||||
static constexpr uint8_t ESTIMATED_SIZE = 0;
|
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
|
||||||
const char *message_name() const override { return "z_wave_proxy_unsubscribe_request"; }
|
|
||||||
#endif
|
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
|
||||||
void dump_to(std::string &out) const override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace esphome::api
|
} // namespace esphome::api
|
||||||
|
@@ -655,6 +655,18 @@ template<> const char *proto_enum_to_string<enums::UpdateCommand>(enums::UpdateC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_ZWAVE_PROXY
|
||||||
|
template<> const char *proto_enum_to_string<enums::ZWaveProxyRequestType>(enums::ZWaveProxyRequestType value) {
|
||||||
|
switch (value) {
|
||||||
|
case enums::ZWAVE_PROXY_REQUEST_TYPE_SUBSCRIBE:
|
||||||
|
return "ZWAVE_PROXY_REQUEST_TYPE_SUBSCRIBE";
|
||||||
|
case enums::ZWAVE_PROXY_REQUEST_TYPE_UNSUBSCRIBE:
|
||||||
|
return "ZWAVE_PROXY_REQUEST_TYPE_UNSUBSCRIBE";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void HelloRequest::dump_to(std::string &out) const {
|
void HelloRequest::dump_to(std::string &out) const {
|
||||||
MessageDumpHelper helper(out, "HelloRequest");
|
MessageDumpHelper helper(out, "HelloRequest");
|
||||||
@@ -2118,8 +2130,10 @@ void ZWaveProxyFrame::dump_to(std::string &out) const {
|
|||||||
out.append(format_hex_pretty(this->data, this->data_len));
|
out.append(format_hex_pretty(this->data, this->data_len));
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
}
|
}
|
||||||
void ZWaveProxySubscribeRequest::dump_to(std::string &out) const { dump_field(out, "flags", this->flags); }
|
void ZWaveProxyRequest::dump_to(std::string &out) const {
|
||||||
void ZWaveProxyUnsubscribeRequest::dump_to(std::string &out) const { out.append("ZWaveProxyUnsubscribeRequest {}"); }
|
MessageDumpHelper helper(out, "ZWaveProxyRequest");
|
||||||
|
dump_field(out, "type", static_cast<enums::ZWaveProxyRequestType>(this->type));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace esphome::api
|
} // namespace esphome::api
|
||||||
|
@@ -608,24 +608,13 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ZWAVE_PROXY
|
#ifdef USE_ZWAVE_PROXY
|
||||||
case ZWaveProxySubscribeRequest::MESSAGE_TYPE: {
|
case ZWaveProxyRequest::MESSAGE_TYPE: {
|
||||||
ZWaveProxySubscribeRequest msg;
|
ZWaveProxyRequest msg;
|
||||||
msg.decode(msg_data, msg_size);
|
msg.decode(msg_data, msg_size);
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||||
ESP_LOGVV(TAG, "on_z_wave_proxy_subscribe_request: %s", msg.dump().c_str());
|
ESP_LOGVV(TAG, "on_z_wave_proxy_request: %s", msg.dump().c_str());
|
||||||
#endif
|
#endif
|
||||||
this->on_z_wave_proxy_subscribe_request(msg);
|
this->on_z_wave_proxy_request(msg);
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef USE_ZWAVE_PROXY
|
|
||||||
case ZWaveProxyUnsubscribeRequest::MESSAGE_TYPE: {
|
|
||||||
ZWaveProxyUnsubscribeRequest msg;
|
|
||||||
// Empty message: no decode needed
|
|
||||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
|
||||||
ESP_LOGVV(TAG, "on_z_wave_proxy_unsubscribe_request: %s", msg.dump().c_str());
|
|
||||||
#endif
|
|
||||||
this->on_z_wave_proxy_unsubscribe_request(msg);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -950,16 +939,9 @@ void APIServerConnection::on_z_wave_proxy_frame(const ZWaveProxyFrame &msg) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ZWAVE_PROXY
|
#ifdef USE_ZWAVE_PROXY
|
||||||
void APIServerConnection::on_z_wave_proxy_subscribe_request(const ZWaveProxySubscribeRequest &msg) {
|
void APIServerConnection::on_z_wave_proxy_request(const ZWaveProxyRequest &msg) {
|
||||||
if (this->check_authenticated_()) {
|
if (this->check_authenticated_()) {
|
||||||
this->zwave_proxy_subscribe(msg);
|
this->zwave_proxy_request(msg);
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef USE_ZWAVE_PROXY
|
|
||||||
void APIServerConnection::on_z_wave_proxy_unsubscribe_request(const ZWaveProxyUnsubscribeRequest &msg) {
|
|
||||||
if (this->check_authenticated_()) {
|
|
||||||
this->zwave_proxy_unsubscribe(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -210,10 +210,7 @@ class APIServerConnectionBase : public ProtoService {
|
|||||||
virtual void on_z_wave_proxy_frame(const ZWaveProxyFrame &value){};
|
virtual void on_z_wave_proxy_frame(const ZWaveProxyFrame &value){};
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ZWAVE_PROXY
|
#ifdef USE_ZWAVE_PROXY
|
||||||
virtual void on_z_wave_proxy_subscribe_request(const ZWaveProxySubscribeRequest &value){};
|
virtual void on_z_wave_proxy_request(const ZWaveProxyRequest &value){};
|
||||||
#endif
|
|
||||||
#ifdef USE_ZWAVE_PROXY
|
|
||||||
virtual void on_z_wave_proxy_unsubscribe_request(const ZWaveProxyUnsubscribeRequest &value){};
|
|
||||||
#endif
|
#endif
|
||||||
protected:
|
protected:
|
||||||
void read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) override;
|
void read_message(uint32_t msg_size, uint32_t msg_type, uint8_t *msg_data) override;
|
||||||
@@ -346,10 +343,7 @@ class APIServerConnection : public APIServerConnectionBase {
|
|||||||
virtual void zwave_proxy_frame(const ZWaveProxyFrame &msg) = 0;
|
virtual void zwave_proxy_frame(const ZWaveProxyFrame &msg) = 0;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ZWAVE_PROXY
|
#ifdef USE_ZWAVE_PROXY
|
||||||
virtual void zwave_proxy_subscribe(const ZWaveProxySubscribeRequest &msg) = 0;
|
virtual void zwave_proxy_request(const ZWaveProxyRequest &msg) = 0;
|
||||||
#endif
|
|
||||||
#ifdef USE_ZWAVE_PROXY
|
|
||||||
virtual void zwave_proxy_unsubscribe(const ZWaveProxyUnsubscribeRequest &msg) = 0;
|
|
||||||
#endif
|
#endif
|
||||||
protected:
|
protected:
|
||||||
void on_hello_request(const HelloRequest &msg) override;
|
void on_hello_request(const HelloRequest &msg) override;
|
||||||
@@ -477,10 +471,7 @@ class APIServerConnection : public APIServerConnectionBase {
|
|||||||
void on_z_wave_proxy_frame(const ZWaveProxyFrame &msg) override;
|
void on_z_wave_proxy_frame(const ZWaveProxyFrame &msg) override;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ZWAVE_PROXY
|
#ifdef USE_ZWAVE_PROXY
|
||||||
void on_z_wave_proxy_subscribe_request(const ZWaveProxySubscribeRequest &msg) override;
|
void on_z_wave_proxy_request(const ZWaveProxyRequest &msg) override;
|
||||||
#endif
|
|
||||||
#ifdef USE_ZWAVE_PROXY
|
|
||||||
void on_z_wave_proxy_unsubscribe_request(const ZWaveProxyUnsubscribeRequest &msg) override;
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -45,20 +45,26 @@ void ZWaveProxy::loop() {
|
|||||||
|
|
||||||
void ZWaveProxy::dump_config() { ESP_LOGCONFIG(TAG, "Z-Wave Proxy"); }
|
void ZWaveProxy::dump_config() { ESP_LOGCONFIG(TAG, "Z-Wave Proxy"); }
|
||||||
|
|
||||||
void ZWaveProxy::subscribe_api_connection(api::APIConnection *api_connection, uint32_t flags) {
|
void ZWaveProxy::zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type) {
|
||||||
if (this->api_connection_ != nullptr) {
|
switch (type) {
|
||||||
ESP_LOGE(TAG, "Only one API subscription is allowed at a time");
|
case api::enums::ZWAVE_PROXY_REQUEST_TYPE_SUBSCRIBE:
|
||||||
return;
|
if (this->api_connection_ != nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Only one API subscription is allowed at a time");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->api_connection_ = api_connection;
|
||||||
|
ESP_LOGV(TAG, "API connection is now subscribed");
|
||||||
|
break;
|
||||||
|
case api::enums::ZWAVE_PROXY_REQUEST_TYPE_UNSUBSCRIBE:
|
||||||
|
if (this->api_connection_ != api_connection) {
|
||||||
|
ESP_LOGV(TAG, "API connection is not subscribed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->api_connection_ = nullptr;
|
||||||
|
default:
|
||||||
|
ESP_LOGW(TAG, "Unknown request type: %d", type);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
this->api_connection_ = api_connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZWaveProxy::unsubscribe_api_connection(api::APIConnection *api_connection) {
|
|
||||||
if (this->api_connection_ != api_connection) {
|
|
||||||
ESP_LOGV(TAG, "API connection is not subscribed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this->api_connection_ = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZWaveProxy::send_frame(const uint8_t *data, size_t length) {
|
void ZWaveProxy::send_frame(const uint8_t *data, size_t length) {
|
||||||
|
@@ -41,8 +41,7 @@ class ZWaveProxy : public uart::UARTDevice, public Component {
|
|||||||
void loop() override;
|
void loop() override;
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
|
|
||||||
void subscribe_api_connection(api::APIConnection *api_connection, uint32_t flags);
|
void zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type);
|
||||||
void unsubscribe_api_connection(api::APIConnection *api_connection);
|
|
||||||
api::APIConnection *get_api_connection() { return this->api_connection_; }
|
api::APIConnection *get_api_connection() { return this->api_connection_; }
|
||||||
|
|
||||||
uint32_t get_feature_flags() const { return ZWaveProxyFeature::FEATURE_ZWAVE_PROXY_ENABLED; }
|
uint32_t get_feature_flags() const { return ZWaveProxyFeature::FEATURE_ZWAVE_PROXY_ENABLED; }
|
||||||
|
Reference in New Issue
Block a user