mirror of
https://github.com/esphome/esphome.git
synced 2025-09-01 10:52:19 +01:00
preen
This commit is contained in:
@@ -70,10 +70,9 @@ service APIConnection {
|
||||
|
||||
rpc alarm_control_panel_command (AlarmControlPanelCommandRequest) returns (void) {}
|
||||
|
||||
rpc zwave_proxy_frame_to_device(ZWaveProxyFrameToDevice) returns (void) {}
|
||||
rpc zwave_proxy_subscribe(ZWaveProxySubscribeRequest) returns (void) {}
|
||||
rpc zwave_proxy_unsubscribe(ZWaveProxyUnsubscribeRequest) returns (void) {}
|
||||
rpc zwave_proxy_from_device(ZWaveProxyFromDeviceRequest) returns (void) {}
|
||||
rpc zwave_proxy_to_device(ZWaveProxyToDeviceRequest) returns (void) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -2286,24 +2285,17 @@ message UpdateCommandRequest {
|
||||
|
||||
// ==================== Z-WAVE ====================
|
||||
|
||||
message ZWaveProxyFromDeviceRequest {
|
||||
message ZWaveProxyFrameFromDevice {
|
||||
option (id) = 128;
|
||||
option (source) = SOURCE_CLIENT;
|
||||
option (source) = SOURCE_SERVER;
|
||||
option (ifdef) = "USE_ZWAVE_PROXY";
|
||||
option (no_delay) = true;
|
||||
|
||||
string data = 1;
|
||||
}
|
||||
|
||||
message ZWaveProxyFromDeviceResponse {
|
||||
message ZWaveProxyFrameToDevice {
|
||||
option (id) = 129;
|
||||
option (source) = SOURCE_SERVER;
|
||||
option (ifdef) = "USE_ZWAVE_PROXY";
|
||||
option (no_delay) = true;
|
||||
}
|
||||
|
||||
message ZWaveProxyToDeviceRequest {
|
||||
option (id) = 130;
|
||||
option (source) = SOURCE_CLIENT;
|
||||
option (ifdef) = "USE_ZWAVE_PROXY";
|
||||
option (no_delay) = true;
|
||||
@@ -2311,15 +2303,8 @@ message ZWaveProxyToDeviceRequest {
|
||||
string data = 1;
|
||||
}
|
||||
|
||||
message ZWaveProxyToDeviceResponse {
|
||||
option (id) = 131;
|
||||
option (source) = SOURCE_SERVER;
|
||||
option (ifdef) = "USE_ZWAVE_PROXY";
|
||||
option (no_delay) = true;
|
||||
}
|
||||
|
||||
message ZWaveProxySubscribeRequest {
|
||||
option (id) = 132;
|
||||
option (id) = 130;
|
||||
option (source) = SOURCE_CLIENT;
|
||||
option (ifdef) = "USE_ZWAVE_PROXY";
|
||||
|
||||
@@ -2327,7 +2312,7 @@ message ZWaveProxySubscribeRequest {
|
||||
}
|
||||
|
||||
message ZWaveProxyUnsubscribeRequest {
|
||||
option (id) = 133;
|
||||
option (id) = 131;
|
||||
option (source) = SOURCE_CLIENT;
|
||||
option (ifdef) = "USE_ZWAVE_PROXY";
|
||||
}
|
||||
|
@@ -1207,6 +1207,10 @@ void APIConnection::voice_assistant_set_configuration(const VoiceAssistantSetCon
|
||||
#endif
|
||||
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void APIConnection::zwave_proxy_frame_to_device(const ZWaveProxyFrameToDevice &msg) {
|
||||
zwave_proxy::global_zwave_proxy->send_frame(msg.data);
|
||||
}
|
||||
|
||||
void APIConnection::zwave_proxy_subscribe(const ZWaveProxySubscribeRequest &msg) {
|
||||
zwave_proxy::global_zwave_proxy->subscribe_api_connection(this, msg.flags);
|
||||
}
|
||||
@@ -1214,14 +1218,6 @@ void APIConnection::zwave_proxy_subscribe(const ZWaveProxySubscribeRequest &msg)
|
||||
void APIConnection::zwave_proxy_unsubscribe(const ZWaveProxyUnsubscribeRequest &msg) {
|
||||
zwave_proxy::global_zwave_proxy->unsubscribe_api_connection(this);
|
||||
}
|
||||
|
||||
void APIConnection::zwave_proxy_from_device(const ZWaveProxyFromDeviceRequest &msg) {
|
||||
this->send_message(msg, ZWaveProxyFromDeviceRequest::MESSAGE_TYPE);
|
||||
}
|
||||
|
||||
void APIConnection::zwave_proxy_to_device(const ZWaveProxyToDeviceRequest &msg) {
|
||||
zwave_proxy::global_zwave_proxy->send_frame(msg.data);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
|
@@ -172,10 +172,9 @@ class APIConnection final : public APIServerConnection {
|
||||
#endif
|
||||
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void zwave_proxy_frame_to_device(const ZWaveProxyFrameToDevice &msg) override;
|
||||
void zwave_proxy_subscribe(const ZWaveProxySubscribeRequest &msg) override;
|
||||
void zwave_proxy_unsubscribe(const ZWaveProxyUnsubscribeRequest &msg) override;
|
||||
void zwave_proxy_from_device(const ZWaveProxyFromDeviceRequest &msg) override;
|
||||
void zwave_proxy_to_device(const ZWaveProxyToDeviceRequest &msg) override;
|
||||
#endif
|
||||
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
|
@@ -3008,17 +3008,9 @@ bool UpdateCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) {
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
bool ZWaveProxyFromDeviceRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) {
|
||||
switch (field_id) {
|
||||
case 1:
|
||||
this->data = value.as_string();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool ZWaveProxyToDeviceRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) {
|
||||
void ZWaveProxyFrameFromDevice::encode(ProtoWriteBuffer buffer) const { buffer.encode_string(1, this->data_ref_); }
|
||||
void ZWaveProxyFrameFromDevice::calculate_size(ProtoSize &size) const { size.add_length(1, this->data_ref_.size()); }
|
||||
bool ZWaveProxyFrameToDevice::decode_length(uint32_t field_id, ProtoLengthDelimited value) {
|
||||
switch (field_id) {
|
||||
case 1:
|
||||
this->data = value.as_string();
|
||||
|
@@ -2914,40 +2914,29 @@ class UpdateCommandRequest final : public CommandProtoMessage {
|
||||
};
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
class ZWaveProxyFromDeviceRequest final : public ProtoDecodableMessage {
|
||||
class ZWaveProxyFrameFromDevice final : public ProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 128;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 9;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "z_wave_proxy_from_device_request"; }
|
||||
const char *message_name() const override { return "z_wave_proxy_frame_from_device"; }
|
||||
#endif
|
||||
std::string data{};
|
||||
StringRef data_ref_{};
|
||||
void set_data(const StringRef &ref) { this->data_ref_ = ref; }
|
||||
void encode(ProtoWriteBuffer buffer) const override;
|
||||
void calculate_size(ProtoSize &size) const override;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
void dump_to(std::string &out) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||
};
|
||||
class ZWaveProxyFromDeviceResponse final : public ProtoMessage {
|
||||
class ZWaveProxyFrameToDevice final : public ProtoDecodableMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 129;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 0;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "z_wave_proxy_from_device_response"; }
|
||||
#endif
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
void dump_to(std::string &out) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
};
|
||||
class ZWaveProxyToDeviceRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 130;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 9;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "z_wave_proxy_to_device_request"; }
|
||||
const char *message_name() const override { return "z_wave_proxy_frame_to_device"; }
|
||||
#endif
|
||||
std::string data{};
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
@@ -2957,22 +2946,9 @@ class ZWaveProxyToDeviceRequest final : public ProtoDecodableMessage {
|
||||
protected:
|
||||
bool decode_length(uint32_t field_id, ProtoLengthDelimited value) override;
|
||||
};
|
||||
class ZWaveProxyToDeviceResponse final : public ProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 131;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 0;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "z_wave_proxy_to_device_response"; }
|
||||
#endif
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
void dump_to(std::string &out) const override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
};
|
||||
class ZWaveProxySubscribeRequest final : public ProtoDecodableMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 132;
|
||||
static constexpr uint8_t MESSAGE_TYPE = 130;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 4;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "z_wave_proxy_subscribe_request"; }
|
||||
@@ -2987,7 +2963,7 @@ class ZWaveProxySubscribeRequest final : public ProtoDecodableMessage {
|
||||
};
|
||||
class ZWaveProxyUnsubscribeRequest final : public ProtoMessage {
|
||||
public:
|
||||
static constexpr uint8_t MESSAGE_TYPE = 133;
|
||||
static constexpr uint8_t MESSAGE_TYPE = 131;
|
||||
static constexpr uint8_t ESTIMATED_SIZE = 0;
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
const char *message_name() const override { return "z_wave_proxy_unsubscribe_request"; }
|
||||
|
@@ -2101,10 +2101,8 @@ void UpdateCommandRequest::dump_to(std::string &out) const {
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void ZWaveProxyFromDeviceRequest::dump_to(std::string &out) const { dump_field(out, "data", this->data); }
|
||||
void ZWaveProxyFromDeviceResponse::dump_to(std::string &out) const { out.append("ZWaveProxyFromDeviceResponse {}"); }
|
||||
void ZWaveProxyToDeviceRequest::dump_to(std::string &out) const { dump_field(out, "data", this->data); }
|
||||
void ZWaveProxyToDeviceResponse::dump_to(std::string &out) const { out.append("ZWaveProxyToDeviceResponse {}"); }
|
||||
void ZWaveProxyFrameFromDevice::dump_to(std::string &out) const { dump_field(out, "data", this->data_ref_); }
|
||||
void ZWaveProxyFrameToDevice::dump_to(std::string &out) const { dump_field(out, "data", this->data); }
|
||||
void ZWaveProxySubscribeRequest::dump_to(std::string &out) const { dump_field(out, "flags", this->flags); }
|
||||
void ZWaveProxyUnsubscribeRequest::dump_to(std::string &out) const { out.append("ZWaveProxyUnsubscribeRequest {}"); }
|
||||
#endif
|
||||
|
@@ -597,24 +597,13 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type,
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
case ZWaveProxyFromDeviceRequest::MESSAGE_TYPE: {
|
||||
ZWaveProxyFromDeviceRequest msg;
|
||||
case ZWaveProxyFrameToDevice::MESSAGE_TYPE: {
|
||||
ZWaveProxyFrameToDevice msg;
|
||||
msg.decode(msg_data, msg_size);
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
ESP_LOGVV(TAG, "on_z_wave_proxy_from_device_request: %s", msg.dump().c_str());
|
||||
ESP_LOGVV(TAG, "on_z_wave_proxy_frame_to_device: %s", msg.dump().c_str());
|
||||
#endif
|
||||
this->on_z_wave_proxy_from_device_request(msg);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
case ZWaveProxyToDeviceRequest::MESSAGE_TYPE: {
|
||||
ZWaveProxyToDeviceRequest msg;
|
||||
msg.decode(msg_data, msg_size);
|
||||
#ifdef HAS_PROTO_MESSAGE_DUMP
|
||||
ESP_LOGVV(TAG, "on_z_wave_proxy_to_device_request: %s", msg.dump().c_str());
|
||||
#endif
|
||||
this->on_z_wave_proxy_to_device_request(msg);
|
||||
this->on_z_wave_proxy_frame_to_device(msg);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
@@ -954,6 +943,13 @@ void APIServerConnection::on_alarm_control_panel_command_request(const AlarmCont
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void APIServerConnection::on_z_wave_proxy_frame_to_device(const ZWaveProxyFrameToDevice &msg) {
|
||||
if (this->check_authenticated_()) {
|
||||
this->zwave_proxy_frame_to_device(msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void APIServerConnection::on_z_wave_proxy_subscribe_request(const ZWaveProxySubscribeRequest &msg) {
|
||||
if (this->check_authenticated_()) {
|
||||
this->zwave_proxy_subscribe(msg);
|
||||
@@ -967,19 +963,5 @@ void APIServerConnection::on_z_wave_proxy_unsubscribe_request(const ZWaveProxyUn
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void APIServerConnection::on_z_wave_proxy_from_device_request(const ZWaveProxyFromDeviceRequest &msg) {
|
||||
if (this->check_authenticated_()) {
|
||||
this->zwave_proxy_from_device(msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void APIServerConnection::on_z_wave_proxy_to_device_request(const ZWaveProxyToDeviceRequest &msg) {
|
||||
if (this->check_authenticated_()) {
|
||||
this->zwave_proxy_to_device(msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace esphome::api
|
||||
|
@@ -206,14 +206,10 @@ class APIServerConnectionBase : public ProtoService {
|
||||
#ifdef USE_UPDATE
|
||||
virtual void on_update_command_request(const UpdateCommandRequest &value){};
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
virtual void on_z_wave_proxy_from_device_request(const ZWaveProxyFromDeviceRequest &value){};
|
||||
#endif
|
||||
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
virtual void on_z_wave_proxy_to_device_request(const ZWaveProxyToDeviceRequest &value){};
|
||||
virtual void on_z_wave_proxy_frame_to_device(const ZWaveProxyFrameToDevice &value){};
|
||||
#endif
|
||||
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
virtual void on_z_wave_proxy_subscribe_request(const ZWaveProxySubscribeRequest &value){};
|
||||
#endif
|
||||
@@ -347,17 +343,14 @@ class APIServerConnection : public APIServerConnectionBase {
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
virtual void alarm_control_panel_command(const AlarmControlPanelCommandRequest &msg) = 0;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
virtual void zwave_proxy_frame_to_device(const ZWaveProxyFrameToDevice &msg) = 0;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
virtual void zwave_proxy_subscribe(const ZWaveProxySubscribeRequest &msg) = 0;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
virtual void zwave_proxy_unsubscribe(const ZWaveProxyUnsubscribeRequest &msg) = 0;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
virtual void zwave_proxy_from_device(const ZWaveProxyFromDeviceRequest &msg) = 0;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
virtual void zwave_proxy_to_device(const ZWaveProxyToDeviceRequest &msg) = 0;
|
||||
#endif
|
||||
protected:
|
||||
void on_hello_request(const HelloRequest &msg) override;
|
||||
@@ -481,18 +474,15 @@ class APIServerConnection : public APIServerConnectionBase {
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
void on_alarm_control_panel_command_request(const AlarmControlPanelCommandRequest &msg) override;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void on_z_wave_proxy_frame_to_device(const ZWaveProxyFrameToDevice &msg) override;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void on_z_wave_proxy_subscribe_request(const ZWaveProxySubscribeRequest &msg) override;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void on_z_wave_proxy_unsubscribe_request(const ZWaveProxyUnsubscribeRequest &msg) override;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void on_z_wave_proxy_from_device_request(const ZWaveProxyFromDeviceRequest &msg) override;
|
||||
#endif
|
||||
#ifdef USE_ZWAVE_PROXY
|
||||
void on_z_wave_proxy_to_device_request(const ZWaveProxyToDeviceRequest &msg) override;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace esphome::api
|
||||
|
@@ -28,10 +28,10 @@ void ZWaveProxy::loop() {
|
||||
return;
|
||||
}
|
||||
if (this->parse_byte_(byte)) {
|
||||
this->outgoing_request_.data = std::string((const char *) this->buffer_, this->buffer_index_);
|
||||
ESP_LOGD(TAG, "Sending frame...%s", YESNO(this->api_connection_ != nullptr));
|
||||
ESP_LOGD(TAG, "Sending frame: %s", YESNO(this->api_connection_ != nullptr));
|
||||
if (this->api_connection_ != nullptr) {
|
||||
this->api_connection_->send_message(this->outgoing_request_, api::ZWaveProxyFromDeviceRequest::MESSAGE_TYPE);
|
||||
this->outgoing_proto_msg_.set_data(StringRef((const char *) this->buffer_, this->buffer_index_));
|
||||
this->api_connection_->send_message(this->outgoing_proto_msg_, api::ZWaveProxyFrameFromDevice::MESSAGE_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,10 +147,9 @@ void ZWaveProxy::parse_start_(uint8_t byte) {
|
||||
return;
|
||||
}
|
||||
// Forward response (ACK/NAK/CAN) back to client for processing
|
||||
this->outgoing_request_.data.resize(1);
|
||||
this->outgoing_request_.data[0] = byte;
|
||||
if (this->api_connection_ != nullptr) {
|
||||
this->api_connection_->send_message(this->outgoing_request_, api::ZWaveProxyFromDeviceRequest::MESSAGE_TYPE);
|
||||
this->outgoing_proto_msg_.set_data(StringRef(&byte, 1));
|
||||
this->api_connection_->send_message(this->outgoing_proto_msg_, api::ZWaveProxyFrameFromDevice::MESSAGE_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -61,8 +61,8 @@ class ZWaveProxy : public uart::UARTDevice, public Component {
|
||||
uint8_t end_frame_after_{0}; // Payload reception ends after this index
|
||||
ZWaveParsingState parsing_state_{ZWAVE_PARSING_STATE_WAIT_START};
|
||||
|
||||
// Pre-allocated response message - always ready to send
|
||||
api::ZWaveProxyFromDeviceRequest outgoing_request_;
|
||||
// Pre-allocated message - always ready to send
|
||||
api::ZWaveProxyFrameFromDevice outgoing_proto_msg_;
|
||||
};
|
||||
|
||||
extern ZWaveProxy *global_zwave_proxy; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
Reference in New Issue
Block a user