[api] Drop ConstActiveClientsView — single caller reads cleaner as indexed loop

is_connected_with_state_subscription() was the only const caller of
active_clients(). Iterating by index directly in that method lets us
drop the entire ConstActiveClientsView class from the header, leaving
a single ActiveClientsView for the mutable range-for sites.
This commit is contained in:
J. Nick Koston
2026-04-21 11:58:58 +02:00
parent 250d28f69c
commit 82e9613631
2 changed files with 4 additions and 14 deletions
+4 -2
View File
@@ -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;
}
}
-12
View File
@@ -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 {