6#ifdef USE_API_PLAINTEXT
9#ifdef USE_API_USER_DEFINED_ACTIONS
30#ifdef USE_HOMEASSISTANT_TIME
33#ifdef USE_BLUETOOTH_PROXY
39#ifdef USE_VOICE_ASSISTANT
52static constexpr uint8_t MAX_MESSAGES_PER_LOOP = 5;
53static constexpr uint8_t MAX_PING_RETRIES = 60;
54static constexpr uint16_t PING_RETRY_INTERVAL = 1000;
55static constexpr uint32_t KEEPALIVE_DISCONNECT_TIMEOUT = (KEEPALIVE_TIMEOUT_MS * 5) / 2;
59static const char *
const TAG =
"api.connection";
61static const int CAMERA_STOP_STREAM = 5000;
67#define ENTITY_COMMAND_MAKE_CALL(entity_type, entity_var, getter_name) \
68 entity_type *entity_var = App.get_##getter_name##_by_key(msg.key, msg.device_id); \
69 if ((entity_var) == nullptr) \
71 auto call = (entity_var)->make_call();
75#define ENTITY_COMMAND_GET(entity_type, entity_var, getter_name) \
76 entity_type *entity_var = App.get_##getter_name##_by_key(msg.key, msg.device_id); \
77 if ((entity_var) == nullptr) \
82#define ENTITY_COMMAND_MAKE_CALL(entity_type, entity_var, getter_name) \
83 entity_type *entity_var = App.get_##getter_name##_by_key(msg.key); \
84 if ((entity_var) == nullptr) \
86 auto call = (entity_var)->make_call();
90#define ENTITY_COMMAND_GET(entity_type, entity_var, getter_name) \
91 entity_type *entity_var = App.get_##getter_name##_by_key(msg.key); \
92 if ((entity_var) == nullptr) \
97 : parent_(parent), initial_state_iterator_(this), list_entities_iterator_(this) {
98#if defined(USE_API_PLAINTEXT) && defined(USE_API_NOISE)
100 if (noise_ctx.has_psk()) {
102 std::unique_ptr<APIFrameHelper>{new APINoiseFrameHelper(std::move(sock), noise_ctx, &this->client_info_)};
104 this->helper_ = std::unique_ptr<APIFrameHelper>{
new APIPlaintextFrameHelper(std::move(sock), &this->client_info_)};
106#elif defined(USE_API_PLAINTEXT)
107 this->helper_ = std::unique_ptr<APIFrameHelper>{
new APIPlaintextFrameHelper(std::move(sock), &this->client_info_)};
108#elif defined(USE_API_NOISE)
109 this->helper_ = std::unique_ptr<APIFrameHelper>{
110 new APINoiseFrameHelper(std::move(sock), parent->get_noise_ctx(), &this->client_info_)};
112#error "No frame helper defined"
121uint32_t APIConnection::get_batch_delay_ms_()
const {
return this->parent_->get_batch_delay(); }
123void APIConnection::start() {
126 APIError err = this->helper_->init();
127 if (err != APIError::OK) {
128 this->fatal_error_with_log_(LOG_STR(
"Helper init failed"), err);
131 this->client_info_.peername = helper_->getpeername();
132 this->client_info_.name = this->client_info_.peername;
135APIConnection::~APIConnection() {
136#ifdef USE_BLUETOOTH_PROXY
141#ifdef USE_VOICE_ASSISTANT
148void APIConnection::loop() {
149 if (this->flags_.next_close) {
151 this->helper_->close();
152 this->flags_.remove =
true;
156 APIError err = this->helper_->loop();
157 if (err != APIError::OK) {
158 this->fatal_error_with_log_(LOG_STR(
"Socket operation failed"), err);
164 if (this->helper_->is_socket_ready()) {
166 for (uint8_t message_count = 0; message_count < MAX_MESSAGES_PER_LOOP; message_count++) {
168 err = this->helper_->read_packet(&buffer);
169 if (err == APIError::WOULD_BLOCK) {
172 }
else if (err != APIError::OK) {
173 this->fatal_error_with_log_(LOG_STR(
"Reading failed"), err);
176 this->last_traffic_ = now;
179 if (this->flags_.remove)
186 if (this->flags_.batch_scheduled && now - this->deferred_batch_.batch_start_time >= this->get_batch_delay_ms_()) {
187 this->process_batch_();
190 if (!this->list_entities_iterator_.completed()) {
191 this->process_iterator_batch_(this->list_entities_iterator_);
192 }
else if (!this->initial_state_iterator_.completed()) {
193 this->process_iterator_batch_(this->initial_state_iterator_);
196 if (this->initial_state_iterator_.completed()) {
198 if (!this->deferred_batch_.empty()) {
199 this->process_batch_();
202 this->flags_.should_try_send_immediately =
true;
204 this->deferred_batch_.release_buffer();
205 this->helper_->release_buffers();
209 if (this->flags_.sent_ping) {
211 if (now - this->last_traffic_ > KEEPALIVE_DISCONNECT_TIMEOUT) {
213 ESP_LOGW(TAG,
"%s (%s) is unresponsive; disconnecting", this->client_info_.name.c_str(),
214 this->client_info_.peername.c_str());
216 }
else if (now - this->last_traffic_ > KEEPALIVE_TIMEOUT_MS && !this->flags_.remove) {
218 ESP_LOGVV(TAG,
"Sending keepalive PING");
220 this->flags_.sent_ping = this->send_message(req, PingRequest::MESSAGE_TYPE);
221 if (!this->flags_.sent_ping) {
224 ESP_LOGW(TAG,
"Buffer full, ping queued");
225 this->schedule_message_front_(
nullptr, &APIConnection::try_send_ping_request, PingRequest::MESSAGE_TYPE,
226 PingRequest::ESTIMATED_SIZE);
227 this->flags_.sent_ping =
true;
232 if (this->image_reader_ && this->image_reader_->available() && this->helper_->can_write_without_blocking()) {
233 uint32_t to_send = std::min((
size_t) MAX_BATCH_PACKET_SIZE, this->image_reader_->available());
234 bool done = this->image_reader_->available() == to_send;
238 msg.
set_data(this->image_reader_->peek_data_buffer(), to_send);
244 if (this->send_message_(msg, CameraImageResponse::MESSAGE_TYPE)) {
245 this->image_reader_->consume_data(to_send);
247 this->image_reader_->return_image();
253#ifdef USE_API_HOMEASSISTANT_STATES
254 if (state_subs_at_ >= 0) {
255 this->process_state_subscriptions_();
264 ESP_LOGD(TAG,
"%s (%s) disconnected", this->client_info_.name.c_str(), this->client_info_.peername.c_str());
265 this->flags_.next_close =
true;
267 return this->send_message(resp, DisconnectResponse::MESSAGE_TYPE);
270 this->helper_->close();
271 this->flags_.remove =
true;
277 uint32_t remaining_size,
bool is_single) {
278#ifdef HAS_PROTO_MESSAGE_DUMP
289 uint32_t calculated_size = size_calc.
get_size();
292 const uint8_t header_padding = conn->
helper_->frame_header_padding();
293 const uint8_t footer_size = conn->
helper_->frame_footer_size();
296 size_t total_calculated_size = calculated_size + header_padding + footer_size;
299 if (total_calculated_size > remaining_size) {
315 size_t current_size = shared_buf.size();
316 shared_buf.reserve(current_size + total_calculated_size);
317 shared_buf.resize(current_size + footer_size + header_padding);
321 size_t size_before_encode = shared_buf.size();
322 msg.
encode({&shared_buf});
325 size_t actual_payload_size = shared_buf.size() - size_before_encode;
328 size_t actual_total_size = header_padding + actual_payload_size + footer_size;
331 assert(calculated_size == actual_payload_size);
332 return static_cast<uint16_t
>(actual_total_size);
335#ifdef USE_BINARY_SENSOR
337 return this->send_message_smart_(binary_sensor, &APIConnection::try_send_binary_sensor_state,
338 BinarySensorStateResponse::MESSAGE_TYPE, BinarySensorStateResponse::ESTIMATED_SIZE);
345 resp.
state = binary_sensor->state;
347 return fill_and_encode_entity_state(binary_sensor, resp, BinarySensorStateResponse::MESSAGE_TYPE, conn,
348 remaining_size, is_single);
357 return fill_and_encode_entity_info(binary_sensor, msg, ListEntitiesBinarySensorResponse::MESSAGE_TYPE, conn,
358 remaining_size, is_single);
364 return this->send_message_smart_(cover, &APIConnection::try_send_cover_state, CoverStateResponse::MESSAGE_TYPE,
365 CoverStateResponse::ESTIMATED_SIZE);
371 auto traits = cover->get_traits();
373 if (traits.get_supports_tilt())
374 msg.
tilt = cover->tilt;
376 return fill_and_encode_entity_state(cover, msg, CoverStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
382 auto traits = cover->get_traits();
388 return fill_and_encode_entity_info(cover, msg, ListEntitiesCoverResponse::MESSAGE_TYPE, conn, remaining_size,
396 call.set_tilt(msg.
tilt);
398 call.set_command_stop();
405 return this->send_message_smart_(fan, &APIConnection::try_send_fan_state, FanStateResponse::MESSAGE_TYPE,
406 FanStateResponse::ESTIMATED_SIZE);
410 auto *fan =
static_cast<fan::Fan *
>(entity);
412 auto traits = fan->get_traits();
413 msg.
state = fan->state;
414 if (traits.supports_oscillation())
416 if (traits.supports_speed()) {
419 if (traits.supports_direction())
421 if (traits.supports_preset_modes() && fan->has_preset_mode())
423 return fill_and_encode_entity_state(fan, msg, FanStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
427 auto *fan =
static_cast<fan::Fan *
>(entity);
429 auto traits = fan->get_traits();
435 return fill_and_encode_entity_info(fan, msg, ListEntitiesFanResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
438 ENTITY_COMMAND_MAKE_CALL(
fan::Fan, fan, fan)
440 call.set_state(msg.
state);
457 return this->send_message_smart_(light, &APIConnection::try_send_light_state, LightStateResponse::MESSAGE_TYPE,
458 LightStateResponse::ESTIMATED_SIZE);
464 auto values = light->remote_values;
465 auto color_mode = values.get_color_mode();
466 resp.
state = values.is_on();
470 resp.
red = values.get_red();
471 resp.
green = values.get_green();
472 resp.
blue = values.get_blue();
473 resp.
white = values.get_white();
477 if (light->supports_effects()) {
478 resp.
set_effect(light->get_effect_name_ref());
480 return fill_and_encode_entity_state(light, resp, LightStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
486 auto traits = light->get_traits();
487 auto supported_modes = traits.get_supported_color_modes();
496 if (light->supports_effects()) {
497 auto &light_effects = light->get_effects();
498 effects_list.
init(light_effects.size() + 1);
500 for (
auto *effect : light_effects) {
501 effects_list.
push_back(effect->get_name());
505 return fill_and_encode_entity_info(light, msg, ListEntitiesLightResponse::MESSAGE_TYPE, conn, remaining_size,
511 call.set_state(msg.
state);
519 call.set_red(msg.
red);
520 call.set_green(msg.
green);
521 call.set_blue(msg.
blue);
524 call.set_white(msg.
white);
536 call.set_effect(
reinterpret_cast<const char *
>(msg.
effect), msg.
effect_len);
543 return this->send_message_smart_(sensor, &APIConnection::try_send_sensor_state, SensorStateResponse::MESSAGE_TYPE,
544 SensorStateResponse::ESTIMATED_SIZE);
551 resp.
state = sensor->state;
553 return fill_and_encode_entity_state(sensor, resp, SensorStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
565 return fill_and_encode_entity_info(sensor, msg, ListEntitiesSensorResponse::MESSAGE_TYPE, conn, remaining_size,
572 return this->send_message_smart_(a_switch, &APIConnection::try_send_switch_state, SwitchStateResponse::MESSAGE_TYPE,
573 SwitchStateResponse::ESTIMATED_SIZE);
580 resp.
state = a_switch->state;
581 return fill_and_encode_entity_state(a_switch, resp, SwitchStateResponse::MESSAGE_TYPE, conn, remaining_size,
591 return fill_and_encode_entity_info(a_switch, msg, ListEntitiesSwitchResponse::MESSAGE_TYPE, conn, remaining_size,
600 a_switch->turn_off();
605#ifdef USE_TEXT_SENSOR
607 return this->send_message_smart_(text_sensor, &APIConnection::try_send_text_sensor_state,
608 TextSensorStateResponse::MESSAGE_TYPE, TextSensorStateResponse::ESTIMATED_SIZE);
617 return fill_and_encode_entity_state(text_sensor, resp, TextSensorStateResponse::MESSAGE_TYPE, conn, remaining_size,
625 return fill_and_encode_entity_info(text_sensor, msg, ListEntitiesTextSensorResponse::MESSAGE_TYPE, conn,
626 remaining_size, is_single);
632 return this->send_message_smart_(climate, &APIConnection::try_send_climate_state, ClimateStateResponse::MESSAGE_TYPE,
633 ClimateStateResponse::ESTIMATED_SIZE);
639 auto traits = climate->get_traits();
651 if (traits.get_supports_fan_modes() && climate->fan_mode.has_value())
653 if (!traits.get_supported_custom_fan_modes().empty() && climate->has_custom_fan_mode()) {
656 if (traits.get_supports_presets() && climate->preset.has_value()) {
659 if (!traits.get_supported_custom_presets().empty() && climate->has_custom_preset()) {
662 if (traits.get_supports_swing_modes())
668 return fill_and_encode_entity_state(climate, resp, ClimateStateResponse::MESSAGE_TYPE, conn, remaining_size,
675 auto traits = climate->get_traits();
697 return fill_and_encode_entity_info(climate, msg, ListEntitiesClimateResponse::MESSAGE_TYPE, conn, remaining_size,
728 return this->send_message_smart_(number, &APIConnection::try_send_number_state, NumberStateResponse::MESSAGE_TYPE,
729 NumberStateResponse::ESTIMATED_SIZE);
736 resp.
state = number->state;
738 return fill_and_encode_entity_state(number, resp, NumberStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
748 msg.
min_value = number->traits.get_min_value();
749 msg.
max_value = number->traits.get_max_value();
750 msg.
step = number->traits.get_step();
751 return fill_and_encode_entity_info(number, msg, ListEntitiesNumberResponse::MESSAGE_TYPE, conn, remaining_size,
756 call.set_value(msg.
state);
761#ifdef USE_DATETIME_DATE
763 return this->send_message_smart_(date, &APIConnection::try_send_date_state, DateStateResponse::MESSAGE_TYPE,
764 DateStateResponse::ESTIMATED_SIZE);
771 resp.
year = date->year;
772 resp.
month = date->month;
773 resp.
day = date->day;
774 return fill_and_encode_entity_state(date, resp, DateStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
780 return fill_and_encode_entity_info(date, msg, ListEntitiesDateResponse::MESSAGE_TYPE, conn, remaining_size,
790#ifdef USE_DATETIME_TIME
792 return this->send_message_smart_(time, &APIConnection::try_send_time_state, TimeStateResponse::MESSAGE_TYPE,
793 TimeStateResponse::ESTIMATED_SIZE);
800 resp.
hour = time->hour;
801 resp.
minute = time->minute;
802 resp.
second = time->second;
803 return fill_and_encode_entity_state(time, resp, TimeStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
809 return fill_and_encode_entity_info(time, msg, ListEntitiesTimeResponse::MESSAGE_TYPE, conn, remaining_size,
819#ifdef USE_DATETIME_DATETIME
821 return this->send_message_smart_(datetime, &APIConnection::try_send_datetime_state,
822 DateTimeStateResponse::MESSAGE_TYPE, DateTimeStateResponse::ESTIMATED_SIZE);
829 if (datetime->has_state()) {
833 return fill_and_encode_entity_state(datetime, resp, DateTimeStateResponse::MESSAGE_TYPE, conn, remaining_size,
840 return fill_and_encode_entity_info(datetime, msg, ListEntitiesDateTimeResponse::MESSAGE_TYPE, conn, remaining_size,
852 return this->send_message_smart_(text, &APIConnection::try_send_text_state, TextStateResponse::MESSAGE_TYPE,
853 TextStateResponse::ESTIMATED_SIZE);
858 auto *text =
static_cast<text::Text *
>(entity);
862 return fill_and_encode_entity_state(text, resp, TextStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
867 auto *text =
static_cast<text::Text *
>(entity);
870 msg.
min_length = text->traits.get_min_length();
871 msg.
max_length = text->traits.get_max_length();
873 return fill_and_encode_entity_info(text, msg, ListEntitiesTextResponse::MESSAGE_TYPE, conn, remaining_size,
877 ENTITY_COMMAND_MAKE_CALL(
text::Text, text, text)
878 call.set_value(msg.
state);
885 return this->send_message_smart_(select, &APIConnection::try_send_select_state, SelectStateResponse::MESSAGE_TYPE,
886 SelectStateResponse::ESTIMATED_SIZE);
895 return fill_and_encode_entity_state(select, resp, SelectStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
902 msg.
options = &select->traits.get_options();
903 return fill_and_encode_entity_info(select, msg, ListEntitiesSelectResponse::MESSAGE_TYPE, conn, remaining_size,
908 call.set_option(
reinterpret_cast<const char *
>(msg.
state), msg.
state_len);
919 return fill_and_encode_entity_info(button, msg, ListEntitiesButtonResponse::MESSAGE_TYPE, conn, remaining_size,
930 return this->send_message_smart_(a_lock, &APIConnection::try_send_lock_state, LockStateResponse::MESSAGE_TYPE,
931 LockStateResponse::ESTIMATED_SIZE);
936 auto *a_lock =
static_cast<lock::Lock *
>(entity);
939 return fill_and_encode_entity_state(a_lock, resp, LockStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
944 auto *a_lock =
static_cast<lock::Lock *
>(entity);
949 return fill_and_encode_entity_info(a_lock, msg, ListEntitiesLockResponse::MESSAGE_TYPE, conn, remaining_size,
956 case enums::LOCK_UNLOCK:
959 case enums::LOCK_LOCK:
962 case enums::LOCK_OPEN:
971 return this->send_message_smart_(valve, &APIConnection::try_send_valve_state, ValveStateResponse::MESSAGE_TYPE,
972 ValveStateResponse::ESTIMATED_SIZE);
980 return fill_and_encode_entity_state(valve, resp, ValveStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
986 auto traits = valve->get_traits();
991 return fill_and_encode_entity_info(valve, msg, ListEntitiesValveResponse::MESSAGE_TYPE, conn, remaining_size,
999 call.set_command_stop();
1004#ifdef USE_MEDIA_PLAYER
1006 return this->send_message_smart_(media_player, &APIConnection::try_send_media_player_state,
1007 MediaPlayerStateResponse::MESSAGE_TYPE, MediaPlayerStateResponse::ESTIMATED_SIZE);
1015 : media_player->state;
1017 resp.
volume = media_player->volume;
1018 resp.
muted = media_player->is_muted();
1019 return fill_and_encode_entity_state(media_player, resp, MediaPlayerStateResponse::MESSAGE_TYPE, conn, remaining_size,
1026 auto traits = media_player->get_traits();
1029 for (
auto &supported_format : traits.get_supported_formats()) {
1032 media_format.set_format(
StringRef(supported_format.format));
1033 media_format.sample_rate = supported_format.sample_rate;
1034 media_format.num_channels = supported_format.num_channels;
1036 media_format.sample_bytes = supported_format.sample_bytes;
1038 return fill_and_encode_entity_info(media_player, msg, ListEntitiesMediaPlayerResponse::MESSAGE_TYPE, conn,
1039 remaining_size, is_single);
1047 call.set_volume(msg.
volume);
1060void APIConnection::set_camera_state(std::shared_ptr<camera::CameraImage> image) {
1061 if (!this->flags_.state_subscription)
1063 if (!this->image_reader_)
1065 if (this->image_reader_->available())
1068 this->image_reader_->set_image(std::move(image));
1074 return fill_and_encode_entity_info(camera, msg, ListEntitiesCameraResponse::MESSAGE_TYPE, conn, remaining_size,
1086 App.scheduler.set_timeout(this->parent_,
"api_camera_stop_stream", CAMERA_STOP_STREAM,
1092#ifdef USE_HOMEASSISTANT_TIME
1096#ifdef USE_TIME_TIMEZONE
1106#ifdef USE_BLUETOOTH_PROXY
1136bool APIConnection::send_subscribe_bluetooth_connections_free_response(
1144 msg.
mode == enums::BluetoothScannerMode::BLUETOOTH_SCANNER_MODE_ACTIVE);
1148#ifdef USE_VOICE_ASSISTANT
1149bool APIConnection::check_voice_assistant_api_connection_()
const {
1160 if (!this->check_voice_assistant_api_connection_()) {
1168 if (msg.
port == 0) {
1174 this->helper_->getpeername((
struct sockaddr *) &storage, &
len);
1179 if (this->check_voice_assistant_api_connection_()) {
1184 if (this->check_voice_assistant_api_connection_()) {
1189 if (this->check_voice_assistant_api_connection_()) {
1195 if (this->check_voice_assistant_api_connection_()) {
1202 if (!this->check_voice_assistant_api_connection_()) {
1203 return this->send_message(resp, VoiceAssistantConfigurationResponse::MESSAGE_TYPE);
1207 for (
auto &wake_word : config.available_wake_words) {
1210 resp_wake_word.set_id(
StringRef(wake_word.id));
1211 resp_wake_word.set_wake_word(
StringRef(wake_word.wake_word));
1212 for (
const auto &lang : wake_word.trained_languages) {
1213 resp_wake_word.trained_languages.push_back(lang);
1219 if (wake_word.model_type !=
"micro") {
1226 resp_wake_word.set_id(
StringRef(wake_word.id));
1227 resp_wake_word.set_wake_word(
StringRef(wake_word.wake_word));
1228 for (
const auto &lang : wake_word.trained_languages) {
1229 resp_wake_word.trained_languages.push_back(lang);
1235 return this->send_message(resp, VoiceAssistantConfigurationResponse::MESSAGE_TYPE);
1239 if (this->check_voice_assistant_api_connection_()) {
1245#ifdef USE_ZWAVE_PROXY
1255#ifdef USE_ALARM_CONTROL_PANEL
1257 return this->send_message_smart_(a_alarm_control_panel, &APIConnection::try_send_alarm_control_panel_state,
1258 AlarmControlPanelStateResponse::MESSAGE_TYPE,
1259 AlarmControlPanelStateResponse::ESTIMATED_SIZE);
1262 uint32_t remaining_size,
bool is_single) {
1266 return fill_and_encode_entity_state(a_alarm_control_panel, resp, AlarmControlPanelStateResponse::MESSAGE_TYPE, conn,
1267 remaining_size, is_single);
1270 uint32_t remaining_size,
bool is_single) {
1274 msg.
requires_code = a_alarm_control_panel->get_requires_code();
1276 return fill_and_encode_entity_info(a_alarm_control_panel, msg, ListEntitiesAlarmControlPanelResponse::MESSAGE_TYPE,
1277 conn, remaining_size, is_single);
1282 case enums::ALARM_CONTROL_PANEL_DISARM:
1285 case enums::ALARM_CONTROL_PANEL_ARM_AWAY:
1288 case enums::ALARM_CONTROL_PANEL_ARM_HOME:
1291 case enums::ALARM_CONTROL_PANEL_ARM_NIGHT:
1294 case enums::ALARM_CONTROL_PANEL_ARM_VACATION:
1295 call.arm_vacation();
1297 case enums::ALARM_CONTROL_PANEL_ARM_CUSTOM_BYPASS:
1298 call.arm_custom_bypass();
1300 case enums::ALARM_CONTROL_PANEL_TRIGGER:
1304 call.set_code(msg.
code);
1310void APIConnection::send_event(
event::Event *event,
const char *event_type) {
1311 this->send_message_smart_(event,
MessageCreator(event_type), EventResponse::MESSAGE_TYPE,
1312 EventResponse::ESTIMATED_SIZE);
1315 uint32_t remaining_size,
bool is_single) {
1318 return fill_and_encode_entity_state(event, resp, EventResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
1327 return fill_and_encode_entity_info(event, msg, ListEntitiesEventResponse::MESSAGE_TYPE, conn, remaining_size,
1334 return this->send_message_smart_(update, &APIConnection::try_send_update_state, UpdateStateResponse::MESSAGE_TYPE,
1335 UpdateStateResponse::ESTIMATED_SIZE);
1342 if (update->has_state()) {
1344 if (update->update_info.has_progress) {
1346 resp.
progress = update->update_info.progress;
1354 return fill_and_encode_entity_state(update, resp, UpdateStateResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
1361 return fill_and_encode_entity_info(update, msg, ListEntitiesUpdateResponse::MESSAGE_TYPE, conn, remaining_size,
1368 case enums::UPDATE_COMMAND_UPDATE:
1371 case enums::UPDATE_COMMAND_CHECK:
1374 case enums::UPDATE_COMMAND_NONE:
1375 ESP_LOGE(TAG,
"UPDATE_COMMAND_NONE not handled; confirm command is correct");
1378 ESP_LOGW(TAG,
"Unknown update command: %" PRIu32, msg.
command);
1384bool APIConnection::try_send_log_message(
int level,
const char *tag,
const char *line,
size_t message_len) {
1387 msg.
set_message(
reinterpret_cast<const uint8_t *
>(line), message_len);
1388 return this->send_message_(msg, SubscribeLogsResponse::MESSAGE_TYPE);
1391void APIConnection::complete_authentication_() {
1393 if (this->flags_.connection_state ==
static_cast<uint8_t
>(ConnectionState::AUTHENTICATED)) {
1397 this->flags_.connection_state =
static_cast<uint8_t
>(ConnectionState::AUTHENTICATED);
1398 ESP_LOGD(TAG,
"%s (%s) connected", this->client_info_.name.c_str(), this->client_info_.peername.c_str());
1399#ifdef USE_API_CLIENT_CONNECTED_TRIGGER
1400 this->parent_->get_client_connected_trigger()->trigger(this->client_info_.name, this->client_info_.peername);
1402#ifdef USE_HOMEASSISTANT_TIME
1404 this->send_time_request();
1407#ifdef USE_ZWAVE_PROXY
1416 this->client_info_.peername = this->helper_->getpeername();
1419 ESP_LOGV(TAG,
"Hello from client: '%s' | %s | API Version %" PRIu32
".%" PRIu32, this->client_info_.name.c_str(),
1420 this->client_info_.peername.c_str(), this->client_api_version_major_, this->client_api_version_minor_);
1429#ifdef USE_API_PASSWORD
1431 this->flags_.connection_state =
static_cast<uint8_t
>(ConnectionState::CONNECTED);
1434 this->complete_authentication_();
1437 return this->send_message(resp, HelloResponse::MESSAGE_TYPE);
1439#ifdef USE_API_PASSWORD
1445 this->complete_authentication_();
1447 return this->send_message(resp, AuthenticationResponse::MESSAGE_TYPE);
1453 return this->send_message(resp, PingResponse::MESSAGE_TYPE);
1458#ifdef USE_API_PASSWORD
1467 char mac_address[18];
1471 resp.set_mac_address(
StringRef(mac_address));
1473 resp.set_esphome_version(ESPHOME_VERSION_REF);
1478#if defined(USE_ESP8266) || defined(USE_ESP32)
1479#define ESPHOME_MANUFACTURER "Espressif"
1480#elif defined(USE_RP2040)
1481#define ESPHOME_MANUFACTURER "Raspberry Pi"
1482#elif defined(USE_BK72XX)
1483#define ESPHOME_MANUFACTURER "Beken"
1484#elif defined(USE_LN882X)
1485#define ESPHOME_MANUFACTURER "Lightning"
1486#elif defined(USE_NRF52)
1487#define ESPHOME_MANUFACTURER "Nordic Semiconductor"
1488#elif defined(USE_RTL87XX)
1489#define ESPHOME_MANUFACTURER "Realtek"
1490#elif defined(USE_HOST)
1491#define ESPHOME_MANUFACTURER "Host"
1496 static const char MANUFACTURER_PROGMEM[]
PROGMEM = ESPHOME_MANUFACTURER;
1497 char manufacturer_buf[
sizeof(MANUFACTURER_PROGMEM)];
1498 memcpy_P(manufacturer_buf, MANUFACTURER_PROGMEM,
sizeof(MANUFACTURER_PROGMEM));
1499 resp.set_manufacturer(
StringRef(manufacturer_buf,
sizeof(MANUFACTURER_PROGMEM) - 1));
1502 resp.set_manufacturer(MANUFACTURER);
1504#undef ESPHOME_MANUFACTURER
1507 static const char MODEL_PROGMEM[]
PROGMEM = ESPHOME_BOARD;
1508 char model_buf[
sizeof(MODEL_PROGMEM)];
1509 memcpy_P(model_buf, MODEL_PROGMEM,
sizeof(MODEL_PROGMEM));
1510 resp.set_model(
StringRef(model_buf,
sizeof(MODEL_PROGMEM) - 1));
1513 resp.set_model(MODEL);
1515#ifdef USE_DEEP_SLEEP
1518#ifdef ESPHOME_PROJECT_NAME
1520 static const char PROJECT_NAME_PROGMEM[]
PROGMEM = ESPHOME_PROJECT_NAME;
1521 static const char PROJECT_VERSION_PROGMEM[]
PROGMEM = ESPHOME_PROJECT_VERSION;
1522 char project_name_buf[
sizeof(PROJECT_NAME_PROGMEM)];
1523 char project_version_buf[
sizeof(PROJECT_VERSION_PROGMEM)];
1524 memcpy_P(project_name_buf, PROJECT_NAME_PROGMEM,
sizeof(PROJECT_NAME_PROGMEM));
1525 memcpy_P(project_version_buf, PROJECT_VERSION_PROGMEM,
sizeof(PROJECT_VERSION_PROGMEM));
1526 resp.set_project_name(
StringRef(project_name_buf,
sizeof(PROJECT_NAME_PROGMEM) - 1));
1527 resp.set_project_version(
StringRef(project_version_buf,
sizeof(PROJECT_VERSION_PROGMEM) - 1));
1531 resp.set_project_name(PROJECT_NAME);
1532 resp.set_project_version(PROJECT_VERSION);
1536 resp.webserver_port = USE_WEBSERVER_PORT;
1538#ifdef USE_BLUETOOTH_PROXY
1541 char bluetooth_mac[18];
1543 resp.set_bluetooth_mac_address(
StringRef(bluetooth_mac));
1545#ifdef USE_VOICE_ASSISTANT
1548#ifdef USE_ZWAVE_PROXY
1553 resp.api_encryption_supported =
true;
1556 size_t device_index = 0;
1558 if (device_index >= ESPHOME_DEVICE_COUNT)
1560 auto &device_info = resp.devices[device_index++];
1561 device_info.device_id = device->get_device_id();
1562 device_info.set_name(
StringRef(device->get_name()));
1563 device_info.area_id = device->get_area_id();
1567 size_t area_index = 0;
1569 if (area_index >= ESPHOME_AREA_COUNT)
1571 auto &area_info = resp.areas[area_index++];
1572 area_info.area_id = area->get_area_id();
1573 area_info.set_name(
StringRef(area->get_name()));
1577 return this->send_message(resp, DeviceInfoResponse::MESSAGE_TYPE);
1580#ifdef USE_API_HOMEASSISTANT_STATES
1582 for (
auto &it : this->parent_->get_state_subs()) {
1584 bool entity_match = (strcmp(it.entity_id, msg.
entity_id.c_str()) == 0);
1585 bool attribute_match = (it.attribute !=
nullptr && strcmp(it.attribute, msg.
attribute.c_str()) == 0) ||
1586 (it.attribute ==
nullptr && msg.
attribute.empty());
1588 if (entity_match && attribute_match) {
1589 it.callback(msg.
state);
1594#ifdef USE_API_USER_DEFINED_ACTIONS
1597#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
1600 uint32_t action_call_id = 0;
1602 action_call_id = this->parent_->register_active_action_call(msg.
call_id,
this);
1605 for (
auto *service : this->parent_->get_user_services()) {
1606 if (service->execute_service(msg, action_call_id)) {
1611 for (
auto *service : this->parent_->get_user_services()) {
1612 if (service->execute_service(msg)) {
1618 ESP_LOGV(TAG,
"Could not find service");
1624#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES
1625void APIConnection::send_execute_service_response(uint32_t call_id,
bool success,
const std::string &error_message) {
1630 this->send_message(resp, ExecuteServiceResponse::MESSAGE_TYPE);
1632#ifdef USE_API_USER_DEFINED_ACTION_RESPONSES_JSON
1633void APIConnection::send_execute_service_response(uint32_t call_id,
bool success,
const std::string &error_message,
1634 const uint8_t *response_data,
size_t response_data_len) {
1641 this->send_message(resp, ExecuteServiceResponse::MESSAGE_TYPE);
1647#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES
1649#ifdef USE_API_HOMEASSISTANT_ACTION_RESPONSES_JSON
1666 if (msg.
key.empty()) {
1667 if (this->parent_->clear_noise_psk(
true)) {
1670 ESP_LOGW(TAG,
"Failed to clear encryption key");
1673 ESP_LOGW(TAG,
"Invalid encryption key length");
1674 }
else if (!this->parent_->save_noise_psk(psk,
true)) {
1675 ESP_LOGW(TAG,
"Failed to save encryption key");
1680 return this->send_message(resp, NoiseEncryptionSetKeyResponse::MESSAGE_TYPE);
1683#ifdef USE_API_HOMEASSISTANT_STATES
1688bool APIConnection::try_to_clear_buffer(
bool log_out_of_space) {
1689 if (this->flags_.remove)
1691 if (this->helper_->can_write_without_blocking())
1694 APIError err = this->helper_->loop();
1695 if (err != APIError::OK) {
1696 this->fatal_error_with_log_(LOG_STR(
"Socket operation failed"), err);
1699 if (this->helper_->can_write_without_blocking())
1701 if (log_out_of_space) {
1702 ESP_LOGV(TAG,
"Cannot send message because of TCP buffer space");
1707 if (!this->try_to_clear_buffer(message_type != SubscribeLogsResponse::MESSAGE_TYPE)) {
1711 APIError err = this->helper_->write_protobuf_packet(message_type, buffer);
1712 if (err == APIError::WOULD_BLOCK)
1714 if (err != APIError::OK) {
1715 this->fatal_error_with_log_(LOG_STR(
"Packet write failed"), err);
1721#ifdef USE_API_PASSWORD
1722void APIConnection::on_unauthenticated_access() {
1723 this->on_fatal_error();
1724 ESP_LOGD(TAG,
"%s (%s) no authentication", this->client_info_.name.c_str(), this->client_info_.peername.c_str());
1727void APIConnection::on_no_setup_connection() {
1728 this->on_fatal_error();
1729 ESP_LOGD(TAG,
"%s (%s) no connection setup", this->client_info_.name.c_str(), this->client_info_.peername.c_str());
1731void APIConnection::on_fatal_error() {
1732 this->helper_->close();
1733 this->flags_.remove =
true;
1737 uint8_t estimated_size) {
1741 for (
auto &item : items) {
1742 if (item.entity == entity && item.message_type == message_type) {
1744 item.creator = creator;
1750 items.emplace_back(entity, creator, message_type, estimated_size);
1754 uint8_t estimated_size) {
1759 items.emplace_back(entity, creator, message_type, estimated_size);
1760 if (items.size() > 1) {
1762 std::swap(items.front(), items.back());
1766bool APIConnection::schedule_batch_() {
1767 if (!this->flags_.batch_scheduled) {
1768 this->flags_.batch_scheduled =
true;
1774void APIConnection::process_batch_() {
1776 static_assert(std::is_trivially_destructible<PacketInfo>::value,
1777 "PacketInfo must remain trivially destructible with this placement-new approach");
1779 if (this->deferred_batch_.empty()) {
1780 this->flags_.batch_scheduled =
false;
1785 if (!this->try_to_clear_buffer(
true)) {
1791 auto &shared_buf = this->parent_->get_shared_buffer_ref();
1792 size_t num_items = this->deferred_batch_.size();
1795 if (num_items == 1) {
1796 const auto &item = this->deferred_batch_[0];
1800 item.creator(item.entity,
this, std::numeric_limits<uint16_t>::max(),
true, item.message_type);
1803#ifdef HAS_PROTO_MESSAGE_DUMP
1806 this->log_batch_item_(item);
1808 this->clear_batch_();
1811 ESP_LOGW(TAG,
"Message too large to send: type=%u", item.message_type);
1812 this->clear_batch_();
1817 size_t packets_to_process = std::min(num_items, MAX_PACKETS_PER_BATCH);
1822 size_t packet_count = 0;
1825 const uint8_t header_padding = this->helper_->frame_header_padding();
1826 const uint8_t footer_size = this->helper_->frame_footer_size();
1832 uint32_t total_estimated_size = num_items * (header_padding + footer_size);
1833 for (
size_t i = 0; i < this->deferred_batch_.size(); i++) {
1834 const auto &item = this->deferred_batch_[i];
1835 total_estimated_size += item.estimated_size;
1840 shared_buf.reserve(total_estimated_size);
1841 this->flags_.batch_first_message =
true;
1843 size_t items_processed = 0;
1844 uint16_t remaining_size = std::numeric_limits<uint16_t>::max();
1850 uint32_t current_offset = 0;
1853 for (
size_t i = 0; i < packets_to_process; i++) {
1854 const auto &item = this->deferred_batch_[i];
1857 uint16_t
payload_size = item.creator(item.entity,
this, remaining_size,
false, item.message_type);
1866 uint16_t proto_payload_size =
payload_size - header_padding - footer_size;
1871 new (&packet_info[packet_count++])
PacketInfo(item.message_type, current_offset, proto_payload_size);
1876 if (items_processed == 1) {
1877 remaining_size = MAX_BATCH_PACKET_SIZE;
1882 current_offset = shared_buf.size() + footer_size;
1885 if (items_processed == 0) {
1886 this->deferred_batch_.clear();
1891 if (footer_size > 0) {
1892 shared_buf.resize(shared_buf.size() + footer_size);
1897 std::span<const PacketInfo>(packet_info, packet_count));
1898 if (err != APIError::OK && err != APIError::WOULD_BLOCK) {
1899 this->fatal_error_with_log_(LOG_STR(
"Batch write failed"), err);
1902#ifdef HAS_PROTO_MESSAGE_DUMP
1905 for (
size_t i = 0; i < items_processed; i++) {
1906 const auto &item = this->deferred_batch_[i];
1907 this->log_batch_item_(item);
1912 if (items_processed < this->deferred_batch_.size()) {
1914 this->deferred_batch_.remove_front(items_processed);
1916 this->schedule_batch_();
1919 this->clear_batch_();
1924 bool is_single, uint8_t message_type)
const {
1927 if (message_type == EventResponse::MESSAGE_TYPE) {
1929 return APIConnection::try_send_event_response(e, data_.const_char_ptr, conn, remaining_size, is_single);
1934 return data_.function_ptr(entity, conn, remaining_size, is_single);
1940 return encode_message_to_buffer(resp, ListEntitiesDoneResponse::MESSAGE_TYPE, conn, remaining_size, is_single);
1946 return encode_message_to_buffer(req, DisconnectRequest::MESSAGE_TYPE, conn, remaining_size, is_single);
1952 return encode_message_to_buffer(req, PingRequest::MESSAGE_TYPE, conn, remaining_size, is_single);
1955#ifdef USE_API_HOMEASSISTANT_STATES
1956void APIConnection::process_state_subscriptions_() {
1957 const auto &subs = this->parent_->get_state_subs();
1958 if (this->state_subs_at_ >=
static_cast<int>(subs.size())) {
1959 this->state_subs_at_ = -1;
1963 const auto &it = subs[this->state_subs_at_];
1970 resp.
once = it.once;
1971 if (this->send_message(resp, SubscribeHomeAssistantStateResponse::MESSAGE_TYPE)) {
1972 this->state_subs_at_++;
1978 ESP_LOGW(TAG,
"%s (%s): %s %s errno=%d", this->client_info_.name.c_str(), this->client_info_.peername.c_str(),
const std::string & get_friendly_name() const
Get the friendly name of this Application set by pre_setup().
const char * get_area() const
Get the area of this Application set by pre_setup().
const auto & get_devices()
const std::string & get_name() const
Get the name of this Application set by pre_setup().
StringRef get_compilation_time_ref() const
Get the compilation time as StringRef (for API usage)
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
uint32_t get_object_id_hash()
uint32_t get_device_id() const
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
void push_back(const T &value)
Add element without bounds checking Caller must ensure sufficient capacity was allocated via init() S...
StringRef is a reference to a string owned by something else.
static constexpr StringRef from_lit(const CharT(&s)[N])
struct esphome::api::APIConnection::APIFlags flags_
void prepare_first_message_buffer(std::vector< uint8_t > &shared_buf, size_t header_padding, size_t total_size)
std::unique_ptr< APIFrameHelper > helper_
APIConnection(std::unique_ptr< socket::Socket > socket, APIServer *parent)
void button_command(const ButtonCommandRequest &msg) override
void log_send_message_(const char *name, const std::string &dump)
APINoiseContext & get_noise_ctx()
std::vector< uint8_t > & get_shared_buffer_ref()
enums::AlarmControlPanelStateCommand command
enums::AlarmControlPanelState state
enums::BluetoothScannerMode mode
void set_data(const uint8_t *data, size_t len)
bool has_target_temperature_high
float target_temperature_low
bool has_target_temperature_low
float target_temperature_high
enums::ClimateSwingMode swing_mode
enums::ClimateFanMode fan_mode
bool has_target_temperature
std::string custom_fan_mode
enums::ClimatePreset preset
std::string custom_preset
enums::ClimateFanMode fan_mode
float target_temperature_low
enums::ClimateSwingMode swing_mode
void set_custom_fan_mode(const StringRef &ref)
void set_custom_preset(const StringRef &ref)
enums::ClimateAction action
enums::ClimatePreset preset
float current_temperature
float target_temperature_high
enums::CoverOperation current_operation
void set_event_type(const StringRef &ref)
uint16_t response_data_len
const uint8_t * response_data
void set_error_message(const StringRef &ref)
enums::FanDirection direction
enums::FanDirection direction
void set_preset_mode(const StringRef &ref)
const uint8_t * client_info
uint32_t api_version_major
uint32_t api_version_minor
uint32_t api_version_minor
void set_name(const StringRef &ref)
void set_server_info(const StringRef &ref)
uint32_t api_version_major
const uint8_t * response_data
std::string error_message
uint16_t response_data_len
bool has_color_temperature
enums::ColorMode color_mode
bool has_transition_length
uint32_t transition_length
bool has_color_brightness
void set_effect(const StringRef &ref)
enums::ColorMode color_mode
bool requires_code_to_arm
uint32_t supported_features
bool is_status_binary_sensor
void set_device_class(const StringRef &ref)
const std::vector< const char * > * supported_custom_presets
const climate::ClimateSwingModeMask * supported_swing_modes
float visual_max_humidity
const std::vector< const char * > * supported_custom_fan_modes
bool supports_current_temperature
bool supports_current_humidity
bool supports_target_humidity
float visual_min_humidity
float visual_max_temperature
float visual_target_temperature_step
bool supports_two_point_target_temperature
const climate::ClimatePresetMask * supported_presets
const climate::ClimateFanModeMask * supported_fan_modes
const climate::ClimateModeMask * supported_modes
float visual_min_temperature
float visual_current_temperature_step
void set_device_class(const StringRef &ref)
const FixedVector< const char * > * event_types
void set_device_class(const StringRef &ref)
const std::vector< const char * > * supported_preset_modes
int32_t supported_speed_count
bool supports_oscillation
const FixedVector< const char * > * effects
const light::ColorModeMask * supported_color_modes
void set_unit_of_measurement(const StringRef &ref)
void set_device_class(const StringRef &ref)
const FixedVector< const char * > * options
int32_t accuracy_decimals
void set_unit_of_measurement(const StringRef &ref)
void set_device_class(const StringRef &ref)
enums::SensorStateClass state_class
void set_device_class(const StringRef &ref)
void set_pattern(const StringRef &ref)
void set_device_class(const StringRef &ref)
void set_device_class(const StringRef &ref)
void set_device_class(const StringRef &ref)
enums::LockCommand command
virtual void encode(ProtoWriteBuffer buffer) const
virtual const char * message_name() const
virtual void calculate_size(ProtoSize &size) const
uint32_t get_size() const
void set_state(const StringRef &ref)
void set_entity_id(const StringRef &ref)
void set_attribute(const StringRef &ref)
void set_message(const uint8_t *data, size_t len)
void set_state(const StringRef &ref)
void set_state(const StringRef &ref)
enums::UpdateCommand command
void set_current_version(const StringRef &ref)
void set_latest_version(const StringRef &ref)
void set_release_summary(const StringRef &ref)
void set_title(const StringRef &ref)
void set_release_url(const StringRef &ref)
enums::ValveOperation current_operation
std::vector< VoiceAssistantExternalWakeWord > external_wake_words
std::vector< VoiceAssistantWakeWord > available_wake_words
uint32_t max_active_wake_words
const std::vector< std::string > * active_wake_words
std::vector< std::string > active_wake_words
enums::ZWaveProxyRequestType type
Base class for all binary_sensor-type classes.
void bluetooth_gatt_read(const api::BluetoothGATTReadRequest &msg)
void bluetooth_gatt_send_services(const api::BluetoothGATTGetServicesRequest &msg)
void bluetooth_device_request(const api::BluetoothDeviceRequest &msg)
void bluetooth_gatt_write_descriptor(const api::BluetoothGATTWriteDescriptorRequest &msg)
void bluetooth_scanner_set_mode(bool active)
void subscribe_api_connection(api::APIConnection *api_connection, uint32_t flags)
uint32_t get_feature_flags() const
void send_connections_free()
void unsubscribe_api_connection(api::APIConnection *api_connection)
void get_bluetooth_mac_address_pretty(std::span< char, 18 > output)
void bluetooth_gatt_read_descriptor(const api::BluetoothGATTReadDescriptorRequest &msg)
void bluetooth_gatt_write(const api::BluetoothGATTWriteRequest &msg)
void bluetooth_gatt_notify(const api::BluetoothGATTNotifyRequest &msg)
Abstract camera base class.
virtual CameraImageReader * create_image_reader()=0
Returns a new camera image reader that keeps track of the JPEG data in the camera image.
virtual void start_stream(CameraRequester requester)=0
virtual void stop_stream(CameraRequester requester)=0
virtual void request_image(CameraRequester requester)=0
static Camera * instance()
The singleton instance of the camera implementation.
ClimateDevice - This is the base class for all climate integrations.
Base class for all cover devices.
void set_epoch_time(uint32_t epoch)
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Base class for all locks.
Base-class for all numbers.
Base-class for all selects.
Base-class for all sensors.
Base class for all switches.
Base-class for all text inputs.
void set_timezone(const std::string &tz)
Set the time zone.
Base class for all valve devices.
const Configuration & get_configuration()
void on_timer_event(const api::VoiceAssistantTimerEventResponse &msg)
void on_audio(const api::VoiceAssistantAudio &msg)
void client_subscription(api::APIConnection *client, bool subscribe)
void on_event(const api::VoiceAssistantEventResponse &msg)
void on_announce(const api::VoiceAssistantAnnounceRequest &msg)
api::APIConnection * get_api_connection() const
uint32_t get_feature_flags() const
void on_set_configuration(const std::vector< std::string > &active_wake_words)
void zwave_proxy_request(api::APIConnection *api_connection, api::enums::ZWaveProxyRequestType type)
void send_frame(const uint8_t *data, size_t length)
uint32_t get_feature_flags() const
void api_connection_authenticated(api::APIConnection *conn)
const LogString * api_error_to_logstr(APIError err)
std::array< uint8_t, 32 > psk_t
BluetoothProxy * global_bluetooth_proxy
@ CLIMATE_SUPPORTS_CURRENT_HUMIDITY
@ CLIMATE_SUPPORTS_TARGET_HUMIDITY
@ CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
@ CLIMATE_SUPPORTS_ACTION
@ CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE
ClimatePreset
Enum for all preset modes NOTE: If adding values, update ClimatePresetMask in climate_traits....
ClimateSwingMode
Enum for all modes a climate swing can be in NOTE: If adding values, update ClimateSwingModeMask in c...
ClimateMode
Enum for all modes a climate device can be in.
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
bool global_has_deep_sleep
FanDirection
Simple enum to represent the direction of a fan.
HomeassistantTime * global_homeassistant_time
ColorMode
Color modes are a combination of color capabilities that can be used at the same time.
@ COLOR_TEMPERATURE
Color temperature can be controlled.
@ COLD_WARM_WHITE
Brightness of cold and warm white output can be controlled.
@ UPDATE_STATE_INSTALLING
VoiceAssistant * global_voice_assistant
ZWaveProxy * global_zwave_proxy
void format_mac_addr_upper(const uint8_t *mac, char *output)
Format MAC address as XX:XX:XX:XX:XX:XX (uppercase)
void get_mac_address_raw(uint8_t *mac)
Get the device MAC address as raw bytes, written into the provided byte array (6 bytes).
void IRAM_ATTR HOT delay(uint32_t ms)
Application App
Global storage of Application pointer - only one Application can exist.
size_t base64_decode(const std::string &encoded_string, uint8_t *buf, size_t buf_len)
A more user-friendly version of struct tm from time.h.
uint8_t batch_first_message
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM