mirror of
https://github.com/esphome/esphome.git
synced 2026-09-24 21:44:04 +00:00
[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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user