Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for ble transport #120

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add PWA proof of concept
tomaszduda23 committed Jul 13, 2024
commit 0adb88e8c45c43ffac2171a7c30e5b18bf0a94f8
3 changes: 2 additions & 1 deletion packages/v2/package.json
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
"vite": "^2.3.6",
"vite-plugin-html": "^2.1.1",
"vite-plugin-package-version": "^1.0.2",
"vite-plugin-singlefile": "^0.5.1"
"vite-plugin-singlefile": "^0.5.1",
"vite-plugin-pwa": "^0.12.8"
}
}
15 changes: 14 additions & 1 deletion packages/v2/src/esp-app.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ interface Config {
export default class EspApp extends LitElement {
@state() scheme: string = "";
@state() ping: string = "";
@state() redirectUrl: string = "";
@query("#beat")
beat!: HTMLSpanElement;

@@ -119,9 +120,21 @@ export default class EspApp extends LitElement {
: nothing;
}

handleRedirect() {
window.location.href = "?target=" + this.redirectUrl;
}

render() {
return html`
<h1>
<div class="redirect-container">
<input
type="text"
placeholder="esphome address"
@input="${(e: Event) => (this.redirectUrl = (e.target as HTMLInputElement).value)}"
/>
<button class="btn" @click="${this.handleRedirect}">Go</button>
</div>
<h1>
<a href="https://esphome.io/web-api" class="logo">
<esp-logo style="width: 52px; height: 40px; display: block;"></esp-logo>
</a>
10 changes: 8 additions & 2 deletions packages/v2/src/esp-entity-table.ts
Original file line number Diff line number Diff line change
@@ -39,8 +39,14 @@ interface entityConfig {
}

export function getBasePath() {
let str = window.location.pathname;
return str.endsWith("/") ? str.slice(0, -1) : str;
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const target = urlParams.get('target')
if (target !== null) {
return "http://" + target
}
const pathname = window.location.pathname;
return pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;;
}

let basePath = getBasePath();
30 changes: 11 additions & 19 deletions packages/v2/vite.config.ts
Original file line number Diff line number Diff line change
@@ -8,8 +8,7 @@ import { viteSingleFile } from "vite-plugin-singlefile";
import { minifyHtml as ViteMinifyHtml } from "vite-plugin-html";
import stripBanner from "rollup-plugin-strip-banner";
import replace from "@rollup/plugin-replace";

const proxy_target = process.env.PROXY_TARGET || "http://nodemcu.local";
import { VitePWA } from 'vite-plugin-pwa'

export default defineConfig({
clearScreen: false,
@@ -53,6 +52,15 @@ export default defineConfig({
enforce: "post",
apply: "build",
},
VitePWA({
registerType: 'autoUpdate',
manifest: {
icons: [{
"src": "logo.svg",
"sizes": "any"
}],
}
}),
],
build: {
brotliSize: false,
@@ -71,24 +79,8 @@ export default defineConfig({
},
},
server: {
open: "/", // auto open browser in dev mode
host: true, // dev on local and network
host: true,
port: 5001,
strictPort: true,
proxy: {
"/light": proxy_target,
"/select": proxy_target,
"/cover": proxy_target,
"/switch": proxy_target,
"/button": proxy_target,
"/fan": proxy_target,
"/lock": proxy_target,
"/number": proxy_target,
"/climate": proxy_target,
"/events": proxy_target,
"/text": proxy_target,
"/date": proxy_target,
"/time": proxy_target,
},
},
});