mirror of
https://github.com/esphome/esphome.git
synced 2025-01-18 12:05:41 +00:00
web_server: Adds REST API POST endpoints to arm and disarm (#7985)
This commit is contained in:
parent
b4a2b50ee0
commit
f319472066
@ -1415,6 +1415,30 @@ void WebServer::handle_alarm_control_panel_request(AsyncWebServerRequest *reques
|
||||
request->send(200, "application/json", data.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto call = obj->make_call();
|
||||
if (request->hasParam("code")) {
|
||||
call.set_code(request->getParam("code")->value().c_str());
|
||||
}
|
||||
|
||||
if (match.method == "disarm") {
|
||||
call.disarm();
|
||||
} else if (match.method == "arm_away") {
|
||||
call.arm_away();
|
||||
} else if (match.method == "arm_home") {
|
||||
call.arm_home();
|
||||
} else if (match.method == "arm_night") {
|
||||
call.arm_night();
|
||||
} else if (match.method == "arm_vacation") {
|
||||
call.arm_vacation();
|
||||
} else {
|
||||
request->send(404);
|
||||
return;
|
||||
}
|
||||
|
||||
this->schedule_([call]() mutable { call.perform(); });
|
||||
request->send(200);
|
||||
return;
|
||||
}
|
||||
request->send(404);
|
||||
}
|
||||
@ -1664,7 +1688,7 @@ bool WebServer::canHandle(AsyncWebServerRequest *request) {
|
||||
#endif
|
||||
|
||||
#ifdef USE_ALARM_CONTROL_PANEL
|
||||
if (request->method() == HTTP_GET && match.domain == "alarm_control_panel")
|
||||
if ((request->method() == HTTP_GET || request->method() == HTTP_POST) && match.domain == "alarm_control_panel")
|
||||
return true;
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user