Expose webserver_port to the native API (#2640)

This commit is contained in:
Jesse Hills 2021-11-01 09:33:04 +13:00 committed by GitHub
parent 2b04152482
commit d8b3af3815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 0 deletions

View File

@ -182,6 +182,8 @@ message DeviceInfoResponse {
// The esphome project details if set
string project_name = 8;
string project_version = 9;
uint32 webserver_port = 10;
}
message ListEntitiesRequest {

View File

@ -759,6 +759,9 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
#ifdef ESPHOME_PROJECT_NAME
resp.project_name = ESPHOME_PROJECT_NAME;
resp.project_version = ESPHOME_PROJECT_VERSION;
#endif
#ifdef USE_WEBSERVER
resp.webserver_port = WEBSERVER_PORT;
#endif
return resp;
}

View File

@ -396,6 +396,10 @@ bool DeviceInfoResponse::decode_varint(uint32_t field_id, ProtoVarInt value) {
this->has_deep_sleep = value.as_bool();
return true;
}
case 10: {
this->webserver_port = value.as_uint32();
return true;
}
default:
return false;
}
@ -444,6 +448,7 @@ void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_bool(7, this->has_deep_sleep);
buffer.encode_string(8, this->project_name);
buffer.encode_string(9, this->project_version);
buffer.encode_uint32(10, this->webserver_port);
}
#ifdef HAS_PROTO_MESSAGE_DUMP
void DeviceInfoResponse::dump_to(std::string &out) const {
@ -484,6 +489,11 @@ void DeviceInfoResponse::dump_to(std::string &out) const {
out.append(" project_version: ");
out.append("'").append(this->project_version).append("'");
out.append("\n");
out.append(" webserver_port: ");
sprintf(buffer, "%u", this->webserver_port);
out.append(buffer);
out.append("\n");
out.append("}");
}
#endif

View File

@ -224,6 +224,7 @@ class DeviceInfoResponse : public ProtoMessage {
bool has_deep_sleep{false};
std::string project_name{};
std::string project_version{};
uint32_t webserver_port{0};
void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override;

View File

@ -54,6 +54,7 @@ async def to_code(config):
cg.add(paren.set_port(config[CONF_PORT]))
cg.add_define("WEBSERVER_PORT", config[CONF_PORT])
cg.add_define("USE_WEBSERVER")
cg.add(var.set_css_url(config[CONF_CSS_URL]))
cg.add(var.set_js_url(config[CONF_JS_URL]))
if CONF_AUTH in config:

View File

@ -36,8 +36,11 @@
#define USE_SWITCH
#define USE_TEXT_SENSOR
#define USE_TIME
#define USE_WEBSERVER
#define USE_WIFI
#define WEBSERVER_PORT 80 // NOLINT
// Arduino-specific feature flags
#ifdef USE_ARDUINO
#define USE_CAPTIVE_PORTAL