mirror of
https://github.com/esphome/esphome.git
synced 2024-11-22 23:18:10 +01:00
commit
ead597d0fb
10 changed files with 67 additions and 21 deletions
|
@ -74,8 +74,10 @@ class BinarySensor : public EntityBase {
|
||||||
|
|
||||||
// ========== OVERRIDE METHODS ==========
|
// ========== OVERRIDE METHODS ==========
|
||||||
// (You'll only need this when creating your own custom binary sensor)
|
// (You'll only need this when creating your own custom binary sensor)
|
||||||
/// Get the default device class for this sensor, or empty string for no default.
|
/** Override this to set the default device class.
|
||||||
ESPDEPRECATED("device_class() is deprecated, set property during config validation instead.", "2022.01")
|
*
|
||||||
|
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||||
|
*/
|
||||||
virtual std::string device_class();
|
virtual std::string device_class();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -169,7 +169,11 @@ class Cover : public EntityBase {
|
||||||
friend CoverCall;
|
friend CoverCall;
|
||||||
|
|
||||||
virtual void control(const CoverCall &call) = 0;
|
virtual void control(const CoverCall &call) = 0;
|
||||||
ESPDEPRECATED("device_class() is deprecated, set property during config validation instead.", "2022.01")
|
|
||||||
|
/** Override this to set the default device class.
|
||||||
|
*
|
||||||
|
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||||
|
*/
|
||||||
virtual std::string device_class();
|
virtual std::string device_class();
|
||||||
|
|
||||||
optional<CoverRestoreState> restore_state_();
|
optional<CoverRestoreState> restore_state_();
|
||||||
|
|
|
@ -417,7 +417,7 @@ def copy_files():
|
||||||
)
|
)
|
||||||
|
|
||||||
dir = os.path.dirname(__file__)
|
dir = os.path.dirname(__file__)
|
||||||
post_build_file = os.path.join(dir, "post_build.py")
|
post_build_file = os.path.join(dir, "post_build.py.script")
|
||||||
copy_file_if_changed(
|
copy_file_if_changed(
|
||||||
post_build_file,
|
post_build_file,
|
||||||
CORE.relative_build_path("post_build.py"),
|
CORE.relative_build_path("post_build.py"),
|
||||||
|
|
|
@ -220,7 +220,7 @@ async def to_code(config):
|
||||||
def copy_files():
|
def copy_files():
|
||||||
|
|
||||||
dir = os.path.dirname(__file__)
|
dir = os.path.dirname(__file__)
|
||||||
post_build_file = os.path.join(dir, "post_build.py")
|
post_build_file = os.path.join(dir, "post_build.py.script")
|
||||||
copy_file_if_changed(
|
copy_file_if_changed(
|
||||||
post_build_file,
|
post_build_file,
|
||||||
CORE.relative_build_path("post_build.py"),
|
CORE.relative_build_path("post_build.py"),
|
||||||
|
|
|
@ -150,20 +150,28 @@ class Sensor : public EntityBase {
|
||||||
void internal_send_state_to_frontend(float state);
|
void internal_send_state_to_frontend(float state);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Override this to set the default unit of measurement.
|
/** Override this to set the default unit of measurement.
|
||||||
ESPDEPRECATED("unit_of_measurement() is deprecated, set property during config validation instead.", "2022.01")
|
*
|
||||||
|
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||||
|
*/
|
||||||
virtual std::string unit_of_measurement(); // NOLINT
|
virtual std::string unit_of_measurement(); // NOLINT
|
||||||
|
|
||||||
/// Override this to set the default accuracy in decimals.
|
/** Override this to set the default accuracy in decimals.
|
||||||
ESPDEPRECATED("accuracy_decimals() is deprecated, set property during config validation instead.", "2022.01")
|
*
|
||||||
|
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||||
|
*/
|
||||||
virtual int8_t accuracy_decimals(); // NOLINT
|
virtual int8_t accuracy_decimals(); // NOLINT
|
||||||
|
|
||||||
/// Override this to set the default device class.
|
/** Override this to set the default device class.
|
||||||
ESPDEPRECATED("device_class() is deprecated, set property during config validation instead.", "2022.01")
|
*
|
||||||
|
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||||
|
*/
|
||||||
virtual std::string device_class(); // NOLINT
|
virtual std::string device_class(); // NOLINT
|
||||||
|
|
||||||
/// Override this to set the default state class.
|
/** Override this to set the default state class.
|
||||||
ESPDEPRECATED("state_class() is deprecated, set property during config validation instead.", "2022.01")
|
*
|
||||||
|
* @deprecated This method is deprecated, set the property during config validation instead. (2022.1)
|
||||||
|
*/
|
||||||
virtual StateClass state_class(); // NOLINT
|
virtual StateClass state_class(); // NOLINT
|
||||||
|
|
||||||
uint32_t hash_base() override;
|
uint32_t hash_base() override;
|
||||||
|
|
|
@ -236,7 +236,18 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) {
|
||||||
#ifdef USE_NUMBER
|
#ifdef USE_NUMBER
|
||||||
for (auto *obj : App.get_numbers())
|
for (auto *obj : App.get_numbers())
|
||||||
if (this->include_internal_ || !obj->is_internal())
|
if (this->include_internal_ || !obj->is_internal())
|
||||||
write_row(stream, obj, "number", "");
|
write_row(stream, obj, "number", "", [](AsyncResponseStream &stream, EntityBase *obj) {
|
||||||
|
number::Number *number = (number::Number *) obj;
|
||||||
|
stream.print(R"(<input type="number" min=")");
|
||||||
|
stream.print(number->traits.get_min_value());
|
||||||
|
stream.print(R"(" max=")");
|
||||||
|
stream.print(number->traits.get_max_value());
|
||||||
|
stream.print(R"(" step=")");
|
||||||
|
stream.print(number->traits.get_step());
|
||||||
|
stream.print(R"(" value=")");
|
||||||
|
stream.print(number->state);
|
||||||
|
stream.print(R"("/>)");
|
||||||
|
});
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SELECT
|
#ifdef USE_SELECT
|
||||||
|
@ -652,18 +663,38 @@ void WebServer::handle_number_request(AsyncWebServerRequest *request, const UrlM
|
||||||
for (auto *obj : App.get_numbers()) {
|
for (auto *obj : App.get_numbers()) {
|
||||||
if (obj->get_object_id() != match.id)
|
if (obj->get_object_id() != match.id)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (request->method() == HTTP_GET) {
|
||||||
std::string data = this->number_json(obj, obj->state);
|
std::string data = this->number_json(obj, obj->state);
|
||||||
request->send(200, "text/json", data.c_str());
|
request->send(200, "text/json", data.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (match.method != "set") {
|
||||||
|
request->send(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto call = obj->make_call();
|
||||||
|
|
||||||
|
if (request->hasParam("value")) {
|
||||||
|
String value = request->getParam("value")->value();
|
||||||
|
optional<float> value_f = parse_number<float>(value.c_str());
|
||||||
|
if (value_f.has_value())
|
||||||
|
call.set_value(*value_f);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->defer([call]() mutable { call.perform(); });
|
||||||
|
request->send(200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
request->send(404);
|
request->send(404);
|
||||||
}
|
}
|
||||||
std::string WebServer::number_json(number::Number *obj, float value) {
|
std::string WebServer::number_json(number::Number *obj, float value) {
|
||||||
return json::build_json([obj, value](JsonObject root) {
|
return json::build_json([obj, value](JsonObject root) {
|
||||||
root["id"] = "number-" + obj->get_object_id();
|
root["id"] = "number-" + obj->get_object_id();
|
||||||
char buffer[64];
|
std::string state = str_sprintf("%f", value);
|
||||||
snprintf(buffer, sizeof(buffer), "%f", value);
|
root["state"] = state;
|
||||||
root["state"] = buffer;
|
|
||||||
root["value"] = value;
|
root["value"] = value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -769,7 +800,7 @@ bool WebServer::canHandle(AsyncWebServerRequest *request) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_NUMBER
|
#ifdef USE_NUMBER
|
||||||
if (request->method() == HTTP_GET && match.domain == "number")
|
if ((request->method() == HTTP_POST || request->method() == HTTP_GET) && match.domain == "number")
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Constants used by esphome."""
|
"""Constants used by esphome."""
|
||||||
|
|
||||||
__version__ = "2022.1.0b2"
|
__version__ = "2022.1.0b3"
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||||
|
|
||||||
|
|
|
@ -445,6 +445,7 @@ class DownloadBinaryRequestHandler(BaseHandler):
|
||||||
|
|
||||||
self.set_header("Content-Type", "application/octet-stream")
|
self.set_header("Content-Type", "application/octet-stream")
|
||||||
self.set_header("Content-Disposition", f'attachment; filename="{filename}"')
|
self.set_header("Content-Disposition", f'attachment; filename="{filename}"')
|
||||||
|
self.set_header("Cache-Control", "no-cache")
|
||||||
if not Path(path).is_file():
|
if not Path(path).is_file():
|
||||||
self.send_error(404)
|
self.send_error(404)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue