esphome 2025.7.0b1__py3-none-any.whl → 2025.7.0b2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- esphome/components/api/__init__.py +19 -5
- esphome/components/api/api_connection.cpp +53 -175
- esphome/components/api/api_connection.h +28 -25
- esphome/components/api/api_frame_helper.cpp +2 -3
- esphome/components/api/api_frame_helper.h +7 -9
- esphome/components/api/api_pb2.cpp +1862 -5133
- esphome/components/api/api_pb2.h +291 -533
- esphome/components/api/api_pb2_dump.cpp +99 -0
- esphome/components/api/api_pb2_service.cpp +4 -0
- esphome/components/api/api_pb2_service.h +6 -0
- esphome/components/api/api_server.cpp +2 -9
- esphome/components/api/api_server.h +7 -33
- esphome/components/api/custom_api_device.h +8 -0
- esphome/components/api/list_entities.cpp +2 -0
- esphome/components/api/list_entities.h +3 -1
- esphome/components/api/proto.h +506 -23
- esphome/components/api/user_services.h +2 -0
- esphome/components/debug/debug_esp32.cpp +2 -0
- esphome/components/esp32/__init__.py +1 -0
- esphome/components/esp32_camera/__init__.py +1 -1
- esphome/components/esp32_touch/esp32_touch_v1.cpp +12 -10
- esphome/components/esp8266/__init__.py +1 -0
- esphome/components/host/__init__.py +1 -0
- esphome/components/ld2410/ld2410.cpp +12 -28
- esphome/components/libretiny/__init__.py +1 -0
- esphome/components/mqtt/mqtt_backend_esp32.cpp +6 -2
- esphome/components/packet_transport/packet_transport.cpp +3 -0
- esphome/components/rp2040/__init__.py +1 -0
- esphome/components/sx126x/__init__.py +3 -3
- esphome/components/sx127x/__init__.py +2 -2
- esphome/components/usb_host/usb_host_client.cpp +10 -10
- esphome/components/usb_uart/cp210x.cpp +1 -1
- esphome/components/usb_uart/usb_uart.cpp +41 -44
- esphome/components/usb_uart/usb_uart.h +4 -3
- esphome/const.py +1 -1
- esphome/core/component_iterator.cpp +4 -2
- esphome/core/component_iterator.h +3 -3
- esphome/core/defines.h +1 -1
- esphome/core/entity_helpers.py +6 -0
- esphome/core/scheduler.cpp +9 -12
- esphome/core/scheduler.h +0 -3
- esphome/wizard.py +1 -1
- {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b2.dist-info}/METADATA +2 -2
- {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b2.dist-info}/RECORD +48 -49
- esphome/components/api/api_pb2_size.h +0 -359
- {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b2.dist-info}/WHEEL +0 -0
- {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b2.dist-info}/entry_points.txt +0 -0
- {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b2.dist-info}/licenses/LICENSE +0 -0
- {esphome-2025.7.0b1.dist-info → esphome-2025.7.0b2.dist-info}/top_level.txt +0 -0
|
@@ -162,6 +162,7 @@ template<> const char *proto_enum_to_string<enums::LogLevel>(enums::LogLevel val
|
|
|
162
162
|
return "UNKNOWN";
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
+
#ifdef USE_API_SERVICES
|
|
165
166
|
template<> const char *proto_enum_to_string<enums::ServiceArgType>(enums::ServiceArgType value) {
|
|
166
167
|
switch (value) {
|
|
167
168
|
case enums::SERVICE_ARG_TYPE_BOOL:
|
|
@@ -184,6 +185,7 @@ template<> const char *proto_enum_to_string<enums::ServiceArgType>(enums::Servic
|
|
|
184
185
|
return "UNKNOWN";
|
|
185
186
|
}
|
|
186
187
|
}
|
|
188
|
+
#endif
|
|
187
189
|
#ifdef USE_CLIMATE
|
|
188
190
|
template<> const char *proto_enum_to_string<enums::ClimateMode>(enums::ClimateMode value) {
|
|
189
191
|
switch (value) {
|
|
@@ -986,6 +988,11 @@ void CoverCommandRequest::dump_to(std::string &out) const {
|
|
|
986
988
|
out.append(" stop: ");
|
|
987
989
|
out.append(YESNO(this->stop));
|
|
988
990
|
out.append("\n");
|
|
991
|
+
|
|
992
|
+
out.append(" device_id: ");
|
|
993
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
994
|
+
out.append(buffer);
|
|
995
|
+
out.append("\n");
|
|
989
996
|
out.append("}");
|
|
990
997
|
}
|
|
991
998
|
#endif
|
|
@@ -1146,6 +1153,11 @@ void FanCommandRequest::dump_to(std::string &out) const {
|
|
|
1146
1153
|
out.append(" preset_mode: ");
|
|
1147
1154
|
out.append("'").append(this->preset_mode).append("'");
|
|
1148
1155
|
out.append("\n");
|
|
1156
|
+
|
|
1157
|
+
out.append(" device_id: ");
|
|
1158
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
1159
|
+
out.append(buffer);
|
|
1160
|
+
out.append("\n");
|
|
1149
1161
|
out.append("}");
|
|
1150
1162
|
}
|
|
1151
1163
|
#endif
|
|
@@ -1419,6 +1431,11 @@ void LightCommandRequest::dump_to(std::string &out) const {
|
|
|
1419
1431
|
out.append(" effect: ");
|
|
1420
1432
|
out.append("'").append(this->effect).append("'");
|
|
1421
1433
|
out.append("\n");
|
|
1434
|
+
|
|
1435
|
+
out.append(" device_id: ");
|
|
1436
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
1437
|
+
out.append(buffer);
|
|
1438
|
+
out.append("\n");
|
|
1422
1439
|
out.append("}");
|
|
1423
1440
|
}
|
|
1424
1441
|
#endif
|
|
@@ -1586,6 +1603,11 @@ void SwitchCommandRequest::dump_to(std::string &out) const {
|
|
|
1586
1603
|
out.append(" state: ");
|
|
1587
1604
|
out.append(YESNO(this->state));
|
|
1588
1605
|
out.append("\n");
|
|
1606
|
+
|
|
1607
|
+
out.append(" device_id: ");
|
|
1608
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
1609
|
+
out.append(buffer);
|
|
1610
|
+
out.append("\n");
|
|
1589
1611
|
out.append("}");
|
|
1590
1612
|
}
|
|
1591
1613
|
#endif
|
|
@@ -1791,6 +1813,7 @@ void GetTimeResponse::dump_to(std::string &out) const {
|
|
|
1791
1813
|
out.append("\n");
|
|
1792
1814
|
out.append("}");
|
|
1793
1815
|
}
|
|
1816
|
+
#ifdef USE_API_SERVICES
|
|
1794
1817
|
void ListEntitiesServicesArgument::dump_to(std::string &out) const {
|
|
1795
1818
|
__attribute__((unused)) char buffer[64];
|
|
1796
1819
|
out.append("ListEntitiesServicesArgument {\n");
|
|
@@ -1890,6 +1913,7 @@ void ExecuteServiceRequest::dump_to(std::string &out) const {
|
|
|
1890
1913
|
}
|
|
1891
1914
|
out.append("}");
|
|
1892
1915
|
}
|
|
1916
|
+
#endif
|
|
1893
1917
|
#ifdef USE_CAMERA
|
|
1894
1918
|
void ListEntitiesCameraResponse::dump_to(std::string &out) const {
|
|
1895
1919
|
__attribute__((unused)) char buffer[64];
|
|
@@ -1944,6 +1968,11 @@ void CameraImageResponse::dump_to(std::string &out) const {
|
|
|
1944
1968
|
out.append(" done: ");
|
|
1945
1969
|
out.append(YESNO(this->done));
|
|
1946
1970
|
out.append("\n");
|
|
1971
|
+
|
|
1972
|
+
out.append(" device_id: ");
|
|
1973
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
1974
|
+
out.append(buffer);
|
|
1975
|
+
out.append("\n");
|
|
1947
1976
|
out.append("}");
|
|
1948
1977
|
}
|
|
1949
1978
|
void CameraImageRequest::dump_to(std::string &out) const {
|
|
@@ -2263,6 +2292,11 @@ void ClimateCommandRequest::dump_to(std::string &out) const {
|
|
|
2263
2292
|
snprintf(buffer, sizeof(buffer), "%g", this->target_humidity);
|
|
2264
2293
|
out.append(buffer);
|
|
2265
2294
|
out.append("\n");
|
|
2295
|
+
|
|
2296
|
+
out.append(" device_id: ");
|
|
2297
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
2298
|
+
out.append(buffer);
|
|
2299
|
+
out.append("\n");
|
|
2266
2300
|
out.append("}");
|
|
2267
2301
|
}
|
|
2268
2302
|
#endif
|
|
@@ -2367,6 +2401,11 @@ void NumberCommandRequest::dump_to(std::string &out) const {
|
|
|
2367
2401
|
snprintf(buffer, sizeof(buffer), "%g", this->state);
|
|
2368
2402
|
out.append(buffer);
|
|
2369
2403
|
out.append("\n");
|
|
2404
|
+
|
|
2405
|
+
out.append(" device_id: ");
|
|
2406
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
2407
|
+
out.append(buffer);
|
|
2408
|
+
out.append("\n");
|
|
2370
2409
|
out.append("}");
|
|
2371
2410
|
}
|
|
2372
2411
|
#endif
|
|
@@ -2448,6 +2487,11 @@ void SelectCommandRequest::dump_to(std::string &out) const {
|
|
|
2448
2487
|
out.append(" state: ");
|
|
2449
2488
|
out.append("'").append(this->state).append("'");
|
|
2450
2489
|
out.append("\n");
|
|
2490
|
+
|
|
2491
|
+
out.append(" device_id: ");
|
|
2492
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
2493
|
+
out.append(buffer);
|
|
2494
|
+
out.append("\n");
|
|
2451
2495
|
out.append("}");
|
|
2452
2496
|
}
|
|
2453
2497
|
#endif
|
|
@@ -2563,6 +2607,11 @@ void SirenCommandRequest::dump_to(std::string &out) const {
|
|
|
2563
2607
|
snprintf(buffer, sizeof(buffer), "%g", this->volume);
|
|
2564
2608
|
out.append(buffer);
|
|
2565
2609
|
out.append("\n");
|
|
2610
|
+
|
|
2611
|
+
out.append(" device_id: ");
|
|
2612
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
2613
|
+
out.append(buffer);
|
|
2614
|
+
out.append("\n");
|
|
2566
2615
|
out.append("}");
|
|
2567
2616
|
}
|
|
2568
2617
|
#endif
|
|
@@ -2658,6 +2707,11 @@ void LockCommandRequest::dump_to(std::string &out) const {
|
|
|
2658
2707
|
out.append(" code: ");
|
|
2659
2708
|
out.append("'").append(this->code).append("'");
|
|
2660
2709
|
out.append("\n");
|
|
2710
|
+
|
|
2711
|
+
out.append(" device_id: ");
|
|
2712
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
2713
|
+
out.append(buffer);
|
|
2714
|
+
out.append("\n");
|
|
2661
2715
|
out.append("}");
|
|
2662
2716
|
}
|
|
2663
2717
|
#endif
|
|
@@ -2711,6 +2765,11 @@ void ButtonCommandRequest::dump_to(std::string &out) const {
|
|
|
2711
2765
|
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->key);
|
|
2712
2766
|
out.append(buffer);
|
|
2713
2767
|
out.append("\n");
|
|
2768
|
+
|
|
2769
|
+
out.append(" device_id: ");
|
|
2770
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
2771
|
+
out.append(buffer);
|
|
2772
|
+
out.append("\n");
|
|
2714
2773
|
out.append("}");
|
|
2715
2774
|
}
|
|
2716
2775
|
#endif
|
|
@@ -2857,6 +2916,11 @@ void MediaPlayerCommandRequest::dump_to(std::string &out) const {
|
|
|
2857
2916
|
out.append(" announcement: ");
|
|
2858
2917
|
out.append(YESNO(this->announcement));
|
|
2859
2918
|
out.append("\n");
|
|
2919
|
+
|
|
2920
|
+
out.append(" device_id: ");
|
|
2921
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
2922
|
+
out.append(buffer);
|
|
2923
|
+
out.append("\n");
|
|
2860
2924
|
out.append("}");
|
|
2861
2925
|
}
|
|
2862
2926
|
#endif
|
|
@@ -3682,6 +3746,11 @@ void AlarmControlPanelCommandRequest::dump_to(std::string &out) const {
|
|
|
3682
3746
|
out.append(" code: ");
|
|
3683
3747
|
out.append("'").append(this->code).append("'");
|
|
3684
3748
|
out.append("\n");
|
|
3749
|
+
|
|
3750
|
+
out.append(" device_id: ");
|
|
3751
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
3752
|
+
out.append(buffer);
|
|
3753
|
+
out.append("\n");
|
|
3685
3754
|
out.append("}");
|
|
3686
3755
|
}
|
|
3687
3756
|
#endif
|
|
@@ -3775,6 +3844,11 @@ void TextCommandRequest::dump_to(std::string &out) const {
|
|
|
3775
3844
|
out.append(" state: ");
|
|
3776
3845
|
out.append("'").append(this->state).append("'");
|
|
3777
3846
|
out.append("\n");
|
|
3847
|
+
|
|
3848
|
+
out.append(" device_id: ");
|
|
3849
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
3850
|
+
out.append(buffer);
|
|
3851
|
+
out.append("\n");
|
|
3778
3852
|
out.append("}");
|
|
3779
3853
|
}
|
|
3780
3854
|
#endif
|
|
@@ -3872,6 +3946,11 @@ void DateCommandRequest::dump_to(std::string &out) const {
|
|
|
3872
3946
|
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->day);
|
|
3873
3947
|
out.append(buffer);
|
|
3874
3948
|
out.append("\n");
|
|
3949
|
+
|
|
3950
|
+
out.append(" device_id: ");
|
|
3951
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
3952
|
+
out.append(buffer);
|
|
3953
|
+
out.append("\n");
|
|
3875
3954
|
out.append("}");
|
|
3876
3955
|
}
|
|
3877
3956
|
#endif
|
|
@@ -3969,6 +4048,11 @@ void TimeCommandRequest::dump_to(std::string &out) const {
|
|
|
3969
4048
|
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->second);
|
|
3970
4049
|
out.append(buffer);
|
|
3971
4050
|
out.append("\n");
|
|
4051
|
+
|
|
4052
|
+
out.append(" device_id: ");
|
|
4053
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
4054
|
+
out.append(buffer);
|
|
4055
|
+
out.append("\n");
|
|
3972
4056
|
out.append("}");
|
|
3973
4057
|
}
|
|
3974
4058
|
#endif
|
|
@@ -4138,6 +4222,11 @@ void ValveCommandRequest::dump_to(std::string &out) const {
|
|
|
4138
4222
|
out.append(" stop: ");
|
|
4139
4223
|
out.append(YESNO(this->stop));
|
|
4140
4224
|
out.append("\n");
|
|
4225
|
+
|
|
4226
|
+
out.append(" device_id: ");
|
|
4227
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
4228
|
+
out.append(buffer);
|
|
4229
|
+
out.append("\n");
|
|
4141
4230
|
out.append("}");
|
|
4142
4231
|
}
|
|
4143
4232
|
#endif
|
|
@@ -4215,6 +4304,11 @@ void DateTimeCommandRequest::dump_to(std::string &out) const {
|
|
|
4215
4304
|
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->epoch_seconds);
|
|
4216
4305
|
out.append(buffer);
|
|
4217
4306
|
out.append("\n");
|
|
4307
|
+
|
|
4308
|
+
out.append(" device_id: ");
|
|
4309
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
4310
|
+
out.append(buffer);
|
|
4311
|
+
out.append("\n");
|
|
4218
4312
|
out.append("}");
|
|
4219
4313
|
}
|
|
4220
4314
|
#endif
|
|
@@ -4323,6 +4417,11 @@ void UpdateCommandRequest::dump_to(std::string &out) const {
|
|
|
4323
4417
|
out.append(" command: ");
|
|
4324
4418
|
out.append(proto_enum_to_string<enums::UpdateCommand>(this->command));
|
|
4325
4419
|
out.append("\n");
|
|
4420
|
+
|
|
4421
|
+
out.append(" device_id: ");
|
|
4422
|
+
snprintf(buffer, sizeof(buffer), "%" PRIu32, this->device_id);
|
|
4423
|
+
out.append(buffer);
|
|
4424
|
+
out.append("\n");
|
|
4326
4425
|
out.append("}");
|
|
4327
4426
|
}
|
|
4328
4427
|
#endif
|
|
@@ -195,6 +195,7 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type,
|
|
|
195
195
|
this->on_home_assistant_state_response(msg);
|
|
196
196
|
break;
|
|
197
197
|
}
|
|
198
|
+
#ifdef USE_API_SERVICES
|
|
198
199
|
case 42: {
|
|
199
200
|
ExecuteServiceRequest msg;
|
|
200
201
|
msg.decode(msg_data, msg_size);
|
|
@@ -204,6 +205,7 @@ void APIServerConnectionBase::read_message(uint32_t msg_size, uint32_t msg_type,
|
|
|
204
205
|
this->on_execute_service_request(msg);
|
|
205
206
|
break;
|
|
206
207
|
}
|
|
208
|
+
#endif
|
|
207
209
|
#ifdef USE_CAMERA
|
|
208
210
|
case 45: {
|
|
209
211
|
CameraImageRequest msg;
|
|
@@ -660,11 +662,13 @@ void APIServerConnection::on_get_time_request(const GetTimeRequest &msg) {
|
|
|
660
662
|
}
|
|
661
663
|
}
|
|
662
664
|
}
|
|
665
|
+
#ifdef USE_API_SERVICES
|
|
663
666
|
void APIServerConnection::on_execute_service_request(const ExecuteServiceRequest &msg) {
|
|
664
667
|
if (this->check_authenticated_()) {
|
|
665
668
|
this->execute_service(msg);
|
|
666
669
|
}
|
|
667
670
|
}
|
|
671
|
+
#endif
|
|
668
672
|
#ifdef USE_API_NOISE
|
|
669
673
|
void APIServerConnection::on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &msg) {
|
|
670
674
|
if (this->check_authenticated_()) {
|
|
@@ -69,7 +69,9 @@ class APIServerConnectionBase : public ProtoService {
|
|
|
69
69
|
virtual void on_get_time_request(const GetTimeRequest &value){};
|
|
70
70
|
virtual void on_get_time_response(const GetTimeResponse &value){};
|
|
71
71
|
|
|
72
|
+
#ifdef USE_API_SERVICES
|
|
72
73
|
virtual void on_execute_service_request(const ExecuteServiceRequest &value){};
|
|
74
|
+
#endif
|
|
73
75
|
|
|
74
76
|
#ifdef USE_CAMERA
|
|
75
77
|
virtual void on_camera_image_request(const CameraImageRequest &value){};
|
|
@@ -216,7 +218,9 @@ class APIServerConnection : public APIServerConnectionBase {
|
|
|
216
218
|
virtual void subscribe_homeassistant_services(const SubscribeHomeassistantServicesRequest &msg) = 0;
|
|
217
219
|
virtual void subscribe_home_assistant_states(const SubscribeHomeAssistantStatesRequest &msg) = 0;
|
|
218
220
|
virtual GetTimeResponse get_time(const GetTimeRequest &msg) = 0;
|
|
221
|
+
#ifdef USE_API_SERVICES
|
|
219
222
|
virtual void execute_service(const ExecuteServiceRequest &msg) = 0;
|
|
223
|
+
#endif
|
|
220
224
|
#ifdef USE_API_NOISE
|
|
221
225
|
virtual NoiseEncryptionSetKeyResponse noise_encryption_set_key(const NoiseEncryptionSetKeyRequest &msg) = 0;
|
|
222
226
|
#endif
|
|
@@ -333,7 +337,9 @@ class APIServerConnection : public APIServerConnectionBase {
|
|
|
333
337
|
void on_subscribe_homeassistant_services_request(const SubscribeHomeassistantServicesRequest &msg) override;
|
|
334
338
|
void on_subscribe_home_assistant_states_request(const SubscribeHomeAssistantStatesRequest &msg) override;
|
|
335
339
|
void on_get_time_request(const GetTimeRequest &msg) override;
|
|
340
|
+
#ifdef USE_API_SERVICES
|
|
336
341
|
void on_execute_service_request(const ExecuteServiceRequest &msg) override;
|
|
342
|
+
#endif
|
|
337
343
|
#ifdef USE_API_NOISE
|
|
338
344
|
void on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &msg) override;
|
|
339
345
|
#endif
|
|
@@ -24,14 +24,6 @@ static const char *const TAG = "api";
|
|
|
24
24
|
// APIServer
|
|
25
25
|
APIServer *global_api_server = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
|
|
26
26
|
|
|
27
|
-
#ifndef USE_API_YAML_SERVICES
|
|
28
|
-
// Global empty vector to avoid guard variables (saves 8 bytes)
|
|
29
|
-
// This is initialized at program startup before any threads
|
|
30
|
-
static const std::vector<UserServiceDescriptor *> empty_user_services{};
|
|
31
|
-
|
|
32
|
-
const std::vector<UserServiceDescriptor *> &get_empty_user_services_instance() { return empty_user_services; }
|
|
33
|
-
#endif
|
|
34
|
-
|
|
35
27
|
APIServer::APIServer() {
|
|
36
28
|
global_api_server = this;
|
|
37
29
|
// Pre-allocate shared write buffer
|
|
@@ -475,7 +467,8 @@ void APIServer::on_shutdown() {
|
|
|
475
467
|
if (!c->send_message(DisconnectRequest())) {
|
|
476
468
|
// If we can't send the disconnect request directly (tx_buffer full),
|
|
477
469
|
// schedule it at the front of the batch so it will be sent with priority
|
|
478
|
-
c->schedule_message_front_(nullptr, &APIConnection::try_send_disconnect_request, DisconnectRequest::MESSAGE_TYPE
|
|
470
|
+
c->schedule_message_front_(nullptr, &APIConnection::try_send_disconnect_request, DisconnectRequest::MESSAGE_TYPE,
|
|
471
|
+
DisconnectRequest::ESTIMATED_SIZE);
|
|
479
472
|
}
|
|
480
473
|
}
|
|
481
474
|
}
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
#include "esphome/core/log.h"
|
|
13
13
|
#include "list_entities.h"
|
|
14
14
|
#include "subscribe_state.h"
|
|
15
|
+
#ifdef USE_API_SERVICES
|
|
15
16
|
#include "user_services.h"
|
|
17
|
+
#endif
|
|
16
18
|
|
|
17
19
|
#include <vector>
|
|
18
20
|
|
|
@@ -25,11 +27,6 @@ struct SavedNoisePsk {
|
|
|
25
27
|
} PACKED; // NOLINT
|
|
26
28
|
#endif
|
|
27
29
|
|
|
28
|
-
#ifndef USE_API_YAML_SERVICES
|
|
29
|
-
// Forward declaration of helper function
|
|
30
|
-
const std::vector<UserServiceDescriptor *> &get_empty_user_services_instance();
|
|
31
|
-
#endif
|
|
32
|
-
|
|
33
30
|
class APIServer : public Component, public Controller {
|
|
34
31
|
public:
|
|
35
32
|
APIServer();
|
|
@@ -112,18 +109,9 @@ class APIServer : public Component, public Controller {
|
|
|
112
109
|
void on_media_player_update(media_player::MediaPlayer *obj) override;
|
|
113
110
|
#endif
|
|
114
111
|
void send_homeassistant_service_call(const HomeassistantServiceResponse &call);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// Vector is pre-allocated when services are defined in YAML
|
|
118
|
-
this->user_services_.push_back(descriptor);
|
|
119
|
-
#else
|
|
120
|
-
// Lazy allocate vector on first use for CustomAPIDevice
|
|
121
|
-
if (!this->user_services_) {
|
|
122
|
-
this->user_services_ = std::make_unique<std::vector<UserServiceDescriptor *>>();
|
|
123
|
-
}
|
|
124
|
-
this->user_services_->push_back(descriptor);
|
|
112
|
+
#ifdef USE_API_SERVICES
|
|
113
|
+
void register_user_service(UserServiceDescriptor *descriptor) { this->user_services_.push_back(descriptor); }
|
|
125
114
|
#endif
|
|
126
|
-
}
|
|
127
115
|
#ifdef USE_HOMEASSISTANT_TIME
|
|
128
116
|
void request_time();
|
|
129
117
|
#endif
|
|
@@ -152,17 +140,9 @@ class APIServer : public Component, public Controller {
|
|
|
152
140
|
void get_home_assistant_state(std::string entity_id, optional<std::string> attribute,
|
|
153
141
|
std::function<void(std::string)> f);
|
|
154
142
|
const std::vector<HomeAssistantStateSubscription> &get_state_subs() const;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return this->user_services_;
|
|
158
|
-
#else
|
|
159
|
-
if (this->user_services_) {
|
|
160
|
-
return *this->user_services_;
|
|
161
|
-
}
|
|
162
|
-
// Return reference to global empty instance (no guard needed)
|
|
163
|
-
return get_empty_user_services_instance();
|
|
143
|
+
#ifdef USE_API_SERVICES
|
|
144
|
+
const std::vector<UserServiceDescriptor *> &get_user_services() const { return this->user_services_; }
|
|
164
145
|
#endif
|
|
165
|
-
}
|
|
166
146
|
|
|
167
147
|
#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
|
|
168
148
|
Trigger<std::string, std::string> *get_client_connected_trigger() const { return this->client_connected_trigger_; }
|
|
@@ -194,14 +174,8 @@ class APIServer : public Component, public Controller {
|
|
|
194
174
|
#endif
|
|
195
175
|
std::vector<uint8_t> shared_write_buffer_; // Shared proto write buffer for all connections
|
|
196
176
|
std::vector<HomeAssistantStateSubscription> state_subs_;
|
|
197
|
-
#ifdef
|
|
198
|
-
// When services are defined in YAML, we know at compile time that services will be registered
|
|
177
|
+
#ifdef USE_API_SERVICES
|
|
199
178
|
std::vector<UserServiceDescriptor *> user_services_;
|
|
200
|
-
#else
|
|
201
|
-
// Services can still be registered at runtime by CustomAPIDevice components even when not
|
|
202
|
-
// defined in YAML. Using unique_ptr allows lazy allocation, saving 12 bytes in the common
|
|
203
|
-
// case where no services (YAML or custom) are used.
|
|
204
|
-
std::unique_ptr<std::vector<UserServiceDescriptor *>> user_services_;
|
|
205
179
|
#endif
|
|
206
180
|
|
|
207
181
|
// Group smaller types together
|
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
#include <map>
|
|
4
4
|
#include "api_server.h"
|
|
5
5
|
#ifdef USE_API
|
|
6
|
+
#ifdef USE_API_SERVICES
|
|
6
7
|
#include "user_services.h"
|
|
8
|
+
#endif
|
|
7
9
|
namespace esphome {
|
|
8
10
|
namespace api {
|
|
9
11
|
|
|
12
|
+
#ifdef USE_API_SERVICES
|
|
10
13
|
template<typename T, typename... Ts> class CustomAPIDeviceService : public UserServiceBase<Ts...> {
|
|
11
14
|
public:
|
|
12
15
|
CustomAPIDeviceService(const std::string &name, const std::array<std::string, sizeof...(Ts)> &arg_names, T *obj,
|
|
@@ -19,6 +22,7 @@ template<typename T, typename... Ts> class CustomAPIDeviceService : public UserS
|
|
|
19
22
|
T *obj_;
|
|
20
23
|
void (T::*callback_)(Ts...);
|
|
21
24
|
};
|
|
25
|
+
#endif // USE_API_SERVICES
|
|
22
26
|
|
|
23
27
|
class CustomAPIDevice {
|
|
24
28
|
public:
|
|
@@ -46,12 +50,14 @@ class CustomAPIDevice {
|
|
|
46
50
|
* @param name The name of the service to register.
|
|
47
51
|
* @param arg_names The name of the arguments for the service, must match the arguments of the function.
|
|
48
52
|
*/
|
|
53
|
+
#ifdef USE_API_SERVICES
|
|
49
54
|
template<typename T, typename... Ts>
|
|
50
55
|
void register_service(void (T::*callback)(Ts...), const std::string &name,
|
|
51
56
|
const std::array<std::string, sizeof...(Ts)> &arg_names) {
|
|
52
57
|
auto *service = new CustomAPIDeviceService<T, Ts...>(name, arg_names, (T *) this, callback); // NOLINT
|
|
53
58
|
global_api_server->register_user_service(service);
|
|
54
59
|
}
|
|
60
|
+
#endif
|
|
55
61
|
|
|
56
62
|
/** Register a custom native API service that will show up in Home Assistant.
|
|
57
63
|
*
|
|
@@ -71,10 +77,12 @@ class CustomAPIDevice {
|
|
|
71
77
|
* @param callback The member function to call when the service is triggered.
|
|
72
78
|
* @param name The name of the arguments for the service, must match the arguments of the function.
|
|
73
79
|
*/
|
|
80
|
+
#ifdef USE_API_SERVICES
|
|
74
81
|
template<typename T> void register_service(void (T::*callback)(), const std::string &name) {
|
|
75
82
|
auto *service = new CustomAPIDeviceService<T>(name, {}, (T *) this, callback); // NOLINT
|
|
76
83
|
global_api_server->register_user_service(service);
|
|
77
84
|
}
|
|
85
|
+
#endif
|
|
78
86
|
|
|
79
87
|
/** Subscribe to the state (or attribute state) of an entity from Home Assistant.
|
|
80
88
|
*
|
|
@@ -83,10 +83,12 @@ bool ListEntitiesIterator::on_end() { return this->client_->send_list_info_done(
|
|
|
83
83
|
|
|
84
84
|
ListEntitiesIterator::ListEntitiesIterator(APIConnection *client) : client_(client) {}
|
|
85
85
|
|
|
86
|
+
#ifdef USE_API_SERVICES
|
|
86
87
|
bool ListEntitiesIterator::on_service(UserServiceDescriptor *service) {
|
|
87
88
|
auto resp = service->encode_list_service_response();
|
|
88
89
|
return this->client_->send_message(resp);
|
|
89
90
|
}
|
|
91
|
+
#endif
|
|
90
92
|
|
|
91
93
|
} // namespace api
|
|
92
94
|
} // namespace esphome
|
|
@@ -14,7 +14,7 @@ class APIConnection;
|
|
|
14
14
|
#define LIST_ENTITIES_HANDLER(entity_type, EntityClass, ResponseType) \
|
|
15
15
|
bool ListEntitiesIterator::on_##entity_type(EntityClass *entity) { /* NOLINT(bugprone-macro-parentheses) */ \
|
|
16
16
|
return this->client_->schedule_message_(entity, &APIConnection::try_send_##entity_type##_info, \
|
|
17
|
-
ResponseType::MESSAGE_TYPE); \
|
|
17
|
+
ResponseType::MESSAGE_TYPE, ResponseType::ESTIMATED_SIZE); \
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
class ListEntitiesIterator : public ComponentIterator {
|
|
@@ -44,7 +44,9 @@ class ListEntitiesIterator : public ComponentIterator {
|
|
|
44
44
|
#ifdef USE_TEXT_SENSOR
|
|
45
45
|
bool on_text_sensor(text_sensor::TextSensor *entity) override;
|
|
46
46
|
#endif
|
|
47
|
+
#ifdef USE_API_SERVICES
|
|
47
48
|
bool on_service(UserServiceDescriptor *service) override;
|
|
49
|
+
#endif
|
|
48
50
|
#ifdef USE_CAMERA
|
|
49
51
|
bool on_camera(camera::Camera *entity) override;
|
|
50
52
|
#endif
|