mirror of
https://github.com/esphome/esphome.git
synced 2025-09-10 15:22:24 +01:00
Refactor fan platform to resemble climate/cover platforms (#2848)
Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> Co-authored-by: rob-deutsch <robzyb+altgithub@gmail.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -440,8 +440,8 @@ void WebServer::handle_binary_sensor_request(AsyncWebServerRequest *request, con
|
||||
#endif
|
||||
|
||||
#ifdef USE_FAN
|
||||
void WebServer::on_fan_update(fan::FanState *obj) { this->events_.send(this->fan_json(obj).c_str(), "state"); }
|
||||
std::string WebServer::fan_json(fan::FanState *obj) {
|
||||
void WebServer::on_fan_update(fan::Fan *obj) { this->events_.send(this->fan_json(obj).c_str(), "state"); }
|
||||
std::string WebServer::fan_json(fan::Fan *obj) {
|
||||
return json::build_json([obj](JsonObject root) {
|
||||
root["id"] = "fan-" + obj->get_object_id();
|
||||
root["state"] = obj->state ? "ON" : "OFF";
|
||||
@@ -470,7 +470,7 @@ std::string WebServer::fan_json(fan::FanState *obj) {
|
||||
});
|
||||
}
|
||||
void WebServer::handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match) {
|
||||
for (fan::FanState *obj : App.get_fans()) {
|
||||
for (fan::Fan *obj : App.get_fans()) {
|
||||
if (obj->get_object_id() != match.id)
|
||||
continue;
|
||||
|
||||
@@ -516,7 +516,7 @@ void WebServer::handle_fan_request(AsyncWebServerRequest *request, const UrlMatc
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->defer([call]() { call.perform(); });
|
||||
this->defer([call]() mutable { call.perform(); });
|
||||
request->send(200);
|
||||
} else if (match.method == "turn_off") {
|
||||
this->defer([obj]() { obj->turn_off().perform(); });
|
||||
|
Reference in New Issue
Block a user