Ver Fonte

Add support for Home Assistant domain in manifest (#101)

Paulus Schoutsen há 3 anos atrás
pai
commit
65b0fab0c5
5 ficheiros alterados com 68 adições e 29 exclusões
  1. 1 0
      README.md
  2. 6 0
      index.html
  3. 1 0
      src/const.ts
  4. 59 29
      src/install-dialog.ts
  5. 1 0
      static/firmware_build/manifest.json

+ 1 - 0
README.md

@@ -14,6 +14,7 @@ Manifest definition:
 {
 {
   "name": "ESPHome",
   "name": "ESPHome",
   "version": "2021.10.3",
   "version": "2021.10.3",
+  "home_assistant_domain": "esphome",
   "builds": [
   "builds": [
     {
     {
       "chipFamily": "ESP32",
       "chipFamily": "ESP32",

+ 6 - 0
index.html

@@ -266,6 +266,7 @@
 {
 {
   "name": "ESPHome",
   "name": "ESPHome",
   "version": "2021.11.0",
   "version": "2021.11.0",
+  "home_assistant_domain": "esphome",
   "builds": [
   "builds": [
     {
     {
       "chipFamily": "ESP32",
       "chipFamily": "ESP32",
@@ -291,6 +292,11 @@
         where it should be installed. Part paths are resolved relative to the
         where it should be installed. Part paths are resolved relative to the
         path of the manifest, but can also be URLs to other hosts.
         path of the manifest, but can also be URLs to other hosts.
       </p>
       </p>
+      <p>
+        If your firmware is supported by Home Assistant, you can add the
+        optional key <code>home_assistant_domain</code>. If present, ESP Web
+        Tools will link the user to add this device to Home Assistant.
+      </p>
       <h3 id="improv">Wi-Fi provisioning</h3>
       <h3 id="improv">Wi-Fi provisioning</h3>
       <p>
       <p>
         ESP Web Tools has support for the
         ESP Web Tools has support for the

+ 1 - 0
src/const.ts

@@ -15,6 +15,7 @@ export interface Build {
 export interface Manifest {
 export interface Manifest {
   name: string;
   name: string;
   version: string;
   version: string;
+  home_assistant_domain?: string;
   builds: Build[];
   builds: Build[];
 }
 }
 
 

+ 59 - 29
src/install-dialog.ts

@@ -61,11 +61,6 @@ class EwtInstallDialog extends LitElement {
 
 
   @state() private _busy = false;
   @state() private _busy = false;
 
 
-  private _progressFeedback?: {
-    resolve: (_: unknown) => void;
-    reject: () => void;
-  };
-
   protected render() {
   protected render() {
     if (!this.port) {
     if (!this.port) {
       return html``;
       return html``;
@@ -180,7 +175,21 @@ class EwtInstallDialog extends LitElement {
                   class="has-button"
                   class="has-button"
                   target="_blank"
                   target="_blank"
                 >
                 >
-                  <ewt-button label="Set up Device"></ewt-button>
+                  <ewt-button label="Visit Device"></ewt-button>
+                </a>
+              </div>
+            `}
+        ${!this._manifest.home_assistant_domain ||
+        this._client!.state !== ImprovSerialCurrentState.PROVISIONED
+          ? ""
+          : html`
+              <div>
+                <a
+                  href=${`https://my.home-assistant.io/redirect/config_flow_start/?domain=${this._manifest.home_assistant_domain}`}
+                  class="has-button"
+                  target="_blank"
+                >
+                  <ewt-button label="Add to Home Assistant"></ewt-button>
                 </a>
                 </a>
               </div>
               </div>
             `}
             `}
@@ -245,29 +254,53 @@ class EwtInstallDialog extends LitElement {
       this._client!.state === ImprovSerialCurrentState.PROVISIONED
       this._client!.state === ImprovSerialCurrentState.PROVISIONED
     ) {
     ) {
       heading = undefined;
       heading = undefined;
+      const showSetupLinks =
+        !this._wasProvisioned &&
+        (this._client!.nextUrl !== undefined ||
+          "home_assistant_domain" in this._manifest);
+      hideActions = showSetupLinks;
       content = html`
       content = html`
         ${messageTemplate(OK_ICON, "Device connected to the network!")}
         ${messageTemplate(OK_ICON, "Device connected to the network!")}
-        ${!this._wasProvisioned && this._client!.nextUrl !== undefined
+        ${showSetupLinks
           ? html`
           ? html`
-              <a
-                slot="primaryAction"
-                href=${this._client!.nextUrl}
-                class="has-button"
-                target="_blank"
-                @click=${() => {
-                  this._state = "DASHBOARD";
-                }}
-              >
-                <ewt-button label="Set up Device"></ewt-button>
-              </a>
-              <ewt-button
-                slot="secondaryAction"
-                label="Skip"
-                @click=${() => {
-                  this._state = "DASHBOARD";
-                  this._installState = undefined;
-                }}
-              ></ewt-button>
+              <div class="dashboard-buttons">
+                <div>
+                  <a
+                    href=${this._client!.nextUrl}
+                    class="has-button"
+                    target="_blank"
+                    @click=${() => {
+                      this._state = "DASHBOARD";
+                    }}
+                  >
+                    <ewt-button label="Visit Device"></ewt-button>
+                  </a>
+                </div>
+                ${!this._manifest.home_assistant_domain
+                  ? ""
+                  : html`
+                      <div>
+                        <a
+                          href=${`https://my.home-assistant.io/redirect/config_flow_start/?domain=${this._manifest.home_assistant_domain}`}
+                          class="has-button"
+                          target="_blank"
+                        >
+                          <ewt-button
+                            label="Add to Home Assistant"
+                          ></ewt-button>
+                        </a>
+                      </div>
+                    `}
+                <div>
+                  <ewt-button
+                    label="Skip"
+                    @click=${() => {
+                      this._state = "DASHBOARD";
+                      this._installState = undefined;
+                    }}
+                  ></ewt-button>
+                </div>
+              </div>
             `
             `
           : html`
           : html`
               <ewt-button
               <ewt-button
@@ -617,9 +650,6 @@ class EwtInstallDialog extends LitElement {
   };
   };
 
 
   private async _handleClose() {
   private async _handleClose() {
-    if (this._progressFeedback) {
-      this._progressFeedback.reject();
-    }
     if (this._client) {
     if (this._client) {
       await this._closeClientWithoutEvents(this._client);
       await this._closeClientWithoutEvents(this._client);
     }
     }

+ 1 - 0
static/firmware_build/manifest.json

@@ -1,6 +1,7 @@
 {
 {
   "name": "ESPHome",
   "name": "ESPHome",
   "version": "2021.11.0-dev",
   "version": "2021.11.0-dev",
+  "home_assistant_domain": "esphome",
   "builds": [
   "builds": [
     {
     {
       "chipFamily": "ESP32",
       "chipFamily": "ESP32",