mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Merge branch 'get_time_response_plus_connect_password_only' into integration
This commit is contained in:
		| @@ -133,6 +133,7 @@ message ConnectRequest { | ||||
|   option (id) = 3; | ||||
|   option (source) = SOURCE_CLIENT; | ||||
|   option (no_delay) = true; | ||||
|   option (ifdef) = "USE_API_PASSWORD"; | ||||
|  | ||||
|   // The password to log in with | ||||
|   string password = 1; | ||||
| @@ -144,6 +145,7 @@ message ConnectResponse { | ||||
|   option (id) = 4; | ||||
|   option (source) = SOURCE_SERVER; | ||||
|   option (no_delay) = true; | ||||
|   option (ifdef) = "USE_API_PASSWORD"; | ||||
|  | ||||
|   bool invalid_password = 1; | ||||
| } | ||||
|   | ||||
| @@ -1386,20 +1386,17 @@ bool APIConnection::send_hello_response(const HelloRequest &msg) { | ||||
|  | ||||
|   return this->send_message(resp, HelloResponse::MESSAGE_TYPE); | ||||
| } | ||||
| bool APIConnection::send_connect_response(const ConnectRequest &msg) { | ||||
|   bool correct = true; | ||||
| #ifdef USE_API_PASSWORD | ||||
|   correct = this->parent_->check_password(msg.password); | ||||
| #endif | ||||
|  | ||||
| bool APIConnection::send_connect_response(const ConnectRequest &msg) { | ||||
|   ConnectResponse resp; | ||||
|   // bool invalid_password = 1; | ||||
|   resp.invalid_password = !correct; | ||||
|   if (correct) { | ||||
|   resp.invalid_password = !this->parent_->check_password(msg.password); | ||||
|   if (!resp.invalid_password) { | ||||
|     this->complete_authentication_(); | ||||
|   } | ||||
|   return this->send_message(resp, ConnectResponse::MESSAGE_TYPE); | ||||
| } | ||||
| #endif  // USE_API_PASSWORD | ||||
|  | ||||
| bool APIConnection::send_ping_response(const PingRequest &msg) { | ||||
|   PingResponse resp; | ||||
|   | ||||
| @@ -197,7 +197,9 @@ class APIConnection final : public APIServerConnection { | ||||
|   void on_get_time_response(const GetTimeResponse &value) override; | ||||
| #endif | ||||
|   bool send_hello_response(const HelloRequest &msg) override; | ||||
| #ifdef USE_API_PASSWORD | ||||
|   bool send_connect_response(const ConnectRequest &msg) override; | ||||
| #endif | ||||
|   bool send_disconnect_response(const DisconnectRequest &msg) override; | ||||
|   bool send_ping_response(const PingRequest &msg) override; | ||||
|   bool send_device_info_response(const DeviceInfoRequest &msg) override; | ||||
|   | ||||
| @@ -42,6 +42,7 @@ void HelloResponse::calculate_size(ProtoSize &size) const { | ||||
|   size.add_length(1, this->server_info_ref_.size()); | ||||
|   size.add_length(1, this->name_ref_.size()); | ||||
| } | ||||
| #ifdef USE_API_PASSWORD | ||||
| bool ConnectRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value) { | ||||
|   switch (field_id) { | ||||
|     case 1: | ||||
| @@ -54,6 +55,7 @@ bool ConnectRequest::decode_length(uint32_t field_id, ProtoLengthDelimited value | ||||
| } | ||||
| void ConnectResponse::encode(ProtoWriteBuffer buffer) const { buffer.encode_bool(1, this->invalid_password); } | ||||
| void ConnectResponse::calculate_size(ProtoSize &size) const { size.add_bool(1, this->invalid_password); } | ||||
| #endif | ||||
| #ifdef USE_AREAS | ||||
| void AreaInfo::encode(ProtoWriteBuffer buffer) const { | ||||
|   buffer.encode_uint32(1, this->area_id); | ||||
|   | ||||
| @@ -360,6 +360,7 @@ class HelloResponse final : public ProtoMessage { | ||||
|  | ||||
|  protected: | ||||
| }; | ||||
| #ifdef USE_API_PASSWORD | ||||
| class ConnectRequest final : public ProtoDecodableMessage { | ||||
|  public: | ||||
|   static constexpr uint8_t MESSAGE_TYPE = 3; | ||||
| @@ -391,6 +392,7 @@ class ConnectResponse final : public ProtoMessage { | ||||
|  | ||||
|  protected: | ||||
| }; | ||||
| #endif | ||||
| class DisconnectRequest final : public ProtoMessage { | ||||
|  public: | ||||
|   static constexpr uint8_t MESSAGE_TYPE = 5; | ||||
|   | ||||
| @@ -669,8 +669,10 @@ void HelloResponse::dump_to(std::string &out) const { | ||||
|   dump_field(out, "server_info", this->server_info_ref_); | ||||
|   dump_field(out, "name", this->name_ref_); | ||||
| } | ||||
| #ifdef USE_API_PASSWORD | ||||
| void ConnectRequest::dump_to(std::string &out) const { dump_field(out, "password", this->password); } | ||||
| void ConnectResponse::dump_to(std::string &out) const { dump_field(out, "invalid_password", this->invalid_password); } | ||||
| #endif | ||||
| void DisconnectRequest::dump_to(std::string &out) const { out.append("DisconnectRequest {}"); } | ||||
| void DisconnectResponse::dump_to(std::string &out) const { out.append("DisconnectResponse {}"); } | ||||
| void PingRequest::dump_to(std::string &out) const { out.append("PingRequest {}"); } | ||||
|   | ||||
| @@ -24,6 +24,7 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type, | ||||
|       this->on_hello_request(msg); | ||||
|       break; | ||||
|     } | ||||
| #ifdef USE_API_PASSWORD | ||||
|     case ConnectRequest::MESSAGE_TYPE: { | ||||
|       ConnectRequest msg; | ||||
|       msg.decode(msg_data, msg_size); | ||||
| @@ -33,6 +34,7 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type, | ||||
|       this->on_connect_request(msg); | ||||
|       break; | ||||
|     } | ||||
| #endif | ||||
|     case DisconnectRequest::MESSAGE_TYPE: { | ||||
|       DisconnectRequest msg; | ||||
|       // Empty message: no decode needed | ||||
| @@ -597,11 +599,13 @@ void APIServerConnection::on_hello_request(const HelloRequest &msg) { | ||||
|     this->on_fatal_error(); | ||||
|   } | ||||
| } | ||||
| #ifdef USE_API_PASSWORD | ||||
| void APIServerConnection::on_connect_request(const ConnectRequest &msg) { | ||||
|   if (!this->send_connect_response(msg)) { | ||||
|     this->on_fatal_error(); | ||||
|   } | ||||
| } | ||||
| #endif | ||||
| void APIServerConnection::on_disconnect_request(const DisconnectRequest &msg) { | ||||
|   if (!this->send_disconnect_response(msg)) { | ||||
|     this->on_fatal_error(); | ||||
|   | ||||
| @@ -26,7 +26,9 @@ class APIServerConnectionBase : public ProtoService { | ||||
|  | ||||
|   virtual void on_hello_request(const HelloRequest &value){}; | ||||
|  | ||||
| #ifdef USE_API_PASSWORD | ||||
|   virtual void on_connect_request(const ConnectRequest &value){}; | ||||
| #endif | ||||
|  | ||||
|   virtual void on_disconnect_request(const DisconnectRequest &value){}; | ||||
|   virtual void on_disconnect_response(const DisconnectResponse &value){}; | ||||
| @@ -213,7 +215,9 @@ class APIServerConnectionBase : public ProtoService { | ||||
| class APIServerConnection : public APIServerConnectionBase { | ||||
|  public: | ||||
|   virtual bool send_hello_response(const HelloRequest &msg) = 0; | ||||
| #ifdef USE_API_PASSWORD | ||||
|   virtual bool send_connect_response(const ConnectRequest &msg) = 0; | ||||
| #endif | ||||
|   virtual bool send_disconnect_response(const DisconnectRequest &msg) = 0; | ||||
|   virtual bool send_ping_response(const PingRequest &msg) = 0; | ||||
|   virtual bool send_device_info_response(const DeviceInfoRequest &msg) = 0; | ||||
| @@ -334,7 +338,9 @@ class APIServerConnection : public APIServerConnectionBase { | ||||
| #endif | ||||
|  protected: | ||||
|   void on_hello_request(const HelloRequest &msg) override; | ||||
| #ifdef USE_API_PASSWORD | ||||
|   void on_connect_request(const ConnectRequest &msg) override; | ||||
| #endif | ||||
|   void on_disconnect_request(const DisconnectRequest &msg) override; | ||||
|   void on_ping_request(const PingRequest &msg) override; | ||||
|   void on_device_info_request(const DeviceInfoRequest &msg) override; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user