mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-22 11:43:51 +01:00 
			
		
		
		
	Merge branch 'api_nest' into integration
This commit is contained in:
		| @@ -31,8 +31,7 @@ | ||||
| #include "esphome/components/voice_assistant/voice_assistant.h" | ||||
| #endif | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| // Read a maximum of 5 messages per loop iteration to prevent starving other components. | ||||
| // This is a balance between API responsiveness and allowing other components to run. | ||||
| @@ -1837,6 +1836,5 @@ uint16_t APIConnection::try_send_ping_request(EntityBase *entity, APIConnection | ||||
|   return encode_message_to_buffer(req, PingRequest::MESSAGE_TYPE, conn, remaining_size, is_single); | ||||
| } | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -13,8 +13,7 @@ | ||||
| #include <vector> | ||||
| #include <functional> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| // Client information structure | ||||
| struct ClientInfo { | ||||
| @@ -723,6 +722,5 @@ class APIConnection : public APIServerConnection { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -9,8 +9,7 @@ | ||||
| #include <cstring> | ||||
| #include <cinttypes> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| static const char *const TAG = "api.frame_helper"; | ||||
|  | ||||
| @@ -247,6 +246,5 @@ APIError APIFrameHelper::handle_socket_read_result_(ssize_t received) { | ||||
|   return APIError::OK; | ||||
| } | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -12,8 +12,7 @@ | ||||
| #include "esphome/core/application.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| // uncomment to log raw packets | ||||
| //#define HELPER_LOG_PACKETS | ||||
| @@ -184,7 +183,6 @@ class APIFrameHelper { | ||||
|   APIError handle_socket_read_result_(ssize_t received); | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|  | ||||
| #endif  // USE_API | ||||
|   | ||||
| @@ -10,8 +10,7 @@ | ||||
| #include <cstring> | ||||
| #include <cinttypes> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| static const char *const TAG = "api.noise"; | ||||
| static const char *const PROLOGUE_INIT = "NoiseAPIInit"; | ||||
| @@ -579,7 +578,6 @@ void noise_rand_bytes(void *output, size_t len) { | ||||
| } | ||||
| } | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif  // USE_API_NOISE | ||||
| #endif  // USE_API | ||||
|   | ||||
| @@ -5,8 +5,7 @@ | ||||
| #include "noise/protocol.h" | ||||
| #include "api_noise_context.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| class APINoiseFrameHelper : public APIFrameHelper { | ||||
|  public: | ||||
| @@ -64,7 +63,6 @@ class APINoiseFrameHelper : public APIFrameHelper { | ||||
|   // 4 bytes total, no padding | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif  // USE_API_NOISE | ||||
| #endif  // USE_API | ||||
|   | ||||
| @@ -10,8 +10,7 @@ | ||||
| #include <cstring> | ||||
| #include <cinttypes> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| static const char *const TAG = "api.plaintext"; | ||||
|  | ||||
| @@ -286,7 +285,6 @@ APIError APIPlaintextFrameHelper::write_protobuf_packets(ProtoWriteBuffer buffer | ||||
|   return write_raw_(this->reusable_iovs_.data(), this->reusable_iovs_.size(), total_write_len); | ||||
| } | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif  // USE_API_PLAINTEXT | ||||
| #endif  // USE_API | ||||
|   | ||||
| @@ -3,8 +3,7 @@ | ||||
| #ifdef USE_API | ||||
| #ifdef USE_API_PLAINTEXT | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| class APIPlaintextFrameHelper : public APIFrameHelper { | ||||
|  public: | ||||
| @@ -49,7 +48,6 @@ class APIPlaintextFrameHelper : public APIFrameHelper { | ||||
|   // 8 bytes total, no padding needed | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif  // USE_API_PLAINTEXT | ||||
| #endif  // USE_API | ||||
|   | ||||
| @@ -3,8 +3,7 @@ | ||||
| #include <cstdint> | ||||
| #include "esphome/core/defines.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| #ifdef USE_API_NOISE | ||||
| using psk_t = std::array<uint8_t, 32>; | ||||
| @@ -28,5 +27,4 @@ class APINoiseContext { | ||||
| }; | ||||
| #endif  // USE_API_NOISE | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|   | ||||
| @@ -5,8 +5,7 @@ | ||||
| #include "esphome/core/helpers.h" | ||||
| #include <cstring> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| bool HelloRequest::decode_varint(uint32_t field_id, ProtoVarInt value) { | ||||
|   switch (field_id) { | ||||
| @@ -2981,5 +2980,4 @@ bool UpdateCommandRequest::decode_32bit(uint32_t field_id, Proto32Bit value) { | ||||
| } | ||||
| #endif | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
|  | ||||
| #include "proto.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| namespace enums { | ||||
|  | ||||
| @@ -2891,5 +2890,4 @@ class UpdateCommandRequest : public CommandProtoMessage { | ||||
| }; | ||||
| #endif | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
|  | ||||
| #ifdef HAS_PROTO_MESSAGE_DUMP | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| // Helper function to append a quoted string, handling empty StringRef | ||||
| static inline void append_quoted_string(std::string &out, const StringRef &ref) { | ||||
| @@ -2067,7 +2066,6 @@ void UpdateCommandRequest::dump_to(std::string &out) const { | ||||
| } | ||||
| #endif | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|  | ||||
| #endif  // HAS_PROTO_MESSAGE_DUMP | ||||
|   | ||||
| @@ -3,8 +3,7 @@ | ||||
| #include "api_pb2_service.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| static const char *const TAG = "api.service"; | ||||
|  | ||||
| @@ -901,5 +900,4 @@ void APIServerConnection::on_alarm_control_panel_command_request(const AlarmCont | ||||
| } | ||||
| #endif | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
|  | ||||
| #include "api_pb2.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| class APIServerConnectionBase : public ProtoService { | ||||
|  public: | ||||
| @@ -444,5 +443,4 @@ class APIServerConnection : public APIServerConnectionBase { | ||||
| #endif | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|   | ||||
| @@ -16,8 +16,7 @@ | ||||
|  | ||||
| #include <algorithm> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| static const char *const TAG = "api"; | ||||
|  | ||||
| @@ -483,6 +482,5 @@ bool APIServer::teardown() { | ||||
|   return this->clients_.empty(); | ||||
| } | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -18,8 +18,7 @@ | ||||
|  | ||||
| #include <vector> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| #ifdef USE_API_NOISE | ||||
| struct SavedNoisePsk { | ||||
| @@ -196,6 +195,5 @@ template<typename... Ts> class APIConnectedCondition : public Condition<Ts...> { | ||||
|   bool check(Ts... x) override { return global_api_server->is_connected(); } | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
| #ifdef USE_API_SERVICES | ||||
| #include "user_services.h" | ||||
| #endif | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| #ifdef USE_API_SERVICES | ||||
| template<typename T, typename... Ts> class CustomAPIDeviceService : public UserServiceBase<Ts...> { | ||||
| @@ -222,6 +221,5 @@ class CustomAPIDevice { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -7,8 +7,7 @@ | ||||
| #include "esphome/core/helpers.h" | ||||
| #include <vector> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| template<typename... X> class TemplatableStringValue : public TemplatableValue<std::string, X...> { | ||||
|  private: | ||||
| @@ -99,6 +98,5 @@ template<typename... Ts> class HomeAssistantServiceCallAction : public Action<Ts | ||||
|   std::vector<TemplatableKeyValuePair<Ts...>> variables_; | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -6,8 +6,7 @@ | ||||
| #include "esphome/core/log.h" | ||||
| #include "esphome/core/util.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| // Generate entity handler implementations using macros | ||||
| #ifdef USE_BINARY_SENSOR | ||||
| @@ -90,6 +89,5 @@ bool ListEntitiesIterator::on_service(UserServiceDescriptor *service) { | ||||
| } | ||||
| #endif | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
| #ifdef USE_API | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/core/component_iterator.h" | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| class APIConnection; | ||||
|  | ||||
| @@ -96,6 +95,5 @@ class ListEntitiesIterator : public ComponentIterator { | ||||
|   APIConnection *client_; | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -3,8 +3,7 @@ | ||||
| #include "esphome/core/helpers.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| static const char *const TAG = "api.proto"; | ||||
|  | ||||
| @@ -89,5 +88,4 @@ std::string ProtoMessage::dump() const { | ||||
| } | ||||
| #endif | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|   | ||||
| @@ -13,8 +13,7 @@ | ||||
| #define HAS_PROTO_MESSAGE_DUMP | ||||
| #endif | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| /* | ||||
|  * StringRef Ownership Model for API Protocol Messages | ||||
| @@ -910,5 +909,4 @@ class ProtoService { | ||||
|   } | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|   | ||||
| @@ -3,8 +3,7 @@ | ||||
| #include "api_connection.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| // Generate entity handler implementations using macros | ||||
| #ifdef USE_BINARY_SENSOR | ||||
| @@ -69,6 +68,5 @@ INITIAL_STATE_HANDLER(update, update::UpdateEntity) | ||||
|  | ||||
| InitialStateIterator::InitialStateIterator(APIConnection *client) : client_(client) {} | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -5,8 +5,7 @@ | ||||
| #include "esphome/core/component.h" | ||||
| #include "esphome/core/component_iterator.h" | ||||
| #include "esphome/core/controller.h" | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| class APIConnection; | ||||
|  | ||||
| @@ -89,6 +88,5 @@ class InitialStateIterator : public ComponentIterator { | ||||
|   APIConnection *client_; | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif | ||||
|   | ||||
| @@ -1,8 +1,7 @@ | ||||
| #include "user_services.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| template<> bool get_execute_arg_value<bool>(const ExecuteServiceArgument &arg) { return arg.bool_; } | ||||
| template<> int32_t get_execute_arg_value<int32_t>(const ExecuteServiceArgument &arg) { | ||||
| @@ -40,5 +39,4 @@ template<> enums::ServiceArgType to_service_arg_type<std::vector<std::string>>() | ||||
|   return enums::SERVICE_ARG_TYPE_STRING_ARRAY; | ||||
| } | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|   | ||||
| @@ -8,8 +8,7 @@ | ||||
| #include "api_pb2.h" | ||||
|  | ||||
| #ifdef USE_API_SERVICES | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| class UserServiceDescriptor { | ||||
|  public: | ||||
| @@ -74,6 +73,5 @@ template<typename... Ts> class UserServiceTrigger : public UserServiceBase<Ts... | ||||
|   void execute(Ts... x) override { this->trigger(x...); }  // NOLINT | ||||
| }; | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| #endif  // USE_API_SERVICES | ||||
|   | ||||
| @@ -2048,8 +2048,7 @@ def main() -> None: | ||||
|  | ||||
| #include "proto.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| """ | ||||
|  | ||||
| @@ -2060,8 +2059,7 @@ namespace api { | ||||
|     #include "esphome/core/helpers.h" | ||||
|     #include <cstring> | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| """ | ||||
|  | ||||
| @@ -2075,8 +2073,7 @@ namespace api { | ||||
|  | ||||
| #ifdef HAS_PROTO_MESSAGE_DUMP | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| // Helper function to append a quoted string, handling empty StringRef | ||||
| static inline void append_quoted_string(std::string &out, const StringRef &ref) { | ||||
| @@ -2268,19 +2265,16 @@ static void dump_field(std::string &out, const char *field_name, T value, int in | ||||
|  | ||||
|     content += """\ | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| """ | ||||
|     cpp += """\ | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| """ | ||||
|  | ||||
|     dump_cpp += """\ | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
|  | ||||
| #endif  // HAS_PROTO_MESSAGE_DUMP | ||||
| """ | ||||
| @@ -2302,8 +2296,7 @@ static void dump_field(std::string &out, const char *field_name, T value, int in | ||||
|  | ||||
| #include "api_pb2.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| """ | ||||
|  | ||||
| @@ -2312,8 +2305,7 @@ namespace api { | ||||
| #include "api_pb2_service.h" | ||||
| #include "esphome/core/log.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| namespace esphome::api { | ||||
|  | ||||
| static const char *const TAG = "api.service"; | ||||
|  | ||||
| @@ -2454,13 +2446,11 @@ static const char *const TAG = "api.service"; | ||||
|  | ||||
|     hpp += """\ | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| """ | ||||
|     cpp += """\ | ||||
|  | ||||
| }  // namespace api | ||||
| }  // namespace esphome | ||||
| }  // namespace esphome::api | ||||
| """ | ||||
|  | ||||
|     with open(root / "api_pb2_service.h", "w", encoding="utf-8") as f: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user