diff --git a/esphome/components/api/api_server.cpp b/esphome/components/api/api_server.cpp index 77bd5f5c3ca..1120d4c5292 100644 --- a/esphome/components/api/api_server.cpp +++ b/esphome/components/api/api_server.cpp @@ -597,8 +597,10 @@ void APIServer::request_time() { #endif bool APIServer::is_connected_with_state_subscription() const { - for (const auto &client : this->active_clients()) { - if (client->flags_.state_subscription) { + // Indexed iteration (not active_clients()) because this method is const; keeps the view + // struct single-flavor in the header. + for (uint8_t i = 0; i < this->api_connection_count_; i++) { + if (this->clients_[i]->flags_.state_subscription) { return true; } } diff --git a/esphome/components/api/api_server.h b/esphome/components/api/api_server.h index 4810cd53885..b411ed770d2 100644 --- a/esphome/components/api/api_server.h +++ b/esphome/components/api/api_server.h @@ -205,21 +205,9 @@ class APIServer final : public Component, APIConnectionPtr *begin() { return this->begin_; } APIConnectionPtr *end() { return this->end_; } }; - class ConstActiveClientsView { - const APIConnectionPtr *begin_; - const APIConnectionPtr *end_; - - public: - ConstActiveClientsView(const APIConnectionPtr *b, const APIConnectionPtr *e) : begin_(b), end_(e) {} - const APIConnectionPtr *begin() const { return this->begin_; } - const APIConnectionPtr *end() const { return this->end_; } - }; ActiveClientsView active_clients() { return {this->clients_.data(), this->clients_.data() + this->api_connection_count_}; } - ConstActiveClientsView active_clients() const { - return {this->clients_.data(), this->clients_.data() + this->api_connection_count_}; - } #ifdef USE_API_HOMEASSISTANT_STATES struct HomeAssistantStateSubscription {