From 44679f23385813ac219be6a6a3635d1a3a446459 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 28 Feb 2024 09:43:07 +0100 Subject: [PATCH] Include (base) dashboard in the builtin-webserver (#593) Co-authored-by: Martin Hjelmare --- .github/workflows/release.yml | 31 +++++++++++++++++-------- dashboard/src/entrypoint/main.ts | 17 ++++++++------ dashboard/src/pages/matter-dashboard.ts | 13 +++++++---- matter_server/server/server.py | 31 ++++++++++++++++++++++++- pyproject.toml | 2 +- tests/server/test_server.py | 4 ++-- 6 files changed, 73 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 66196f1f..243ba137 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,6 +3,9 @@ name: Publish releases on: release: types: [published] +env: + PYTHON_VERSION: "3.10" + NODE_VERSION: "18.x" jobs: build-and-publish-pypi: @@ -28,10 +31,14 @@ jobs: exit 1 fi fi - - name: Set up Python 3.10 + - name: Set up Python ${{ env.PYTHON_VERSION }} uses: actions/setup-python@v5.0.0 with: - python-version: "3.10" + python-version: ${{ env.PYTHON_VERSION }} + - name: Set up Node ${{ env.NODE_VERSION }} + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} - name: Install build run: >- pip install build tomli tomli-w @@ -48,7 +55,13 @@ jobs: with open("pyproject.toml", "wb") as f: tomli_w.dump(pyproject, f) - - name: Build + - name: Build dashboard + run: | + cd dashboard + script/setup + script/build + cd .. + - name: Build python package run: >- python3 -m build - name: Publish release to PyPI @@ -69,9 +82,9 @@ jobs: - name: Log in to the GitHub container registry uses: docker/login-action@v3.0.0 with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3.1.0 - name: Version number for tags @@ -95,8 +108,7 @@ jobs: ghcr.io/${{ github.repository_owner }}/python-matter-server:${{ steps.tags.outputs.major }}, ghcr.io/${{ github.repository_owner }}/python-matter-server:stable push: true - build-args: - "PYTHON_MATTER_SERVER=${{ needs.build-and-publish-pypi.outputs.version }}" + build-args: "PYTHON_MATTER_SERVER=${{ needs.build-and-publish-pypi.outputs.version }}" - name: Build and Push pre-release uses: docker/build-push-action@v5.1.0 if: github.event.release.prerelease == true @@ -108,5 +120,4 @@ jobs: ghcr.io/${{ github.repository_owner }}/python-matter-server:${{ steps.tags.outputs.patch }}, ghcr.io/${{ github.repository_owner }}/python-matter-server:beta push: true - build-args: - "PYTHON_MATTER_SERVER=${{ needs.build-and-publish-pypi.outputs.version }}" + build-args: "PYTHON_MATTER_SERVER=${{ needs.build-and-publish-pypi.outputs.version }}" diff --git a/dashboard/src/entrypoint/main.ts b/dashboard/src/entrypoint/main.ts index ce7c9f76..e9f6dbae 100644 --- a/dashboard/src/entrypoint/main.ts +++ b/dashboard/src/entrypoint/main.ts @@ -3,16 +3,19 @@ import { MatterClient } from "../client/client"; async function main() { import("../pages/matter-dashboard-app"); - // Turn httpX url into wsX url and append "/ws" - let url = "ws" + new URL("./ws", location.href).toString().substring(4); - - // Inside Home Assistant ingress, we will not prompt for the URL - if (!location.pathname.endsWith("/ingress")) { + let url = ""; + // Detect if we're running in the (production) webserver included in the matter server or not. + if (location.href.includes(":5580")) { + // production server running inside the matter server + // Turn httpX url into wsX url and append "/ws" + url = "ws" + new URL("./ws", location.href).toString().substring(4); + } else { + // development server, ask for url to matter server let storageUrl = localStorage.getItem("matterURL"); if (!storageUrl) { storageUrl = prompt( - "Enter Matter URL", - "ws://homeassistant.local:5580/ws" + "Enter Websocket URL to a running Matter Server", + "ws://localhost:5580/ws" ); if (!storageUrl) { alert("Unable to connect without URL"); diff --git a/dashboard/src/pages/matter-dashboard.ts b/dashboard/src/pages/matter-dashboard.ts index 1c7c9391..41f99515 100644 --- a/dashboard/src/pages/matter-dashboard.ts +++ b/dashboard/src/pages/matter-dashboard.ts @@ -28,14 +28,19 @@ class MatterDashboard extends LitElement { render() { const nodes = this.nodeEntries(this.nodes); + const isProductionServer = location.href.includes(":5580") return html`
Python Matter Server
+ ${isProductionServer + ? "" + : html` + `}
@@ -50,20 +55,20 @@ class MatterDashboard extends LitElement { ${nodes.map(([id, node]) => { - return html` + return html` ${node.node_id}
${node.vendorName} ${node.productName} ${node.available - ? "" - : html`OFFLINE`} + ? "" + : html`OFFLINE`}
${node.serialNumber}
`; - })} + })}