Add friendly_name to device (#4296)

This commit is contained in:
Jesse Hills
2023-01-17 10:28:09 +13:00
committed by GitHub
parent 3d2d681a7b
commit c301ae3645
18 changed files with 137 additions and 18 deletions
+2
View File
@@ -206,6 +206,8 @@ message DeviceInfoResponse {
uint32 bluetooth_proxy_version = 11;
string manufacturer = 12;
string friendly_name = 13;
}
message ListEntitiesRequest {
@@ -930,6 +930,7 @@ DeviceInfoResponse APIConnection::device_info(const DeviceInfoRequest &msg) {
DeviceInfoResponse resp{};
resp.uses_password = this->parent_->uses_password();
resp.name = App.get_name();
resp.friendly_name = App.get_friendly_name();
resp.mac_address = get_mac_address_pretty();
resp.esphome_version = ESPHOME_VERSION;
resp.compilation_time = App.get_compilation_time();
+9
View File
@@ -628,6 +628,10 @@ bool DeviceInfoResponse::decode_length(uint32_t field_id, ProtoLengthDelimited v
this->manufacturer = value.as_string();
return true;
}
case 13: {
this->friendly_name = value.as_string();
return true;
}
default:
return false;
}
@@ -645,6 +649,7 @@ void DeviceInfoResponse::encode(ProtoWriteBuffer buffer) const {
buffer.encode_uint32(10, this->webserver_port);
buffer.encode_uint32(11, this->bluetooth_proxy_version);
buffer.encode_string(12, this->manufacturer);
buffer.encode_string(13, this->friendly_name);
}
#ifdef HAS_PROTO_MESSAGE_DUMP
void DeviceInfoResponse::dump_to(std::string &out) const {
@@ -699,6 +704,10 @@ void DeviceInfoResponse::dump_to(std::string &out) const {
out.append(" manufacturer: ");
out.append("'").append(this->manufacturer).append("'");
out.append("\n");
out.append(" friendly_name: ");
out.append("'").append(this->friendly_name).append("'");
out.append("\n");
out.append("}");
}
#endif
+1
View File
@@ -276,6 +276,7 @@ class DeviceInfoResponse : public ProtoMessage {
uint32_t webserver_port{0};
uint32_t bluetooth_proxy_version{0};
std::string manufacturer{};
std::string friendly_name{};
void encode(ProtoWriteBuffer buffer) const override;
#ifdef HAS_PROTO_MESSAGE_DUMP
void dump_to(std::string &out) const override;
@@ -1,14 +1,15 @@
from pathlib import Path
from typing import Optional
import requests
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import git
from esphome.components.packages import validate_source_shorthand
from esphome.const import CONF_WIFI, CONF_REF
from esphome.const import CONF_REF, CONF_WIFI
from esphome.wizard import wizard_file
from esphome.yaml_util import dump
from esphome import git
dashboard_import_ns = cg.esphome_ns.namespace("dashboard_import")
@@ -66,7 +67,12 @@ async def to_code(config):
def import_config(
path: str, name: str, project_name: str, import_url: str, network: str = CONF_WIFI
path: str,
name: str,
friendly_name: Optional[str],
project_name: str,
import_url: str,
network: str = CONF_WIFI,
) -> None:
p = Path(path)
@@ -77,6 +83,7 @@ def import_config(
p.write_text(
wizard_file(
name=name,
friendly_name=friendly_name,
platform="ESP32" if "esp32" in import_url else "ESP8266",
board="esp32dev" if "esp32" in import_url else "esp01_1m",
ssid="!secret wifi_ssid",
@@ -98,13 +105,15 @@ def import_config(
p.write_text(req.text, encoding="utf8")
else:
substitutions = {"name": name}
esphome_core = {"name": "${name}", "name_add_mac_suffix": False}
if friendly_name:
substitutions["friendly_name"] = friendly_name
esphome_core["friendly_name"] = "${friendly_name}"
config = {
"substitutions": {"name": name},
"substitutions": substitutions,
"packages": {project_name: import_url},
"esphome": {
"name": "${name}",
"name_add_mac_suffix": False,
},
"esphome": esphome_core,
}
output = dump(config)
@@ -30,6 +30,9 @@ void MDNSComponent::compile_records_() {
service.service_type = "_esphomelib";
service.proto = "_tcp";
service.port = api::global_api_server->get_port();
if (App.get_friendly_name().empty()) {
service.txt_records.push_back({"friendly_name", App.get_friendly_name()});
}
service.txt_records.push_back({"version", ESPHOME_VERSION});
service.txt_records.push_back({"mac", get_mac_address()});
const char *platform = nullptr;
+1 -1
View File
@@ -104,7 +104,7 @@ void WebServer::setup() {
// Configure reconnect timeout and send config
client->send(json::build_json([this](JsonObject root) {
root["title"] = App.get_name();
root["title"] = App.get_friendly_name().empty() ? App.get_name() : App.get_friendly_name();
root["ota"] = this->allow_ota_;
root["lang"] = "en";
}).c_str(),