Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bcbcaa801 | ||
|
|
b479476833 | ||
|
|
baa31ab649 | ||
|
|
dc7c6273e4 | ||
|
|
2942b6173b | ||
|
|
bcfc648011 | ||
|
|
084d86ad7a | ||
|
|
ea6be4a8f3 | ||
|
|
14649ac1fd | ||
|
|
f1b99cad1c | ||
|
|
ab7f50d4aa | ||
|
|
d22bba8c4d | ||
|
|
549f52655b | ||
|
|
2c5d64ab86 | ||
|
|
7c50c345ec | ||
|
|
f4261f9701 | ||
|
|
34826acb97 | ||
|
|
cd1b4e8e2b | ||
|
|
2b4c64c94b | ||
|
|
067f5fa642 | ||
|
|
957b6a66fe | ||
|
|
e4af85cdfa | ||
|
|
f99cb84658 | ||
|
|
644edb2ef6 | ||
|
|
b4a9763ead | ||
|
|
4551daedd3 | ||
|
|
fa4048e28c | ||
|
|
ea86f7f763 | ||
|
|
9a26fc46d5 | ||
|
|
35244bb107 | ||
|
|
883955e523 | ||
|
|
57c86093a4 | ||
|
|
2a827c24f6 | ||
|
|
473684efa6 | ||
|
|
3f0430ab37 | ||
|
|
96617e7b0c | ||
|
|
a9c3e9c890 | ||
|
|
02ec81c16a | ||
|
|
05d09830bb | ||
|
|
f16d25d41e | ||
|
|
104882cb25 | ||
|
|
5d9c04072b | ||
|
|
27314be9a8 | ||
|
|
f20eb271d9 | ||
|
|
dfcbe9e76a | ||
|
|
fca97b84ac | ||
|
|
8f59f0284c | ||
|
|
2eb5b65fd9 | ||
|
|
a7ef2706e9 | ||
|
|
bd2f10fbfc | ||
|
|
8f53ec0130 | ||
|
|
fb980dc8fb | ||
|
|
6eacb355b7 | ||
|
|
4168799329 | ||
|
|
8ee2b905b8 | ||
|
|
381d9295b7 | ||
|
|
80bb8c909c | ||
|
|
88c9b7d6b8 | ||
|
|
badf9a7038 | ||
|
|
957d962ecb | ||
|
|
a366928f7f | ||
|
|
9a00fc9bbf | ||
|
|
1ad7b19c0a | ||
|
|
22e50a9fd7 | ||
|
|
c0faa41104 | ||
|
|
52d4c10a8c | ||
|
|
4b120cf8ea | ||
|
|
3a172f310e | ||
|
|
2a6163219e | ||
|
|
c4ba65bd8e | ||
|
|
f2bea3c33c | ||
|
|
d0077a8d83 | ||
|
|
28f2e0f31f | ||
|
|
8c8d26c1e1 | ||
|
|
0ac2991ad8 | ||
|
|
6ca2ee105a | ||
|
|
06e5e3f847 | ||
|
|
4ad5c08769 | ||
|
|
b0bf8fefe7 | ||
|
|
bfda0b58ae | ||
|
|
b7e79b5fa7 | ||
|
|
4f0f72190f | ||
|
|
74cd85b0e8 | ||
|
|
c699d298bf | ||
|
|
ea45662ed9 | ||
|
|
67f5358f45 | ||
|
|
c40e441f33 | ||
|
|
a3ee13e8e3 | ||
|
|
a3fa409eda | ||
|
|
7ac7d60468 | ||
|
|
cb34db3c86 | ||
|
|
ea8697137a | ||
|
|
e9246a5b6c | ||
|
|
d121082d4f | ||
|
|
2605978b43 | ||
|
|
f5b21be26d | ||
|
|
582859b35b | ||
|
|
184734ee70 | ||
|
|
3a44057a40 | ||
|
|
ef02abe0cb | ||
|
|
1d52993253 | ||
|
|
50031c4868 | ||
|
|
b3dae6fea7 | ||
|
|
fd35938fcb | ||
|
|
649ee0f31e | ||
|
|
e7110dc97b | ||
|
|
dcf577f84c | ||
|
|
fabb5612d5 | ||
|
|
2958fa49f8 | ||
|
|
211f5d8be7 | ||
|
|
3dac905fda | ||
|
|
75d70b1133 | ||
|
|
47b0c89589 | ||
|
|
212349b4c0 | ||
|
|
a4789cf43e | ||
|
|
395a9d955e | ||
|
|
937a3f97c4 | ||
|
|
6bb18563b4 | ||
|
|
2a9ba678d3 | ||
|
|
38e362a469 | ||
|
|
b56b5fc184 | ||
|
|
1cce2d20f4 | ||
|
|
717fada35e | ||
|
|
ca4be32d63 | ||
|
|
ad4c1f66f2 | ||
|
|
4af6b1688a | ||
|
|
045ce75362 | ||
|
|
442a49da8b | ||
|
|
8e859ff191 | ||
|
|
3b1b88b404 | ||
|
|
8306686e4c | ||
|
|
6d67dd129c | ||
|
|
5086ecd993 | ||
|
|
bbb87ebf9e | ||
|
|
a1ca9d62b7 | ||
|
|
0e4e4783fa | ||
|
|
1719148c58 | ||
|
|
2ea96973ad | ||
|
|
a35e8e127f | ||
|
|
46a67b1395 |
No files matched your search
@@ -1,5 +1,4 @@
|
|||||||
webapp/node_modules
|
webapp/node_modules
|
||||||
webapp/build
|
|
||||||
webapp/.storybook
|
webapp/.storybook
|
||||||
webapp/.vscode
|
webapp/.vscode
|
||||||
webapp/.env.local
|
webapp/.env.local
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: bug, triage
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behavior:
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
Or even paste your automation file here
|
||||||
|
**Expected behavior**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**Screenshots**
|
||||||
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
**Desktop (please complete the following information):**
|
||||||
|
- OS: [e.g. iOS]
|
||||||
|
- Browser [e.g. chrome, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Smartphone (please complete the following information):**
|
||||||
|
- Device: [e.g. iPhone6]
|
||||||
|
- OS: [e.g. iOS8.1]
|
||||||
|
- Browser [e.g. stock browser, safari]
|
||||||
|
- Version [e.g. 22]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for this project
|
||||||
|
title: ''
|
||||||
|
labels: triage
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
name: Other
|
||||||
|
about: ''
|
||||||
|
title: ''
|
||||||
|
labels: triage
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
name: Security Issue
|
||||||
|
about: 'Use this to report vulnerabilities '
|
||||||
|
title: ''
|
||||||
|
labels: triage, Vulnerability
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
@@ -1,18 +1,54 @@
|
|||||||
name: "Manual Build"
|
name: Build
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
type: string
|
type: string
|
||||||
description: "Version Number"
|
description: "Version Number"
|
||||||
required: true
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
metadata:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: "${{ github.event.inputs.version }} / ${{ matrix.arch }}"
|
name: Metadata
|
||||||
|
outputs:
|
||||||
|
version: ${{ steps.version.outputs.VERSION }}
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Get Version
|
||||||
|
id: version
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
if [ -z "${INPUT_VERSION}" ]; then
|
||||||
|
echo ::set-output name=VERSION::$(git describe --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
|
||||||
|
else
|
||||||
|
echo ::set-output name=VERSION::${INPUT_VERSION}
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
INPUT_VERSION: ${{ github.event.inputs.version }}
|
||||||
|
- name: ${{ steps.version.outputs.VERSION }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo ${{ steps.version.outputs.VERSION }}
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Build & Publish ${{ matrix.arch }} / ${{ needs.metadata.outputs.version }}
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
needs:
|
||||||
|
- metadata
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
arch: ["aarch64", "amd64", "armhf", "armv7", "i386"]
|
arch:
|
||||||
|
- "aarch64"
|
||||||
|
- "amd64"
|
||||||
|
- "armhf"
|
||||||
|
- "armv7"
|
||||||
|
- "i386"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Cancel Previous Runs
|
- name: Cancel Previous Runs
|
||||||
@@ -24,16 +60,55 @@ jobs:
|
|||||||
- name: Check out repository
|
- name: Check out repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Setup node
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
cache: "yarn"
|
||||||
|
cache-dependency-path: webapp/yarn.lock
|
||||||
|
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@v2.0.0
|
uses: docker/login-action@v2.0.0
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Build & Push to Dockerhub
|
- name: "Save version number"
|
||||||
|
run: echo "REACT_APP_BUILD_VERSION=${{ needs.metadata.outputs.version }}" > ./webapp/.env.production
|
||||||
|
|
||||||
|
- name: "Build Web"
|
||||||
|
run: cd webapp && yarn install && yarn build
|
||||||
|
|
||||||
|
- name: ${{ matrix.arch }} / ${{ needs.metadata.outputs.version }}
|
||||||
uses: home-assistant/builder@2022.07.0
|
uses: home-assistant/builder@2022.07.0
|
||||||
with:
|
with:
|
||||||
args: |
|
args: |
|
||||||
--${{ matrix.arch }} \
|
--${{ matrix.arch }} \
|
||||||
--version ${{ github.event.inputs.version }} \
|
--no-latest \
|
||||||
|
--version ${{ needs.metadata.outputs.version }} \
|
||||||
--target .
|
--target .
|
||||||
|
|
||||||
|
publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: "${{ github.event.inputs.version != '' }}"
|
||||||
|
needs:
|
||||||
|
- metadata
|
||||||
|
- deploy
|
||||||
|
name: Create Github Pre-Release
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Pre-Release ${{ needs.metadata.outputs.version }}
|
||||||
|
uses: actions/github-script@v6
|
||||||
|
env:
|
||||||
|
VERSION: ${{ needs.metadata.outputs.version }}
|
||||||
|
CHANGELOG: ${{ needs.metadata.outputs.changlelog }}
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
script: |
|
||||||
|
github.rest.repos.createRelease({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
tag_name: process.env.VERSION,
|
||||||
|
prerelease: true,
|
||||||
|
});
|
||||||
@@ -13,12 +13,12 @@ name: "CodeQL"
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ "main" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
# The branches below must be a subset of the branches above
|
# The branches below must be a subset of the branches above
|
||||||
branches: [ main ]
|
branches: [ "main" ]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '29 23 * * 0'
|
- cron: '26 21 * * 2'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
analyze:
|
analyze:
|
||||||
@@ -34,15 +34,9 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
language: [ 'javascript', 'python' ]
|
language: [ 'javascript', 'python' ]
|
||||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||||
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Cancel Previous Runs
|
|
||||||
uses: styfle/cancel-workflow-action@0.10.0
|
|
||||||
with:
|
|
||||||
all_but_latest: true
|
|
||||||
access_token: ${{ github.token }}
|
|
||||||
|
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
@@ -54,23 +48,25 @@ jobs:
|
|||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
# By default, queries listed here will override any specified in a config file.
|
# By default, queries listed here will override any specified in a config file.
|
||||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
||||||
|
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||||
|
# queries: security-extended,security-and-quality
|
||||||
|
|
||||||
|
|
||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v2
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||||
|
|
||||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
||||||
# and modify them (or add more) to build your code if your project
|
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
||||||
# uses a compiled language
|
|
||||||
|
|
||||||
#- run: |
|
# - run: |
|
||||||
# make bootstrap
|
# echo "Run, Build Application using script"
|
||||||
# make release
|
# ./location_of_script_within_repo/buildscript.sh
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@v2
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Dependency Review Action
|
||||||
|
#
|
||||||
|
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
|
||||||
|
#
|
||||||
|
# Source repository: https://github.com/actions/dependency-review-action
|
||||||
|
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
|
||||||
|
name: 'Dependency Review'
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dependency-review:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 'Checkout Repository'
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: 'Dependency Review'
|
||||||
|
uses: actions/dependency-review-action@v2
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
name: Deploy
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
|
||||||
branch: [main]
|
|
||||||
paths:
|
|
||||||
- "config.yaml"
|
|
||||||
jobs:
|
|
||||||
metadata:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Metadata
|
|
||||||
outputs:
|
|
||||||
version: ${{ steps.version.outputs.VERSION }}
|
|
||||||
changlelog: ${{ steps.changlelog.outputs.CHANGELOG }}
|
|
||||||
steps:
|
|
||||||
- name: Check out repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: Get Version
|
|
||||||
id: version
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo ::set-output name=VERSION::$(cat config.yaml | sed -nr 's/version: (.*)/\1/p')
|
|
||||||
- name: Get Changelog
|
|
||||||
id: changlelog
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo ::set-output name=CHANGELOG::$(cat CHANGELOG.md)
|
|
||||||
|
|
||||||
publish:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- metadata
|
|
||||||
name: Publish Github Release
|
|
||||||
steps:
|
|
||||||
- name: Publish Release ${{ needs.metadata.outputs.version }}
|
|
||||||
uses: actions/github-script@v6
|
|
||||||
env:
|
|
||||||
VERSION: ${{ needs.metadata.outputs.version }}
|
|
||||||
CHANGELOG: ${{ needs.metadata.outputs.changlelog }}
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
github.rest.repos.createRelease({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
tag_name: process.env.VERSION,
|
|
||||||
});
|
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
name: Tests
|
name: Commit Tests
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branch:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
paths:
|
||||||
|
- "webapp"
|
||||||
|
- "api"
|
||||||
pull_request:
|
pull_request:
|
||||||
branch:
|
branches:
|
||||||
- main
|
- main
|
||||||
jobs:
|
jobs:
|
||||||
metadata:
|
metadata:
|
||||||
@@ -72,40 +75,3 @@ jobs:
|
|||||||
run: cd webapp && yarn install
|
run: cd webapp && yarn install
|
||||||
- name: ${{ needs.metadata.outputs.version }} / ${{ matrix.action }}
|
- name: ${{ needs.metadata.outputs.version }} / ${{ matrix.action }}
|
||||||
run: cd webapp && yarn ${{ matrix.action }}
|
run: cd webapp && yarn ${{ matrix.action }}
|
||||||
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
name: Build & Publish ${{ matrix.arch }}
|
|
||||||
if: github.event_name != 'pull_request'
|
|
||||||
needs:
|
|
||||||
- metadata
|
|
||||||
- nodejs
|
|
||||||
- python
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
arch: ["aarch64", "amd64", "armhf", "armv7", "i386"]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Cancel Previous Runs
|
|
||||||
uses: styfle/cancel-workflow-action@0.10.0
|
|
||||||
with:
|
|
||||||
all_but_latest: true
|
|
||||||
access_token: ${{ github.token }}
|
|
||||||
|
|
||||||
- name: Check out repository
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v2.0.0
|
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Build & Push to Dockerhub - ${{ matrix.arch }} / ${{ needs.metadata.outputs.version }}
|
|
||||||
uses: home-assistant/builder@2022.07.0
|
|
||||||
with:
|
|
||||||
args: |
|
|
||||||
--${{ matrix.arch }} \
|
|
||||||
--no-latest \
|
|
||||||
--version ${{ needs.metadata.outputs.version }} \
|
|
||||||
--target .
|
|
||||||
@@ -1 +1,4 @@
|
|||||||
.vscode/*.log
|
.vscode/*.log
|
||||||
|
webapp/src/types/validators/index.test.ts
|
||||||
|
example/containerized/config/
|
||||||
|
example/containerized/.env
|
||||||
+57
-3
@@ -1,10 +1,65 @@
|
|||||||
# Changelog 
|
# Changelog 
|
||||||
|
|
||||||
|
## [0.5.2] - Better Controls
|
||||||
|
|
||||||
|
- Add automation trigger
|
||||||
|
- Speed dial on the bottom
|
||||||
|
<img src="https://user-images.githubusercontent.com/7451445/183231968-9891bbb4-5c7c-4e05-b804-36978c809a5c.png" width="200px"/>
|
||||||
|
- Infinite undos <img src="https://user-images.githubusercontent.com/7451445/183231977-ed000017-2886-4a57-b5fb-c7e527bf3894.png" width="200px"/>
|
||||||
|
|
||||||
|
## [0.5.1] - Sidebar!
|
||||||
|
|
||||||
|
- completely redesigned the sidebar!
|
||||||
|
|
||||||
|
- Disable/enable automatons
|
||||||
|
- See 'bad state' automatons
|
||||||
|
- Delete automatons from registry (in cases where references are stale)
|
||||||
|
- Refactored sidebar UX to match MUI standards
|
||||||
|
- Cleaned up editing tags in sidebar
|
||||||
|
<img src="https://user-images.githubusercontent.com/7451445/182066721-07a93651-2f83-44d5-8420-15093caa52df.png" width="400px"/>
|
||||||
|
|
||||||
|
- Websockets now live-refresh when updates occur
|
||||||
|
|
||||||
|
## [0.4.0] - Depedency update
|
||||||
|
|
||||||
|
- Core dependency updates
|
||||||
|
- Python port is now dynamically set
|
||||||
|
|
||||||
|
## [0.3.4] - Condition/Trigger Editor Upgrades!
|
||||||
|
|
||||||
|
- Many condition editor fixes
|
||||||
|
- Many trigger editor fixes
|
||||||
|
- Refactor time triggers & condition triggers (time + time pattern are now in a single node selection --- trying to keep list selection small)
|
||||||
|
- Support for condition: time weekdays
|
||||||
|
- Support for time inputs (using both timestamp device classes and input_datetime)
|
||||||
|
- Fixed up condition editor nesting error (though still a better experience on pc, it is mostly usable on mobile)
|
||||||
|
- Description generation for time+time pattern condition and triggers
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## [0.3.2] - Fixed Addon Image for arm-based devices
|
||||||
|
|
||||||
|
- Using hypercon instead of uvicorn (this losses the rust dependency which makes it easier to install on arm)
|
||||||
|
- Pre-building web assets outside of docker (this takes the image size down and speeds up instaltion of addon)
|
||||||
|
- Updated build scripts to actually fail installation when build/prep steps fail
|
||||||
|
- Ensured that builds for all architecture run successfully
|
||||||
|
- Re-worked github actions (quicker test phases)
|
||||||
|
|
||||||
|
## [0.3.1] - Increased Pagination + Restricted Repeat Node
|
||||||
|
|
||||||
|
- Increased pagination to display up to 10,000 autos for now
|
||||||
|
- Repeat node now has types
|
||||||
|
|
||||||
## [0.3.0] - Complete Refactor of Graphs
|
## [0.3.0] - Complete Refactor of Graphs
|
||||||
|
|
||||||
- Added visual support for
|
- Added visual support for
|
||||||
* Repeat Nodes
|
|
||||||
* Parallel Nodes
|
- Repeat Nodes
|
||||||
|
- Parallel Nodes
|
||||||
|
|
||||||
- Using collections for conditions & triggers
|
- Using collections for conditions & triggers
|
||||||
- Fixed several bugs with improper alerts
|
- Fixed several bugs with improper alerts
|
||||||
@@ -17,7 +72,6 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## [0.1.22] - Many Visual improvements
|
## [0.1.22] - Many Visual improvements
|
||||||
|
|
||||||
- Deprecated several custom components in favor of mui.com
|
- Deprecated several custom components in favor of mui.com
|
||||||
|
|||||||
+7
-14
@@ -1,8 +1,8 @@
|
|||||||
# <--- Pre-Build Args -->
|
# <--- Pre-Build Args -->
|
||||||
ARG BUILD_ARCH
|
ARG BUILD_ARCH
|
||||||
|
|
||||||
# <--- Image Setup -->
|
# <--- Main Image -->
|
||||||
FROM homeassistant/${BUILD_ARCH}-base-python:3.9-alpine3.14
|
FROM python:3.9.13-slim-buster
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# <--- Post-Build Args -->
|
# <--- Post-Build Args -->
|
||||||
@@ -13,11 +13,8 @@ ENV BUILD_VERSION $BUILD_VERSION
|
|||||||
|
|
||||||
# <--- System Wide Dependencies -->
|
# <--- System Wide Dependencies -->
|
||||||
ENV LANG C.UTF-8
|
ENV LANG C.UTF-8
|
||||||
RUN apk add --no-cache \
|
RUN apt-get update -y && \
|
||||||
nodejs \
|
apt-get install -y gcc git build-essential libtool automake curl
|
||||||
npm \
|
|
||||||
build-base \
|
|
||||||
python3-dev
|
|
||||||
|
|
||||||
# <--- Scripts -->
|
# <--- Scripts -->
|
||||||
COPY docker/bin /app/bin
|
COPY docker/bin /app/bin
|
||||||
@@ -28,16 +25,12 @@ RUN /app/bin/prep.sh
|
|||||||
# <--- Python Dependencies -->
|
# <--- Python Dependencies -->
|
||||||
COPY api/setup.py /app/setup.py
|
COPY api/setup.py /app/setup.py
|
||||||
|
|
||||||
# <--- Webapp Build -->
|
|
||||||
COPY webapp/ /app/web-builder
|
|
||||||
RUN cd /app/web-builder && \
|
|
||||||
echo "REACT_APP_BUILD_VERSION=${BUILD_VERSION}" > /app/web-builder/.env.production
|
|
||||||
|
|
||||||
# <--- BUILD -->
|
# <--- BUILD -->
|
||||||
RUN /app/bin/build.sh /app /app/web-builder
|
RUN /app/bin/build.sh /app
|
||||||
|
|
||||||
# <--- Api Code -->
|
# <--- Api Code -->
|
||||||
COPY api/src /app/src
|
COPY api/src /app/src
|
||||||
|
COPY webapp/build /app/web
|
||||||
|
|
||||||
# <--- Ports -->
|
# <--- Ports -->
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
@@ -45,7 +38,7 @@ EXPOSE 8000
|
|||||||
# <--- Final -->
|
# <--- Final -->
|
||||||
LABEL \
|
LABEL \
|
||||||
io.hass.type="addon" \
|
io.hass.type="addon" \
|
||||||
io.hass.arch="armhf|aarch64|i386|amd64"
|
io.hass.arch="armhf|aarch64|i386|amd64|armv7"
|
||||||
|
|
||||||
ENTRYPOINT [ "/app/bin/run.sh" ]
|
ENTRYPOINT [ "/app/bin/run.sh" ]
|
||||||
CMD [ "/app" ]
|
CMD [ "/app" ]
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2022 Ari Sosnovsky
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
BUILD_TAG=$(shell git describe --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
|
|
||||||
DC=BUILD_TAG=${BUILD_TAG} docker-compose -f docker-compose.build.yaml -f docker-compose.test.yaml
|
|
||||||
|
|
||||||
build-with-builder:
|
|
||||||
docker run \
|
|
||||||
--rm \
|
|
||||||
--privileged \
|
|
||||||
-v ~/.docker:/root/.docker \
|
|
||||||
-v /var/run/docker.sock:/var/run/docker.sock:ro \
|
|
||||||
-v ${PWD}:/data \
|
|
||||||
homeassistant/amd64-builder \
|
|
||||||
--amd64 \
|
|
||||||
--test \
|
|
||||||
--version ${BUILD_TAG} \
|
|
||||||
-t /data
|
|
||||||
|
|
||||||
build:
|
|
||||||
$(DC) build
|
|
||||||
|
|
||||||
build-no-cache:
|
|
||||||
$(DC) build --no-cache
|
|
||||||
|
|
||||||
push:
|
|
||||||
$(DC) push
|
|
||||||
|
|
||||||
start:
|
|
||||||
$(DC) up -d
|
|
||||||
sleep 1
|
|
||||||
$(DC) ps
|
|
||||||
|
|
||||||
logs:
|
|
||||||
$(DC) logs -f
|
|
||||||
|
|
||||||
ps:
|
|
||||||
$(DC) ps
|
|
||||||
|
|
||||||
stop:
|
|
||||||
$(DC) stop
|
|
||||||
|
|
||||||
bash:
|
|
||||||
$(DC) exec addon bash
|
|
||||||
|
|
||||||
config:
|
|
||||||
$(DC) config
|
|
||||||
@@ -1,56 +1,42 @@
|
|||||||
# Shortumation 
|
# <img src="logo.png" height="40x"/> Shortumation 
|
||||||
|
|
||||||
[](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml)
|
[](https://github.com/asosnovsky/Shortumation/actions/workflows/test.yml) [](https://github.com/asosnovsky/Shortumation/actions/workflows/build.yml)
|
||||||

|
|
||||||
| | Stable | Edge
|
|
||||||
| --- | --- | ---
|
|
||||||
| Version |  | 
|
|
||||||
|
|
||||||
A better way to write automations in home-assistant without having to install and run a seperate automation engine!
|
| | Stable | Edge |
|
||||||
|
| ------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| Version |  |  |
|
||||||
|
|
||||||
Sort and organize your home-assistant automations using tags!
|
A [home-assistant addon](https://www.home-assistant.io/addons/) for a better UI for managing and writing your automations. We provide a way to visualize your automation using a visual-programming language that draws inspirations from [Node-Red](https://nodered.org/).
|
||||||
|
|
||||||

|
<img src="./assets/comparisons.png">
|
||||||
|
|
||||||
Utilize the auto-generated node descriptions to understand what your automation is doing! No more reading YAML to just understand what 1 node does!
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
More condense UI for service calls!
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
Visualize complex 'choose' or 'if/else' nodes
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Visualize parallel nodes!
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Visualize repeat nodes!
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
A [home-assistant addon](https://www.home-assistant.io/addons/) for a better UI for managing your automations & scripts. We provide a way to visualize and develop your automation using a visual-programming language that draws inspirations from [Node-Red](https://nodered.org/).
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- [X] View your automations & scripts in a visual graph
|
- Sort and organize your home-assistant automations using tags!
|
||||||
- [X] See all automations in one common view
|
|
||||||
- [X] Automation Manager
|
|
||||||
- [X] Tags for automation organization
|
|
||||||
- [X] Autocomplete fields for entities/devices
|
|
||||||
- [X] Visualize parallel/repeat/choose/if-else nodes
|
|
||||||
- [X] Autogenerate node names
|
|
||||||
- [ ] Clean error reporting
|
|
||||||
- [ ] Script Editor
|
|
||||||
|
|
||||||
See roadmap in [Version 1 Github Project](https://github.com/asosnovsky/Shortumation/projects/1).
|
<img src="https://user-images.githubusercontent.com/7451445/179136346-cf04a8c0-ac4e-44b2-b9fe-806824864660.png" width="500px"/>
|
||||||
|
|
||||||
|
- Utilize the auto-generated node descriptions to understand what your automation is doing! No more reading YAML to just understand what 1 node does!
|
||||||
|
|
||||||
|
<img src="https://user-images.githubusercontent.com/7451445/179137357-455260f3-2cdd-44ca-ae62-084ed7c59ebd.png" width="500px"/>
|
||||||
|
|
||||||
|
- More condense UI for service calls!
|
||||||
|
|
||||||
|
<img src="https://user-images.githubusercontent.com/7451445/179137126-93601ea9-435f-4c4f-8f21-0d09cd61c7a2.png" width="500px"/>
|
||||||
|
|
||||||
|
- Visualize complex 'choose' or 'if/else' nodes
|
||||||
|
|
||||||
|
<img src="https://user-images.githubusercontent.com/7451445/179135734-8d7ca46d-7e6f-4975-abc3-de86a48de0c0.png" width="500px"/>
|
||||||
|
|
||||||
|
- Visualize parallel nodes!
|
||||||
|
|
||||||
|
<img src="https://user-images.githubusercontent.com/7451445/179136706-695912d7-e223-42d9-a27b-f330b021a56a.png" width="500px"/>
|
||||||
|
|
||||||
|
- Visualize repeat nodes!
|
||||||
|
|
||||||
|
<img src="https://user-images.githubusercontent.com/7451445/179135790-a5e77e2b-6d42-4810-a27b-ff4d165e99ec.png" width="500px"/>
|
||||||
|
|
||||||
|
See roadmap in [Version 1 Github Project](https://github.com/users/asosnovsky/projects/3/views/4).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -62,23 +48,34 @@ Add the repository URL under **Supervisor → Add-on store → ⋮ → Manage ad
|
|||||||
|
|
||||||
It should now appear in your `Add-on Store` and you should be able to install it!
|
It should now appear in your `Add-on Store` and you should be able to install it!
|
||||||
|
|
||||||
### Containerized
|
**Please note that you may need to enable advance mode in your settings first!**
|
||||||
|
|
||||||
Please note that this way of using Shortumation is **not future proof**, currently we use the `/config/automation.yaml` file as our source of truth for the automations. Which means that we do not need access to the HA API or Websockets. In future release you may need to configure some additional compomenents to enable this.
|
### Containerized or HA Core
|
||||||
|
|
||||||
If this warning does not scare you or you still want to try things out, then take a look at the example [docker-compose.yaml](example/containerized/docker-compose.yaml).
|
Please note that this way of using Shortumation is **not future proof**.
|
||||||
|
|
||||||
|
If this warning does not scare you or you still want to try things out, then take a look at the example [docker-compose.yaml](example/containerized/docker-compose.yaml), or read the [extended guide here](https://github.com/asosnovsky/Shortumation/wiki/Installation#containerized--ha-core).
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
**How is this different from Node-Red?**
|
**How is this different from Node-Red?**
|
||||||
|
|
||||||
> Node-Red is both an execution engine and an automation editor, which means that in order for you automations to run you have to have an additional component running and executing the automations. Shortumation simply provides a different editor and manager for writing Homeassistant automations, while relying on Homeassistant to execute the automations (this uses the `automations.yaml` file as the backend database)
|
> Node-Red is both an execution engine and an automation editor, which means that in order for your automations to run you have to have an additional component running and executing the automations. Shortumation simply provides a different editor and manager for writing Homeassistant automations, while relying on Homeassistant to execute the automations (this uses the `automations.yaml` file as the backend database)
|
||||||
|
|
||||||
**Which HA Installation does this support?**
|
**Which HA Installation does this support?**
|
||||||
|
|
||||||
> Currently this is only tested on HA OS. However, you should be able to get it working supervised installations as well (as they support addons). If you want to make it work for Container or Core, you will need to do some additional leg-work and I welcome a PR to get this working (it should be just a matter of mounting the `/config` path to the container running the images in this repo).
|
> Currently this is only tested on HA OS. However, you should be able to get it working supervised installations as well (as they support addons). If you want to make it work for Container or Core, you will need to do some additional leg-work and I welcome a PR to get this working (it should be just a matter of mounting the `/config` path to the container running the images in this repo).
|
||||||
|
|
||||||
**Which version of HA does this require?**
|
**Which version of HA does this require?**
|
||||||
|
|
||||||
> Since I am working on this project on my own, I can only test it against my own HA installations at home, and I tend to keep things as up to date as possible. The lowest version of HA this was tested on is `core-2022.5.4`
|
> Since I am working on this project on my own, I can only test it against my own HA installations at home, and I tend to keep things as up to date as possible. The lowest version of HA this was tested on is `core-2022.5.4`
|
||||||
|
|
||||||
|
**This is awesome and all, how can I help?**
|
||||||
|
|
||||||
|
> Take a look at our Roadmap in [Version 1 Github Project](https://github.com/users/asosnovsky/projects/3/views/4), the [Development Guide](https://github.com/asosnovsky/Shortumation/wiki/Development) and send me some PRs to review!
|
||||||
|
|
||||||
|
> Please also note that I did went ahead and marked some [good first issues](https://github.com/asosnovsky/Shortumation/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) if you want to pick them up just leave a comment and I will give you more context (I haven't had time to add more details).
|
||||||
|
|
||||||
|
**HACS Support? I don't like docker.**
|
||||||
|
|
||||||
|
> Currently this is beyond v1, but if this is something you really want please +1 this issue https://github.com/asosnovsky/Shortumation/issues/102 or perhaps help us get there yourself by contributing! :)
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
| Version | Supported |
|
| Version | Supported |
|
||||||
| ------- | ------------------ |
|
| ------- | ------------------ |
|
||||||
| 0.1.x | :white_check_mark: |
|
| 0.x.x | :white_check_mark: |
|
||||||
|
|
||||||
|
|
||||||
## Reporting a Vulnerability
|
## Reporting a Vulnerability
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
LOG_LEVEL=DEBUG
|
||||||
|
SUPERVISOR_TOKEN=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI2ZjJiYzM2MjkyOWM0OGM1Yjg1NzgxNDEzNTRkNDk0NSIsImlhdCI6MTY1OTExMTExMCwiZXhwIjoxOTc0NDcxMTEwfQ.Q5Ei1a9BXyB4-whrPGoko6CKavOOloFC1fbP-jAYBpU
|
||||||
|
HASSIO_WS=ws://homeassistant:8123/api/websocket
|
||||||
@@ -143,3 +143,4 @@ dmypy.json
|
|||||||
cython_debug/
|
cython_debug/
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/python
|
# End of https://www.toptal.com/developers/gitignore/api/python
|
||||||
|
development_config
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"njpwerner.autodocstring",
|
||||||
|
"bungcip.better-toml",
|
||||||
|
"ms-azuretools.vscode-docker",
|
||||||
|
"editorconfig.editorconfig",
|
||||||
|
"eamodio.gitlens",
|
||||||
|
"esbenp.prettier-vscode",
|
||||||
|
"ms-python.vscode-pylance",
|
||||||
|
"ms-python.python",
|
||||||
|
"redhat.vscode-yaml",
|
||||||
|
"ninoseki.vscode-pylens"
|
||||||
|
]
|
||||||
|
}
|
||||||
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"label": "Docker: Server",
|
||||||
|
"group": "none",
|
||||||
|
"command": ["make start-docker"],
|
||||||
|
"problemMatcher": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+6
-4
@@ -40,7 +40,9 @@ clean:
|
|||||||
find . -type d -name "__pycache__" -exec rm -r {} +
|
find . -type d -name "__pycache__" -exec rm -r {} +
|
||||||
find . -type d -name "*tmp" -exec rm -r {} +
|
find . -type d -name "*tmp" -exec rm -r {} +
|
||||||
|
|
||||||
run-local:
|
start-docker:
|
||||||
rm -f web
|
rm -rf ./development_config
|
||||||
ln -s ../webapp/build web
|
tar -xvf ../development_config.tar.gz -C ./
|
||||||
USE_EXAMPLE_REPO=1 $(VENV_BIN)/uvicorn src.app:app --reload
|
cp ./development_config/.env .env.api
|
||||||
|
docker-compose down
|
||||||
|
docker-compose up
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Make commands summary
|
||||||
|
|
||||||
|
`make setup`: configure python venv for development
|
||||||
|
|
||||||
|
`make test`: run all unittests
|
||||||
|
|
||||||
|
`make coverage`: run all unittests and report coverage stats
|
||||||
|
|
||||||
|
`make lint`: run all linter and code formatting
|
||||||
|
|
||||||
|
`make start-docker`: starts the api locally
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
homeassistant:
|
||||||
|
image: "ghcr.io/home-assistant/home-assistant:stable"
|
||||||
|
volumes:
|
||||||
|
- ./development_config/config:/config
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- main
|
||||||
|
ports:
|
||||||
|
- 8124:8123
|
||||||
|
addon:
|
||||||
|
image: "asosnovsky/shortumation-${ARCH:-amd64}:${BUILD_TAG:-edge}"
|
||||||
|
build:
|
||||||
|
context: "../"
|
||||||
|
dockerfile: "../Dockerfile"
|
||||||
|
args:
|
||||||
|
BUILD_ARCH: ${ARCH:-amd64}
|
||||||
|
BUILD_VERSION: ${BUILD_TAG:-edge}
|
||||||
|
volumes:
|
||||||
|
- "./development_config/config:/config"
|
||||||
|
- "./:/app"
|
||||||
|
- "../docker/bin:/app/bin"
|
||||||
|
- "../webapp/build:/app/web"
|
||||||
|
networks:
|
||||||
|
- main
|
||||||
|
ports:
|
||||||
|
- "8001:8000"
|
||||||
|
env_file:
|
||||||
|
- ./development_config/.env
|
||||||
|
entrypoint: hypercorn src.app:app --reload -b 0.0.0.0:8000
|
||||||
|
|
||||||
|
networks:
|
||||||
|
main:
|
||||||
+8
-7
@@ -7,21 +7,22 @@ setuptools.setup(
|
|||||||
"PyYAML==6.0",
|
"PyYAML==6.0",
|
||||||
"fastapi==0.78.0",
|
"fastapi==0.78.0",
|
||||||
"pydantic==1.9.1",
|
"pydantic==1.9.1",
|
||||||
"uvicorn[standard]==0.18.2",
|
"hypercorn==0.13.2",
|
||||||
"python-decouple==3.6",
|
"python-decouple==3.6",
|
||||||
|
"websockets==10.3"
|
||||||
],
|
],
|
||||||
extras_require={
|
extras_require={
|
||||||
"dev": [
|
"dev": [
|
||||||
"mypy==0.961",
|
"mypy==0.971",
|
||||||
"mypy-extensions==0.4.3",
|
"mypy-extensions==0.4.3",
|
||||||
"black==22.6.0",
|
"black==22.6.0",
|
||||||
"bandit==1.7.4",
|
"bandit==1.7.4",
|
||||||
"isort==5.10.1",
|
"isort==5.10.1",
|
||||||
"coverage==6.4.1",
|
"coverage==6.4.2",
|
||||||
"pre-commit==2.19.0",
|
"pre-commit==2.20.0",
|
||||||
"vulture==2.4",
|
"vulture==2.5",
|
||||||
"types-requests==2.28.0",
|
"types-requests==2.28.4",
|
||||||
"types-PyYAML==6.0.9",
|
"types-PyYAML==6.0.11",
|
||||||
"requests==2.28.1",
|
"requests==2.28.1",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
+11
-1
@@ -1,6 +1,7 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from fastapi.responses import RedirectResponse
|
||||||
|
|
||||||
from src.automations.manager import AutomationManager
|
from src.automations.manager import AutomationManager
|
||||||
from src.env import API_PREFIX, ORIGIN, ROOT_FOLDER
|
from src.env import API_PREFIX, ORIGIN, ROOT_FOLDER
|
||||||
@@ -10,7 +11,8 @@ from .routes import automations, details, ping, socket
|
|||||||
|
|
||||||
def make_app(automation_mgr: AutomationManager) -> FastAPI:
|
def make_app(automation_mgr: AutomationManager) -> FastAPI:
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
if (ROOT_FOLDER / "web").exists():
|
has_web_folder = (ROOT_FOLDER / "web").exists()
|
||||||
|
if has_web_folder:
|
||||||
app.mount(
|
app.mount(
|
||||||
f"{API_PREFIX}/web",
|
f"{API_PREFIX}/web",
|
||||||
StaticFiles(
|
StaticFiles(
|
||||||
@@ -19,6 +21,7 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI:
|
|||||||
),
|
),
|
||||||
name="web",
|
name="web",
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("WARN: could not find web folder")
|
print("WARN: could not find web folder")
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
@@ -36,4 +39,11 @@ def make_app(automation_mgr: AutomationManager) -> FastAPI:
|
|||||||
details.make_details_router(automation_mgr.hass_config), prefix=f"{API_PREFIX}/details"
|
details.make_details_router(automation_mgr.hass_config), prefix=f"{API_PREFIX}/details"
|
||||||
)
|
)
|
||||||
app.include_router(socket.router, prefix=f"{API_PREFIX}/socket")
|
app.include_router(socket.router, prefix=f"{API_PREFIX}/socket")
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def get_index():
|
||||||
|
if has_web_folder:
|
||||||
|
return RedirectResponse("/web")
|
||||||
|
return RedirectResponse("/details")
|
||||||
|
|
||||||
return app
|
return app
|
||||||
@@ -5,6 +5,7 @@ from src.api.types import (
|
|||||||
ListData,
|
ListData,
|
||||||
ListParams,
|
ListParams,
|
||||||
UpdateAutoRequest,
|
UpdateAutoRequest,
|
||||||
|
UpdateTags,
|
||||||
)
|
)
|
||||||
from src.automations.errors import FailedDeletion
|
from src.automations.errors import FailedDeletion
|
||||||
from src.automations.manager import AutomationManager
|
from src.automations.manager import AutomationManager
|
||||||
@@ -29,6 +30,10 @@ def make_automation_router(automations: AutomationManager) -> APIRouter:
|
|||||||
def upsert_auto(body: UpdateAutoRequest):
|
def upsert_auto(body: UpdateAutoRequest):
|
||||||
automations.update(body.index, body.data)
|
automations.update(body.index, body.data)
|
||||||
|
|
||||||
|
@router.post("/item/tags")
|
||||||
|
def update_tags(body: UpdateTags):
|
||||||
|
automations.update_tags(body.automation_id, body.tags)
|
||||||
|
|
||||||
@router.delete("/item")
|
@router.delete("/item")
|
||||||
def delete_auto(body: DeleteAutoRequest):
|
def delete_auto(body: DeleteAutoRequest):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Generic, List, TypeVar
|
from typing import Dict, Generic, List, TypeVar
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from pydantic.fields import Field
|
from pydantic.fields import Field
|
||||||
@@ -25,5 +25,10 @@ class UpdateAutoRequest(BaseModel):
|
|||||||
data: ExtenededAutomationData
|
data: ExtenededAutomationData
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateTags(BaseModel):
|
||||||
|
automation_id: str = Field(description="Automation Id to update")
|
||||||
|
tags: Dict[str, str]
|
||||||
|
|
||||||
|
|
||||||
class DeleteAutoRequest(BaseModel):
|
class DeleteAutoRequest(BaseModel):
|
||||||
index: int = Field(description="Index of the automation to update")
|
index: int = Field(description="Index of the automation to update")
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Iterator, List, Optional
|
from typing import Dict, Iterator, List, Optional
|
||||||
|
|
||||||
from src.automations.errors import FailedDeletion, InvalidAutomationFile
|
from src.automations.errors import FailedDeletion, InvalidAutomationFile
|
||||||
from src.automations.types import AutomationData, ExtenededAutomationData
|
from src.automations.types import AutomationData, ExtenededAutomationData
|
||||||
@@ -24,7 +24,7 @@ class AutomationManager:
|
|||||||
break
|
break
|
||||||
yield from load_automation(auto, tags.get(auto.get("id", ""), {}))
|
yield from load_automation(auto, tags.get(auto.get("id", ""), {}))
|
||||||
|
|
||||||
def get(self, index: int) -> Optional[AutomationData]:
|
def get(self, index: int) -> Optional[ExtenededAutomationData]:
|
||||||
tags = self.hass_config.automation_tags
|
tags = self.hass_config.automation_tags
|
||||||
if index >= 0:
|
if index >= 0:
|
||||||
for i, auto in enumerate(self.hass_config.automations):
|
for i, auto in enumerate(self.hass_config.automations):
|
||||||
@@ -51,6 +51,11 @@ class AutomationManager:
|
|||||||
self.hass_config.save_automations(automations)
|
self.hass_config.save_automations(automations)
|
||||||
self.hass_config.save_tags(tags)
|
self.hass_config.save_tags(tags)
|
||||||
|
|
||||||
|
def update_tags(self, auto_id: str, tags: Dict[str, str]):
|
||||||
|
autos_tags = self.hass_config.automation_tags
|
||||||
|
autos_tags[auto_id] = tags
|
||||||
|
self.hass_config.save_tags(autos_tags)
|
||||||
|
|
||||||
def delete(self, index: int):
|
def delete(self, index: int):
|
||||||
automations: List[dict] = []
|
automations: List[dict] = []
|
||||||
deleted = False
|
deleted = False
|
||||||
|
|||||||
@@ -10,9 +10,12 @@ def find_hass_config() -> HassConfig:
|
|||||||
"""Try to find HASS config."""
|
"""Try to find HASS config."""
|
||||||
if config("USE_EXAMPLE_REPO", False, cast=bool):
|
if config("USE_EXAMPLE_REPO", False, cast=bool):
|
||||||
print("using USE_EXAMPLE_REPO")
|
print("using USE_EXAMPLE_REPO")
|
||||||
from tests.utils import create_copy_of_example_config, HA_CONFIG3_EXAMPLE
|
from tests.utils import (
|
||||||
|
HA_CONFIG2_EXAMPLE,
|
||||||
|
create_copy_of_example_config,
|
||||||
|
)
|
||||||
|
|
||||||
path = create_copy_of_example_config(HA_CONFIG3_EXAMPLE)
|
path = create_copy_of_example_config(HA_CONFIG2_EXAMPLE)
|
||||||
print("|-> ", path)
|
print("|-> ", path)
|
||||||
return HassConfig(path)
|
return HassConfig(path)
|
||||||
|
|
||||||
|
|||||||
@@ -100,3 +100,16 @@ class manager_tests(TestCase):
|
|||||||
self.assertEqual(manager.get_total_items(), 3)
|
self.assertEqual(manager.get_total_items(), 3)
|
||||||
with self.assertRaises(FailedDeletion):
|
with self.assertRaises(FailedDeletion):
|
||||||
manager.delete(10)
|
manager.delete(10)
|
||||||
|
|
||||||
|
def test_save_tags(self):
|
||||||
|
_, _, manager = get_dummy_automation_loader(
|
||||||
|
[
|
||||||
|
ExtenededAutomationData(metadata=AutomationMetdata(id="test1")),
|
||||||
|
ExtenededAutomationData(metadata=AutomationMetdata(id="test2")),
|
||||||
|
ExtenededAutomationData(metadata=AutomationMetdata(id="test3")),
|
||||||
|
],
|
||||||
|
automation_in_conifguration_mode="none",
|
||||||
|
)
|
||||||
|
manager.update_tags("test1", {"room": "bathroom"})
|
||||||
|
auto = manager.get(0)
|
||||||
|
assert auto.tags == {"room": "bathroom"}
|
||||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.9 MiB |
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name: Shortumation
|
name: Shortumation
|
||||||
version: v0.3.0
|
version: v0.5.2
|
||||||
slug: shortumation
|
slug: shortumation
|
||||||
image: asosnovsky/shortumation-{arch}
|
image: asosnovsky/shortumation-{arch}
|
||||||
url: "https://github.com/asosnovsky/Shortumation"
|
url: "https://github.com/asosnovsky/Shortumation"
|
||||||
|
|||||||
Binary file not shown.
@@ -1,10 +0,0 @@
|
|||||||
version: '3'
|
|
||||||
services:
|
|
||||||
addon:
|
|
||||||
image: "asosnovsky/shortumation-${ARCH:-amd64}:${BUILD_TAG:-edge}"
|
|
||||||
build:
|
|
||||||
context: "./"
|
|
||||||
dockerfile: "./Dockerfile"
|
|
||||||
args:
|
|
||||||
BUILD_ARCH: ${ARCH:-amd64}
|
|
||||||
BUILD_VERSION: ${BUILD_TAG:-edge}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
version: '3'
|
|
||||||
services:
|
|
||||||
addon:
|
|
||||||
volumes:
|
|
||||||
- "./sample_config:/config"
|
|
||||||
- "./api/tests:/app/tests"
|
|
||||||
ports:
|
|
||||||
- "8000:8000"
|
|
||||||
env_file:
|
|
||||||
- api/.env
|
|
||||||
+4
-8
@@ -2,7 +2,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
api_location=${1}
|
api_location=${1}
|
||||||
web_location=${2}
|
# web_location=${2}
|
||||||
|
|
||||||
function install_yarn() {
|
function install_yarn() {
|
||||||
pushd $web_location
|
pushd $web_location
|
||||||
@@ -18,11 +18,7 @@ function install_py() {
|
|||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
declare -i err=0 werr=0
|
install_py
|
||||||
install_py &
|
# install_yarn
|
||||||
install_yarn &
|
|
||||||
while wait -fn || werr=$?; ((werr != 127)); do
|
|
||||||
err=$werr
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "DONE BUILD"
|
echo "DONE BUILD"
|
||||||
+7
-8
@@ -2,18 +2,17 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
function prep_yarn() {
|
function prep_yarn() {
|
||||||
|
curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n
|
||||||
|
ln -s /usr/bin/nodejs /usr/bin/node
|
||||||
|
bash n lts
|
||||||
npm i -g yarn
|
npm i -g yarn
|
||||||
}
|
}
|
||||||
|
|
||||||
function prep_py() {
|
function prep_py() {
|
||||||
pip install -U wheel setuptools pip
|
pip install -U wheel setuptools pip Cython
|
||||||
}
|
}
|
||||||
|
|
||||||
declare -i err=0 werr=0
|
prep_py
|
||||||
prep_py &
|
# prep_yarn
|
||||||
prep_yarn &
|
|
||||||
while wait -fn || werr=$?; ((werr != 127)); do
|
|
||||||
err=$werr
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "DONE PREP"
|
echo "DONE PREP"
|
||||||
+6
-1
@@ -1,10 +1,15 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
api_location=${1}
|
api_location=${1}
|
||||||
|
port=${PORT:-8000}
|
||||||
|
host=${HOST:-0.0.0.0}
|
||||||
|
host_port="$host:$port"
|
||||||
|
|
||||||
pushd $api_location
|
pushd $api_location
|
||||||
echo "--------------------"
|
echo "--------------------"
|
||||||
echo "BUILD_VERSION = "$BUILD_VERSION
|
echo "BUILD_VERSION = "$BUILD_VERSION
|
||||||
|
echo "HOST = $host_port"
|
||||||
|
echo "HASSIO_WS = $HASSIO_WS"
|
||||||
echo $(python --version)
|
echo $(python --version)
|
||||||
echo "--------------------"
|
echo "--------------------"
|
||||||
python -m uvicorn src.app:app --host "0.0.0.0" --port 8000
|
python -m hypercorn src.app:app -b $host_port
|
||||||
@@ -4,18 +4,20 @@ services:
|
|||||||
container_name: homeassistant
|
container_name: homeassistant
|
||||||
image: "ghcr.io/home-assistant/home-assistant:stable"
|
image: "ghcr.io/home-assistant/home-assistant:stable"
|
||||||
volumes:
|
volumes:
|
||||||
- config:/config
|
- ./config:/config
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
privileged: true
|
privileged: true
|
||||||
network_mode: host
|
network_mode: host
|
||||||
|
|
||||||
shortumation:
|
shortumation:
|
||||||
# make sure to replace the ARCH with whatever system you are running!
|
# make sure to replace the ARCH with whatever system you are running!
|
||||||
image: "asosnovsky/shortumation-${ARCH:-amd64}:latest"
|
image: "asosnovsky/shortumation-${ARCH:-amd64}:${SHORTUMATION_VERSION:-latest}"
|
||||||
volumes:
|
|
||||||
- config:/config
|
|
||||||
ports:
|
ports:
|
||||||
- 8081:8000
|
- 8000:8000
|
||||||
|
extra_hosts:
|
||||||
volumes:
|
- "host.docker.internal:host-gateway"
|
||||||
config:
|
volumes:
|
||||||
|
- ./config:/config
|
||||||
|
environment:
|
||||||
|
- SUPERVISOR_TOKEN=${SUPERVISOR_TOKEN}
|
||||||
|
- HASSIO_WS=ws://host.docker.internal:8123/api/websocket
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
|||||||
<mxfile host="Electron" modified="2021-12-22T03:59:52.849Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/13.7.3 Chrome/85.0.4183.98 Electron/10.1.2 Safari/537.36" etag="tLc5i3WharxOLc8-v9Jg" version="13.7.3" type="device" pages="2"><diagram id="jPQkoFvJ-TX3pFbO5KUV" name="autos">7V1bk5s4Fv41rtp5aBfizmM6l9mZ7exkJpNN5qkLg2yzwcgFuNvOrx9oI2wktQ22JATj9EOMwBi+c3TuOpoYb1fbn1N/vfyIQhhPdC3cTox3E10HuuMW/5Uju/2IrVUDizQKq4sOA5+jH7Aa1KrRTRTCrHFhjlCcR+vmYICSBAZ5Y8xPU/TcvGyO4uavrv0FpAY+B35Mj36Nwny5H3Ut7TD+bxgtlviXgVadWfn44mogW/ohej4aMt5PjLcpQvn+02r7FsYleBiX/fc+vHK2frAUJnmbL3x9cr+iHx/m/m/hl49go2lf7t7c2fr+Nk9+vKneuHrafIchSNEmCWF5FzAx7p+XUQ4/r/2gPPtcEL0YW+aruDpNP1X1oE8wzeH2aKh6yp8hWsE83RWXVGdtp0KsYhlgVsfPBwKYXjW2PAK/YK6K8BXRF/W9D7gUHypoOsAEXI2CBYYFo1SHKM2XaIESP35/GL0PNulTjdsBRa04OnzhAaF1dcn/YZ7vqingb3LURLYANN19q77/cvBXeTC18OG77fHJd7vq6FWK5H66gPmpt3as/ZXlq56kXApjP4+emnOGRYXqq59QVDxMTXEPWFPt6J/VoL/lmM0bZmiTBrC6B0HZ+qEuJ7ah3pQwdGJKGBY1JQzAmhKGqCnhKogSITh0jUaplhHHKAFxgoNCyU/C64CaR3H8FsUoffmuEfrQnQfFeJan6Ds8OmMHLpzNizN+HC2SYiwooIWpPI60GFAL40eTQjqHq3UhliBfuC3ohiYLblefGbYthpNrSdwXuhaFbpYX0Gb/issfn36P8mAJk58muu2vSgCTWbZ+gUKbTqe9CwaTZFYGnMCQiadN4ZmgXLZckCRypTIqoOXARL/niux8PtcDJrKhPbMtXiLAbVpBOsMK1lkaXxiyDoXsli+ubgDZuM5cy7RO2rIdcLUIWeAyjASWjSDOtxglrjroGVdskA4cVxMQuJo942oACsXzrnBv3i+MZy9BlxLwKPBj0i1/lUJ7J/MUf1Xy8KwbrXsTzl70dfOCluN5tLrSSvbToCKdyctmI8S0Tqs/wOJ7Ya4cNln+8XzvDpPvbeMC+nEO4W2j/NvR5yNSFkcHSpYHu2Oy8gz7nSew15LAhlL0xY99KiJV3CZaZ7CFPMvW+2zCPNqWFO/Hu6KEYN8+gEH7rd8okIuXywk0yQAUlkpvqhOrKAz38hJm0Q9/9nKrkovXZZD35S2s+4n1rrxXMauy/QQDFP4JSiBBrGqIh0ZyCGLoPRODVuQULbLvMA+Wx2DC9P0T3GP6gh/OSpUXhH62rOXbEf3Ogjwpzf/yrxiP/RmMPxU0yiPEJPoDccEM5TlaMbgiL8XqPdrkcZQUv44TfBqLo4r3WJfvvNouykTkFM3nUQCnAUoCuM6z6XNa/FyyeFzDJIhiPgxRh4xOcAT2ghqmuSWII7B4OMURi0KLrdu/fJ1ZrSbl5Dh52cJu07W+7Tad9q9D+FQwBwUNX4v3NIXOM1l/hm6L1M5NrrSXK9cyAk6SEhOLEcKWKWsM2twarCnAiUJN+4DhsEo1D6wWeWzRysAjmNbo3Yu36PxA9lxmr6b5Jk0eJ7odlxw7S4tPi/ITSq7OYF2mKmr6KawqLDoveFMVvFVFB0ZQU1VYI/IaOVFIMVXRwpMUrSqApjW5ti7K6U+60YbwCoaR/7iO/R1Mp7SyKE889qQunFcooZK6aBGiu6mLa9VFe0ZQU11g9huvuuhMIbXUhU1XNQ4xs26QCse0W+EqLLNu09Z0NOcLrJTSJYcE1jEoYE0GsOKq7VwKxcFX759N49kVN59N42EzR5E8nk17CxlMMpTiKtPH5WalQFGp45Fcrk97LyulDflks4JpFNC26ksBL1fpIqc22iGTogzpIrXk1KatWhiPQnDrmsdgaami29EpcClgZUcxddNkzXSprpRDR3cVjWPWFFTYMXVYVeM3x5SvY9qBEdR0TB3aPh+XY9qdQmo5pmNcpXvWznfa1iHj1Jcidr5D26owzvhapP2YTQZrwbpMo8llGU1DXATlXLj4QZyEoc2uIYa+bJfwofpeBOXSTv8gcXW8Jr/ixV294arA4rKD28ANZnINn9XO8BAHMx0CCJYIcdZmPS31t+0mU7Oq0B0gUb15ClQ2mUTtr87of1DXvjZ4UFwHBJtCYbjW70nCn7WJq+vOmsS4/ZHoBjc6sUz+zqtjxfgm+2cV1tSmReb9ygD66anaKfgjeeLQjkgPTVqEAirV+8BadkBJiGuhxpqS8ANpPSm3Fwadp29m0vhn0TgBCcBZJFkN4MQhSTvUo+ZcRumdXM59NbtRc+5QWJcBpVTW1VnGsgKxIF5wE4Ki5/iQTieSFIhjcMKaSLy3XIwsrsELnY4ZLdZO31jT8bkxSRGn2WvLa4e2MCnitUhHiw5wkGU27FoQyZ6aZ1E4jC3EwT1Jp2xEgiVSZJh0eHKpHJLwBhWTuAhRqTEJj86DDDMm0R5qNWMSHh2I7Ccm0RlI5WISWCINJShxLev2HpTQGPG0fqISVzNv31EJoNERNYUdiu54qxWWAJqSdSucwFYsLgG0AQWBrgW778AE0FgtKMYjSBSLTABtTEUGbUtsvbZL6Ry1WmICjdXYQYHJ0b3VHtVrz+19JrDapI0CW5Z1KBlbVrnKKLBl1YbLxRbv4/BP72MNQNtG1vVaNFXEOmPLCBVbuBNVumbvDX0A8G68v+doc6i8byjQxl26AVpT4Ty9DMXohZ98TG3ZScHWuy2q05HJwa5M7a5mHIIaet/UYMU2CWLcVpOLbMxORgQZLCF15ThgVuERLCG6ooOQWhbDE5FsjjGq5fprzX6gkcKNKgCj6O0mW3h3qujCCmq2qgCMgr3BWgS8aKRWswrQZsMi0TqB3MbZtFhVfpJlnEG7DFcXP12qE7xXkFZJJxi09X/TCfx1QntWUFQnGLRfMjad0JlGiukE45IA5eCjW1jgt4huVZNDlejWgDvLXrIZ5TU0ttrSGLeXFl0Cb5NRAtz+DN9i/1LCCuCBPdzJLox5rPmd8eT9iX6/M+/e/Io+peHu4Q60Zh3u4uEV1iFKUy2H0AivrJ04z4OebB5sEZ4XvvUH8BT0Qhhd7tXd/eNAR5UdFdxu5eaoiHRUOrCCoo6KTUfLR+aodKeRYo6KrcISVatZHGuZdCd42RKODs8r2pb7QEGlNUaLRaI3jXG1xuhclq6cxqALncemMbovHVBLYzisKPUga3oNLITqwAG7NYJUdFmm9RDRdd0muBbeNLA/aBXtoNS9mzZhL9mgd5mggBUJNECakSatzeSaPYydJhSOPThDsCSdmyUpwZLswAqKWpKMbSlGZkl2p5FqluR4Vt6ZhOqx5Rk7+h/G/d0vyS+/z379r2s/fPnffx7+umPZ6JL1sUXspqJEMsCgFTKPBv9nFe5JIqmsbo2buuWqbq9khFeULXPHUrk1SSNSt3xo1FS2wJEYWjiVfB/R+i1y9yMLryA6ghjXVDa6IXEoI2JCPNwljZfUgcAkfJOmL3K9mkrFyIeohExEkdEpphZdJ+KQa26wfde5ToSs03Y9sl0nv0oRJmKX9H3hwJY1qwSxn2VR0OAW4eWKTCRaL53m3w2mHZfZpC7g18n1FCDnNnIcmpYg9nKzNVoRi9rcnQnzcHsfD1VLSOrFfLlw5yYKCqj93dFllZUsQFiwOlLd/EJ5a6NtvCVkbZLY4pzA4jBFKD/moPJFP6IQllf8DQ==</diagram><diagram id="7X2k5OJ-jCNTzSic57L4" name="Page-2">5Zlbc9o8EIZ/DZdhZMnGcJlAekyaTunXdnrTUWxhayJbrixO/fXfCsuAEU1IG4cwhQvs1cl63vVqJTpkmC1eK1qk1zJmooNRvOiQUQdjD5E+/BjLsrL0kDUkise20sYw5r9Y3dJapzxmZaOillJoXjSNkcxzFumGjSol581qEymaoxY0YY5hHFHhWr/yWKeVtY/Djf0N40laj+z1BlVJRuvKdiZlSmM53zKRyw4ZKil1dZUthkwYeDWXvr794NPPfoh+RFdfxvLbMsJnVWevHtNkPQXFcv3HXY9wcF32hmefv7+ek7dSq7dfRmeexTCjYmqB2cnqZU1QyWkeM9ML6pCLeco1Gxc0MqVz8BmwpToTcOfB5YQLMZRCqlVbMgnMF+ylVvKObZX0Vh/TQuZ6y159wG4fjCnNFjtSPsDBW4sDXs1kxrRaQjvbi2/ltP5MQns/33gHRtaWbnnG2kitRybrrjfU4cKCf4QI/r+uweBQCfpPIMHexyWOBFd8xvMEbJ+kzODnYqq1zO8RxntYmLZw9ps4vT08PbyHp98WTtejbyYTDlQwupaaG47o5oXCDJswfXxsmMEhMCeT06C5J9o+L83eATSvmaYngTN4Tufcu3a5gdMBlwC54rdAbN5Hb+vqqJWQ6B/b77AD6j3XUcry51xbfi+hC/JoLuWSasGlHkPC+lDYDVwf8gKXDH4CMuLupxz9t/hYTNOrAH8IZrPRO5vg30umvGPgVTZPLCTPNVOXM5h2af1kvYsxFWJapuuscsuZmpliLnPmppUBMl+wC3rLxEdZ8lX0JKOImUGhwEjDYSd2tVPhVoK7Z1sVzgVPTIGWxqnlVAuew+j1htAMQm2Vdecwj8LMOVskZuPalaso3gXLine truncated
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
0:
|
|
||||||
Type: Generic2
|
|
||||||
1:
|
|
||||||
Type: Generic
|
|
||||||
2:
|
|
||||||
Type: Climate
|
|
||||||
Room: House
|
|
||||||
4: {}
|
|
||||||
3:
|
|
||||||
Type: Vent
|
|
||||||
Room: Bathroom
|
|
||||||
Floor: First
|
|
||||||
5: {}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
- id: '1616887975473'
|
|
||||||
alias: Home Assistant Off
|
|
||||||
description: ''
|
|
||||||
trigger_variables:
|
|
||||||
mode: single
|
|
||||||
trigger:
|
|
||||||
- platform: homeassistant
|
|
||||||
event: shutdown
|
|
||||||
- $smType: trigger
|
|
||||||
platform: device
|
|
||||||
device_id: ''
|
|
||||||
domain: ''
|
|
||||||
type: ''
|
|
||||||
subtype: ''
|
|
||||||
condition: []
|
|
||||||
action:
|
|
||||||
- device_id: 2a98db84af7526c7ec3cc7aebd1a9e1c
|
|
||||||
domain: mobile_app
|
|
||||||
type: notify
|
|
||||||
title: Hassio Status
|
|
||||||
message: Hassio Is turning off...
|
|
||||||
- choose: []
|
|
||||||
default: []
|
|
||||||
alias: choose better days
|
|
||||||
- id: '1616888026264'
|
|
||||||
alias: Home Assistant On
|
|
||||||
description: ''
|
|
||||||
trigger_variables:
|
|
||||||
mode: single
|
|
||||||
trigger:
|
|
||||||
- platform: homeassistant
|
|
||||||
event: start
|
|
||||||
condition: []
|
|
||||||
action:
|
|
||||||
- device_id: 2a98db84af7526c7ec3cc7aebd1a9e1c
|
|
||||||
domain: mobile_app
|
|
||||||
type: notify
|
|
||||||
title: Hassio Status
|
|
||||||
message: Home assistant is up!
|
|
||||||
- id: shortu-2
|
|
||||||
alias: Neat trick
|
|
||||||
description: ''
|
|
||||||
mode: queued
|
|
||||||
trigger: []
|
|
||||||
condition: []
|
|
||||||
action:
|
|
||||||
- alias: Choose
|
|
||||||
default:
|
|
||||||
- condition: and
|
|
||||||
alias: ''
|
|
||||||
conditions:
|
|
||||||
- condition: or
|
|
||||||
conditions: []
|
|
||||||
choose: []
|
|
||||||
- service: lights.turn_on
|
|
||||||
target:
|
|
||||||
entity: bear
|
|
||||||
data: {}
|
|
||||||
- id: shortu-3
|
|
||||||
alias: Bathroom Vent
|
|
||||||
description: Turn the vent on when the humidity is high or it's smelly
|
|
||||||
trigger_variables:
|
|
||||||
mode: single
|
|
||||||
trigger: []
|
|
||||||
condition: []
|
|
||||||
action: []
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# empty configuration file
|
|
||||||
cloud:
|
|
||||||
+1
-1
@@ -21,4 +21,4 @@
|
|||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
development_config
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<link rel="icon" type="image/png" href="/icon.png" sizes="192x192">
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { addons } from '@storybook/addons';
|
||||||
|
import theme from './shortumationTheme';
|
||||||
|
|
||||||
|
addons.setConfig({
|
||||||
|
theme,
|
||||||
|
});
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import theme from './shortumationTheme';
|
||||||
|
|
||||||
export const parameters = {
|
export const parameters = {
|
||||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
actions: { argTypesRegex: "^on[A-Z].*" },
|
||||||
@@ -7,4 +8,7 @@ export const parameters = {
|
|||||||
date: /Date$/,
|
date: /Date$/,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
docs: {
|
||||||
|
theme,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { create } from '@storybook/theming';
|
||||||
|
|
||||||
|
export default create({
|
||||||
|
base: 'dark',
|
||||||
|
brandTitle: 'Shrotumation Storybook',
|
||||||
|
brandUrl: 'https://github.com/asosnovsky/Shortumation',
|
||||||
|
// brandImage: 'https://raw.githubusercontent.com/asosnovsky/Shortumation/main/icon.png',
|
||||||
|
brandTarget: '_blank',
|
||||||
|
});
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BIN_DIR="$( realpath $( dirname -- "${BASH_SOURCE[0]}" ) )"
|
||||||
|
VSCODE_DIR="$( dirname ${BIN_DIR} )"
|
||||||
|
WEBAPP_DIR="$( dirname ${VSCODE_DIR} )"
|
||||||
|
ROOT_DIR="$( dirname ${WEBAPP_DIR} )"
|
||||||
|
|
||||||
|
pushd $WEBAPP_DIR
|
||||||
|
rm -rf $WEBAPP_DIR/development_config
|
||||||
|
tar -xvf ../development_config.tar.gz -C $WEBAPP_DIR/
|
||||||
|
docker-compose down
|
||||||
|
docker-compose up
|
||||||
Vendored
+13
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"njpwerner.autodocstring",
|
||||||
|
"aeschli.vscode-css-formatter",
|
||||||
|
"paulmolluzzo.convert-css-in-js",
|
||||||
|
"ms-azuretools.vscode-docker",
|
||||||
|
"editorconfig.editorconfig",
|
||||||
|
"eamodio.gitlens",
|
||||||
|
"orta.vscode-jest",
|
||||||
|
"esbenp.prettier-vscode",
|
||||||
|
"pmneo.tsimporter"
|
||||||
|
]
|
||||||
|
}
|
||||||
Vendored
+77
-58
@@ -1,59 +1,78 @@
|
|||||||
{
|
{
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{
|
{
|
||||||
"type": "npm",
|
"icon": {
|
||||||
"script": "tsc",
|
"id": "server-environment"
|
||||||
"problemMatcher": [],
|
},
|
||||||
"label": "npm: tsc",
|
"type": "shell",
|
||||||
"detail": "tsc -w",
|
"label": "Docker: Start Server",
|
||||||
"presentation": {
|
"group": "none",
|
||||||
"reveal": "always",
|
"command": [".vscode/bin/start-docker-server.sh"],
|
||||||
"panel": "shared"
|
"runOptions": {
|
||||||
},
|
"runOn": "folderOpen"
|
||||||
"runOptions": {
|
},
|
||||||
"runOn": "folderOpen"
|
"problemMatcher": []
|
||||||
},
|
},
|
||||||
"group": "test"
|
{
|
||||||
},
|
"type": "npm",
|
||||||
{
|
"script": "tsc",
|
||||||
"type": "npm",
|
"problemMatcher": [],
|
||||||
"script": "test",
|
"label": "npm: tsc",
|
||||||
"problemMatcher": [],
|
"detail": "tsc -w",
|
||||||
"label": "npm: test",
|
"presentation": {
|
||||||
"detail": "test",
|
"reveal": "always",
|
||||||
"presentation": {
|
"panel": "shared"
|
||||||
"reveal": "always",
|
},
|
||||||
"panel": "shared"
|
"runOptions": {
|
||||||
},
|
"runOn": "folderOpen"
|
||||||
"runOptions": {
|
},
|
||||||
"runOn": "folderOpen"
|
"group": "test"
|
||||||
},
|
},
|
||||||
"group": "test",
|
{
|
||||||
},
|
"type": "npm",
|
||||||
{
|
"script": "test",
|
||||||
"type": "npm",
|
"problemMatcher": [],
|
||||||
"script": "storybook",
|
"label": "npm: test",
|
||||||
"problemMatcher": [],
|
"detail": "test",
|
||||||
"label": "npm: storybook",
|
"presentation": {
|
||||||
"detail": "start-storybook -p 6006 -s public",
|
"reveal": "always",
|
||||||
"promptOnClose": true
|
"panel": "shared"
|
||||||
},
|
},
|
||||||
{
|
"runOptions": {
|
||||||
"type": "npm",
|
"runOn": "folderOpen"
|
||||||
"script": "build",
|
},
|
||||||
"problemMatcher": [],
|
"group": "test"
|
||||||
"label": "npm: build",
|
},
|
||||||
"detail": "react-scripts build",
|
{
|
||||||
"group": "build"
|
"type": "npm",
|
||||||
},
|
"script": "storybook",
|
||||||
{
|
"problemMatcher": [],
|
||||||
"type": "npm",
|
"label": "npm: storybook",
|
||||||
"script": "start",
|
"detail": "start-storybook -p 6006 -s public",
|
||||||
"problemMatcher": [],
|
"promptOnClose": true,
|
||||||
"label": "npm: start",
|
"runOptions": {
|
||||||
"detail": "react-scripts start",
|
"runOn": "folderOpen"
|
||||||
"promptOnClose": true
|
}
|
||||||
},
|
},
|
||||||
]
|
{
|
||||||
}
|
"type": "npm",
|
||||||
|
"script": "build",
|
||||||
|
"problemMatcher": [],
|
||||||
|
"label": "npm: build",
|
||||||
|
"detail": "react-scripts build",
|
||||||
|
"group": "build"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "npm",
|
||||||
|
"script": "start",
|
||||||
|
"problemMatcher": [],
|
||||||
|
"label": "npm: start",
|
||||||
|
"detail": "react-scripts start",
|
||||||
|
"promptOnClose": true,
|
||||||
|
"runOptions": {
|
||||||
|
"runOn": "folderOpen"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+13
-40
@@ -1,46 +1,19 @@
|
|||||||
# Getting Started with Create React App
|
# Development Guide
|
||||||
|
|
||||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
## Prerequisites
|
||||||
|
|
||||||
## Available Scripts
|
- https://code.visualstudio.com/
|
||||||
|
- https://nodejs.org/en/
|
||||||
|
- https://www.docker.com/
|
||||||
|
|
||||||
In the project directory, you can run:
|
## Setup
|
||||||
|
|
||||||
### `yarn start`
|
Open this folder directly with vscode. As soon as it happens you will be prompted to install certain extensions and you should see a few tasks automatically spin up. Primarily:
|
||||||
|
|
||||||
Runs the app in the development mode.\
|
- `npm: tsc`: scans code and validate the syntax is correct
|
||||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
- `npm: test`: automatically run test cases
|
||||||
|
- `npm: start`: automatically starts the webap on port `3000`
|
||||||
|
- `npm: storybook`: automatically starts storybook on port `6006` (I recommend you develop containers using this first!)
|
||||||
|
- `Docker: Server`: this will start the Shortumation server as well as a development Homeassistant container (you can access these over locahost:8123 and localhost:8000).
|
||||||
|
|
||||||
The page will reload if you make edits.\
|
If you don't need some of these, you can turn them off by selecting the 'trash can' icon to their right.
|
||||||
You will also see any lint errors in the console.
|
|
||||||
|
|
||||||
### `yarn test`
|
|
||||||
|
|
||||||
Launches the test runner in the interactive watch mode.\
|
|
||||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
|
||||||
|
|
||||||
### `yarn build`
|
|
||||||
|
|
||||||
Builds the app for production to the `build` folder.\
|
|
||||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
|
||||||
|
|
||||||
The build is minified and the filenames include the hashes.\
|
|
||||||
Your app is ready to be deployed!
|
|
||||||
|
|
||||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
|
||||||
|
|
||||||
### `yarn eject`
|
|
||||||
|
|
||||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
|
||||||
|
|
||||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
|
||||||
|
|
||||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
|
||||||
|
|
||||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
|
||||||
|
|
||||||
## Learn More
|
|
||||||
|
|
||||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
|
||||||
|
|
||||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
homeassistant:
|
||||||
|
image: "ghcr.io/home-assistant/home-assistant:stable"
|
||||||
|
volumes:
|
||||||
|
- ./development_config/config:/config
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- main
|
||||||
|
ports:
|
||||||
|
- 8123:8123
|
||||||
|
addon:
|
||||||
|
image: "asosnovsky/shortumation-${ARCH:-amd64}:${BUILD_TAG:-edge}"
|
||||||
|
build:
|
||||||
|
context: "../"
|
||||||
|
dockerfile: "../Dockerfile"
|
||||||
|
args:
|
||||||
|
BUILD_ARCH: ${ARCH:-amd64}
|
||||||
|
BUILD_VERSION: ${BUILD_TAG:-edge}
|
||||||
|
volumes:
|
||||||
|
- "./development_config/config:/config"
|
||||||
|
- "../api:/app"
|
||||||
|
- "../docker/bin:/app/bin"
|
||||||
|
- "./build:/app/web"
|
||||||
|
networks:
|
||||||
|
- main
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
env_file:
|
||||||
|
- ./development_config/.env
|
||||||
|
entrypoint: hypercorn src.app:app --reload -b 0.0.0.0:8000
|
||||||
|
|
||||||
|
networks:
|
||||||
|
main:
|
||||||
+11
-11
@@ -9,23 +9,23 @@
|
|||||||
"@mui/icons-material": "5.8.4",
|
"@mui/icons-material": "5.8.4",
|
||||||
"@mui/material": "5.8.6",
|
"@mui/material": "5.8.6",
|
||||||
"@mui/styles": "5.8.6",
|
"@mui/styles": "5.8.6",
|
||||||
"@types/jest": "28.1.5",
|
"@types/jest": "28.1.6",
|
||||||
"@types/node": "17.0.36",
|
"@types/node": "17.0.36",
|
||||||
"@types/react": "18.0.14",
|
"@types/react": "18.0.15",
|
||||||
"@types/react-dom": "18.0.6",
|
"@types/react-dom": "18.0.6",
|
||||||
"@types/ws": "8.5.3",
|
"@types/ws": "8.5.3",
|
||||||
"@uiw/react-codemirror": "4.10.4",
|
"@uiw/react-codemirror": "4.10.4",
|
||||||
"autosuggest-highlight": "3.3.2",
|
"autosuggest-highlight": "3.3.4",
|
||||||
"home-assistant-js-websocket": "7.1.0",
|
"home-assistant-js-websocket": "7.1.0",
|
||||||
"jss": "10.9.0",
|
"jss": "10.9.2",
|
||||||
"material-ui-confirm": "3.0.4",
|
"material-ui-confirm": "3.0.4",
|
||||||
"notistack": "2.0.5",
|
"notistack": "2.0.5",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-cookie": "4.1.1",
|
"react-cookie": "4.1.1",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"react-flow-renderer": "10.3.8",
|
"react-flow-renderer": "10.3.12",
|
||||||
"react-imask": "6.4.2",
|
"react-imask": "6.4.2",
|
||||||
"react-jss": "10.9.0",
|
"react-jss": "10.9.2",
|
||||||
"react-router-dom": "6.3.0",
|
"react-router-dom": "6.3.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"superstruct": "0.16.0",
|
"superstruct": "0.16.0",
|
||||||
@@ -87,13 +87,13 @@
|
|||||||
"@storybook/react": "6.5.9",
|
"@storybook/react": "6.5.9",
|
||||||
"@testing-library/jest-dom": "5.16.4",
|
"@testing-library/jest-dom": "5.16.4",
|
||||||
"@testing-library/react": "13.3.0",
|
"@testing-library/react": "13.3.0",
|
||||||
"@testing-library/user-event": "14.2.1",
|
"@testing-library/user-event": "14.3.0",
|
||||||
"@types/autosuggest-highlight": "3.2.0",
|
"@types/autosuggest-highlight": "3.2.0",
|
||||||
"@types/chroma-js": "2.1.3",
|
"@types/chroma-js": "2.1.4",
|
||||||
"@types/js-yaml": "4.0.5",
|
"@types/js-yaml": "4.0.5",
|
||||||
"jest-environment-jsdom": "28.1.2",
|
"jest-environment-jsdom": "28.1.3",
|
||||||
"ts-node": "10.8.2",
|
"ts-node": "10.9.1",
|
||||||
"webpack": "5.73.0",
|
"webpack": "5.74.0",
|
||||||
"webpack-dev-server": "4.9.3"
|
"webpack-dev-server": "4.9.3"
|
||||||
},
|
},
|
||||||
"moduleDirectories": [
|
"moduleDirectories": [
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
@@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
<link rel="icon" href="%PUBLIC_URL%/icon.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<meta name="description" content="An easier way to maintain automations & scripts in
|
<meta name="description" content="An easier way to maintain automations & scripts in
|
||||||
home-assistant" />
|
home-assistant" />
|
||||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo.png" />
|
||||||
<!--
|
<!--
|
||||||
manifest.json provides metadata used when your web app is installed on a
|
manifest.json provides metadata used when your web app is installed on a
|
||||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 9.4 KiB |
@@ -1,21 +1,16 @@
|
|||||||
{
|
{
|
||||||
"short_name": "React App",
|
"short_name": "Shortumation",
|
||||||
"name": "Create React App Sample",
|
"name": "Shortumation",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "favicon.ico",
|
"src": "favicon.png",
|
||||||
"sizes": "64x64 32x32 24x24 16x16",
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
"type": "image/x-icon"
|
"type": "image/png"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"src": "logo192.png",
|
"src": "logo.png",
|
||||||
"type": "image/png",
|
"type": "image/png",
|
||||||
"sizes": "192x192"
|
"sizes": "192x192 512x512"
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "logo512.png",
|
|
||||||
"type": "image/png",
|
|
||||||
"sizes": "512x512"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"start_url": ".",
|
"start_url": ".",
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import App from "./App";
|
import App from "./App";
|
||||||
import { withQuery } from "@storybook/addon-queryparams";
|
import { withQuery } from "@storybook/addon-queryparams";
|
||||||
|
import { makeStory } from "devUtils";
|
||||||
|
|
||||||
const book = {
|
const { make, componentMeta } = makeStory({
|
||||||
title: "App/App",
|
Component: App,
|
||||||
decorators: [withQuery],
|
meta: {
|
||||||
component: App
|
title: "App",
|
||||||
};
|
decorators: [withQuery],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
export default componentMeta;
|
||||||
|
|
||||||
export const Basic = () => <App />
|
export const RootApp = make({});
|
||||||
|
|
||||||
export default book;
|
|
||||||
@@ -1,27 +1,46 @@
|
|||||||
import { AutomationData } from "types/automations";
|
import { AutomationData } from "types/automations";
|
||||||
import { API } from "./base";
|
import { API } from "./base";
|
||||||
import { ListData, ListParams } from "./types";
|
import { ListData, ListParams } from "./types";
|
||||||
import { AUTOMTAION_LIST, AUTOMTAION_ITEM } from './paths';
|
import {
|
||||||
|
AUTOMTAION_LIST,
|
||||||
|
AUTOMTAION_ITEM,
|
||||||
|
AUTOMTAION_ITEM_TAGS,
|
||||||
|
} from "./paths";
|
||||||
|
|
||||||
export const makeAutomationAPI = (api: API) => ({
|
export const makeAutomationAPI = (api: API) => ({
|
||||||
async list({ offset, limit }: ListParams) {
|
async list({ offset, limit }: ListParams) {
|
||||||
const data = await api.makeCall<ListData<AutomationData>, ListParams>({
|
const data = await api.makeCall<ListData<AutomationData>, ListParams>({
|
||||||
path: AUTOMTAION_LIST,
|
path: AUTOMTAION_LIST,
|
||||||
data: {
|
data: {
|
||||||
offset, limit,
|
offset,
|
||||||
}
|
limit,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
async update({ index, auto }: { index: number, auto: AutomationData }) {
|
async update({ index, auto }: { index: number; auto: AutomationData }) {
|
||||||
return await api.makeCall({
|
return await api.makeCall({
|
||||||
path: AUTOMTAION_ITEM,
|
path: AUTOMTAION_ITEM,
|
||||||
data: {
|
data: {
|
||||||
index,
|
index,
|
||||||
data: auto
|
data: auto,
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
},
|
||||||
|
async updateTags({
|
||||||
|
automation_id,
|
||||||
|
tags,
|
||||||
|
}: {
|
||||||
|
automation_id: string;
|
||||||
|
tags: Record<string, string>;
|
||||||
|
}) {
|
||||||
|
return await api.makeCall({
|
||||||
|
path: AUTOMTAION_ITEM_TAGS,
|
||||||
|
data: {
|
||||||
|
automation_id,
|
||||||
|
tags,
|
||||||
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
async remove({ index }: { index: number }) {
|
async remove({ index }: { index: number }) {
|
||||||
return await api.makeCall({
|
return await api.makeCall({
|
||||||
@@ -29,10 +48,9 @@ export const makeAutomationAPI = (api: API) => ({
|
|||||||
path: AUTOMTAION_ITEM,
|
path: AUTOMTAION_ITEM,
|
||||||
data: {
|
data: {
|
||||||
index,
|
index,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
export type AutomationAPI = ReturnType<typeof makeAutomationAPI>;
|
export type AutomationAPI = ReturnType<typeof makeAutomationAPI>;
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from "react";
|
||||||
import { useDefaultApiState, makeReloadAutomations } from './util';
|
import { useDefaultApiState, makeReloadAutomations } from "./util";
|
||||||
import { AutomationAPI } from './automations';
|
import { AutomationAPI } from "./automations";
|
||||||
|
|
||||||
export type ApiService = ReturnType<typeof useAPIService>;
|
export type ApiService = ReturnType<typeof useAPIService>;
|
||||||
export const useAPIService = (
|
export const useAPIService = (automationAPI: AutomationAPI) => {
|
||||||
automationAPI: AutomationAPI
|
|
||||||
) => {
|
|
||||||
// state
|
// state
|
||||||
const [state, setState] = useDefaultApiState();
|
const [state, setState] = useDefaultApiState();
|
||||||
const { reload, wrapCall } = makeReloadAutomations(automationAPI, state, setState);
|
const { reload, wrapCall } = makeReloadAutomations(
|
||||||
|
automationAPI,
|
||||||
|
state,
|
||||||
|
setState
|
||||||
|
);
|
||||||
|
|
||||||
// initial load of autos
|
// initial load of autos
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -21,5 +22,6 @@ export const useAPIService = (
|
|||||||
state,
|
state,
|
||||||
removeAutomation: wrapCall(automationAPI.remove),
|
removeAutomation: wrapCall(automationAPI.remove),
|
||||||
updateAutomation: wrapCall(automationAPI.update),
|
updateAutomation: wrapCall(automationAPI.update),
|
||||||
}
|
updateTags: wrapCall(automationAPI.updateTags),
|
||||||
}
|
};
|
||||||
|
};
|
||||||
@@ -1,22 +1,24 @@
|
|||||||
import { AutomationData } from 'types/automations';
|
import { AutomationData } from "types/automations";
|
||||||
import { makeAutomationAPI } from './automations';
|
import { makeAutomationAPI } from "./automations";
|
||||||
import { makeRemoteAPI } from "./base";
|
import { makeRemoteAPI } from "./base";
|
||||||
import { useAPIService } from './core';
|
import { useAPIService } from "./core";
|
||||||
import { useMockAPI } from "./mock";
|
import { useMockAPI } from "./mock";
|
||||||
|
import { useRef } from "react";
|
||||||
|
|
||||||
const locationPrefixWeb = window.location.pathname.match(/(\/.+\/)web/i);
|
const locationPrefixWeb = window.location.pathname.match(/(\/.+\/)web/i);
|
||||||
const baseURL = new URL(
|
const baseURL = new URL(
|
||||||
process.env.NODE_ENV === 'development' ?
|
process.env.NODE_ENV === "development"
|
||||||
`http://${window.location.hostname}:8000` :
|
? `http://${window.location.hostname}:8000`
|
||||||
window.location.origin + (!locationPrefixWeb ? '' : locationPrefixWeb[1])
|
: window.location.origin + (!locationPrefixWeb ? "" : locationPrefixWeb[1])
|
||||||
);
|
|
||||||
export const wsURL = baseURL + "socket"
|
|
||||||
export const remoteAutoAPI = makeRemoteAPI(
|
|
||||||
baseURL + "automations"
|
|
||||||
);
|
|
||||||
export const useConnectedApiService = () => useAPIService(
|
|
||||||
makeAutomationAPI(remoteAutoAPI)
|
|
||||||
);
|
|
||||||
export const useMockApiService = (initialAutos: AutomationData[]) => useAPIService(
|
|
||||||
makeAutomationAPI(useMockAPI(initialAutos))
|
|
||||||
);
|
);
|
||||||
|
export const wsURL = baseURL + "socket";
|
||||||
|
export const remoteAutoAPI = makeRemoteAPI(baseURL + "automations");
|
||||||
|
export const useConnectedApiService = () =>
|
||||||
|
useAPIService(makeAutomationAPI(remoteAutoAPI));
|
||||||
|
export const useMockApiService = (
|
||||||
|
initialAutos: AutomationData[],
|
||||||
|
returnErrors: boolean = false
|
||||||
|
) =>
|
||||||
|
useAPIService(
|
||||||
|
makeAutomationAPI(useMockAPI(initialAutos, useRef, returnErrors))
|
||||||
|
);
|
||||||
@@ -1,57 +1,93 @@
|
|||||||
import { useMockAPI } from "./mock"
|
import { useMockAPI } from "./mock";
|
||||||
import { makeAutomationAPI } from "./automations";
|
import { makeAutomationAPI } from "./automations";
|
||||||
import { createMockAuto } from '../utils/mocks';
|
import { createMockAuto } from "../utils/mocks";
|
||||||
|
import { AutomationData } from "types/automations";
|
||||||
|
|
||||||
const fakeUseRef = (a: any) => ({ current: a });
|
const fakeUseRef = (a: any) => ({ current: a });
|
||||||
|
|
||||||
test('mock api uses initial autos for initial population -- empty', async () => {
|
test("mock api uses initial autos for initial population -- empty", async () => {
|
||||||
const mockApi = makeAutomationAPI(useMockAPI([], fakeUseRef as any));
|
const mockApi = makeAutomationAPI(useMockAPI([], fakeUseRef as any));
|
||||||
const data = await mockApi.list({ limit: 10, offset: 0 });
|
const data = await mockApi.list({ limit: 10, offset: 0 });
|
||||||
expect(data.ok).toBe(true);
|
expect(data.ok).toBe(true);
|
||||||
expect((data as any).data.data).toHaveLength(0);
|
expect((data as any).data.data).toHaveLength(0);
|
||||||
expect((data as any).data.totalItems).toBe(0);
|
expect((data as any).data.totalItems).toBe(0);
|
||||||
})
|
});
|
||||||
|
|
||||||
test('mock api uses initial autos for initial population -- some data', async () => {
|
test("mock api uses initial autos for initial population -- some data", async () => {
|
||||||
const initials = [
|
const initials = [createMockAuto(), createMockAuto()];
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto()
|
|
||||||
];
|
|
||||||
const mockApi = makeAutomationAPI(useMockAPI(initials, fakeUseRef as any));
|
const mockApi = makeAutomationAPI(useMockAPI(initials, fakeUseRef as any));
|
||||||
const data = await mockApi.list({ limit: 10, offset: 0 });
|
const data = await mockApi.list({ limit: 10, offset: 0 });
|
||||||
expect(data.ok).toBe(true);
|
expect(data.ok).toBe(true);
|
||||||
expect((data as any).data.data).toHaveLength(2);
|
expect((data as any).data.data).toHaveLength(2);
|
||||||
expect((data as any).data.totalItems).toBe(2);
|
expect((data as any).data.totalItems).toBe(2);
|
||||||
})
|
});
|
||||||
|
|
||||||
test('populate mock api with some data', async () => {
|
test("populate mock api with some data", async () => {
|
||||||
const mockApi = makeAutomationAPI(useMockAPI([], fakeUseRef as any));
|
const mockApi = makeAutomationAPI(useMockAPI([], fakeUseRef as any));
|
||||||
await mockApi.update({index: 0, auto: createMockAuto()})
|
await mockApi.update({ index: 0, auto: createMockAuto() });
|
||||||
let data = await mockApi.list({ limit: 10, offset: 0 });
|
let data = await mockApi.list({ limit: 10, offset: 0 });
|
||||||
expect(data.ok).toBe(true);
|
expect(data.ok).toBe(true);
|
||||||
expect((data as any).data.data).toHaveLength(1);
|
expect((data as any).data.data).toHaveLength(1);
|
||||||
expect((data as any).data.totalItems).toBe(1);
|
expect((data as any).data.totalItems).toBe(1);
|
||||||
await mockApi.update({index: 1, auto: createMockAuto()})
|
await mockApi.update({ index: 1, auto: createMockAuto() });
|
||||||
data = await mockApi.list({ limit: 10, offset: 0 });
|
data = await mockApi.list({ limit: 10, offset: 0 });
|
||||||
expect((data as any).data.data).toHaveLength(2);
|
expect((data as any).data.data).toHaveLength(2);
|
||||||
expect((data as any).data.totalItems).toBe(2);
|
expect((data as any).data.totalItems).toBe(2);
|
||||||
})
|
});
|
||||||
|
|
||||||
test('delete/update data from mock api', async () => {
|
test("delete/update data from mock api", async () => {
|
||||||
const mockApi = makeAutomationAPI(useMockAPI([
|
const mockApi = makeAutomationAPI(
|
||||||
createMockAuto(),
|
useMockAPI(
|
||||||
createMockAuto(),
|
[
|
||||||
createMockAuto(),
|
createMockAuto(),
|
||||||
createMockAuto(),
|
createMockAuto(),
|
||||||
createMockAuto(),
|
createMockAuto(),
|
||||||
], fakeUseRef as any));
|
createMockAuto(),
|
||||||
let data = (await mockApi.list({ limit: 10, offset: 0 }) as any).data.data;
|
createMockAuto(),
|
||||||
|
],
|
||||||
|
fakeUseRef as any
|
||||||
|
)
|
||||||
|
);
|
||||||
|
let data = ((await mockApi.list({ limit: 10, offset: 0 })) as any).data.data;
|
||||||
const toBeEdited = data[0];
|
const toBeEdited = data[0];
|
||||||
toBeEdited.metadata.alias = "Bob is my uncle";
|
toBeEdited.metadata.alias = "Bob is my uncle";
|
||||||
await mockApi.update({index: 0, auto: toBeEdited})
|
await mockApi.update({ index: 0, auto: toBeEdited });
|
||||||
data = (await mockApi.list({ limit: 10, offset: 0 }) as any).data.data;
|
data = ((await mockApi.list({ limit: 10, offset: 0 })) as any).data.data;
|
||||||
expect(data[0].metadata.alias).toEqual("Bob is my uncle");
|
expect(data[0].metadata.alias).toEqual("Bob is my uncle");
|
||||||
await mockApi.remove({index: 0})
|
await mockApi.remove({ index: 0 });
|
||||||
data = (await mockApi.list({ limit: 10, offset: 0 }) as any).data.data;
|
data = ((await mockApi.list({ limit: 10, offset: 0 })) as any).data.data;
|
||||||
expect(data[0].metadata.alias === "Bob is my uncle").toEqual(false);
|
expect(data[0].metadata.alias === "Bob is my uncle").toEqual(false);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
test("update tags from mock api", async () => {
|
||||||
|
const mockApi = makeAutomationAPI(
|
||||||
|
useMockAPI(
|
||||||
|
[
|
||||||
|
createMockAuto(),
|
||||||
|
createMockAuto(),
|
||||||
|
createMockAuto(),
|
||||||
|
createMockAuto(),
|
||||||
|
createMockAuto(),
|
||||||
|
],
|
||||||
|
fakeUseRef as any
|
||||||
|
)
|
||||||
|
);
|
||||||
|
let data = ((await mockApi.list({ limit: 10, offset: 0 })) as any).data
|
||||||
|
.data as AutomationData[];
|
||||||
|
const autoId = data[0].metadata.id;
|
||||||
|
expect(data[0].tags).toStrictEqual({});
|
||||||
|
mockApi.updateTags({
|
||||||
|
automation_id: autoId,
|
||||||
|
tags: {
|
||||||
|
room: "bathroom",
|
||||||
|
type: "popup",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
data = ((await mockApi.list({ limit: 10, offset: 0 })) as any).data
|
||||||
|
.data as AutomationData[];
|
||||||
|
expect(data[0].metadata.id).toEqual(autoId);
|
||||||
|
expect(data[0].tags).toStrictEqual({
|
||||||
|
room: "bathroom",
|
||||||
|
type: "popup",
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,33 +1,41 @@
|
|||||||
import { useRef } from 'react';
|
import { useRef } from "react";
|
||||||
import { AutomationData } from 'types/automations';
|
import { AutomationData } from "types/automations";
|
||||||
import { API } from './base';
|
import { API } from "./base";
|
||||||
import { AUTOMTAION_LIST, AUTOMTAION_ITEM } from './paths';
|
import {
|
||||||
|
AUTOMTAION_LIST,
|
||||||
|
AUTOMTAION_ITEM,
|
||||||
|
AUTOMTAION_ITEM_TAGS,
|
||||||
|
} from "./paths";
|
||||||
|
|
||||||
export const useMockAPI = (
|
export const useMockAPI = (
|
||||||
initialAutos: AutomationData[] = [],
|
initialAutos: AutomationData[] = [],
|
||||||
makeRef = useRef,
|
makeRef = useRef,
|
||||||
|
returnErrors: boolean = false
|
||||||
): API => {
|
): API => {
|
||||||
const automationsRef = makeRef(initialAutos);
|
const automationsRef = makeRef(initialAutos);
|
||||||
return {
|
return {
|
||||||
async makeCall({
|
async makeCall({ path, method = "POST", data = {} }) {
|
||||||
path,
|
if (returnErrors) {
|
||||||
method = "POST",
|
return {
|
||||||
data = {}
|
ok: false,
|
||||||
}) {
|
error: "Test Error",
|
||||||
|
};
|
||||||
|
}
|
||||||
// console.debug("[[mockCall]]", method, path, data);
|
// console.debug("[[mockCall]]", method, path, data);
|
||||||
if (path === AUTOMTAION_LIST) {
|
if (path === AUTOMTAION_LIST) {
|
||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
data: JSON.parse(JSON.stringify({
|
data: JSON.parse(
|
||||||
totalItems: automationsRef.current.length,
|
JSON.stringify({
|
||||||
params: { offset: 0, limit: 100 },
|
totalItems: automationsRef.current.length,
|
||||||
data: automationsRef.current,
|
params: { offset: 0, limit: 100 },
|
||||||
}))
|
data: automationsRef.current,
|
||||||
} as any
|
})
|
||||||
|
),
|
||||||
|
} as any;
|
||||||
}
|
}
|
||||||
if (path === AUTOMTAION_ITEM) {
|
if (path === AUTOMTAION_ITEM) {
|
||||||
if (method === 'POST') {
|
if (method === "POST") {
|
||||||
const { index, data: auto } = data as any;
|
const { index, data: auto } = data as any;
|
||||||
if (index >= automationsRef.current.length) {
|
if (index >= automationsRef.current.length) {
|
||||||
automationsRef.current = [...automationsRef.current, auto];
|
automationsRef.current = [...automationsRef.current, auto];
|
||||||
@@ -35,29 +43,45 @@ export const useMockAPI = (
|
|||||||
automationsRef.current = [
|
automationsRef.current = [
|
||||||
...automationsRef.current.slice(0, index),
|
...automationsRef.current.slice(0, index),
|
||||||
auto,
|
auto,
|
||||||
...automationsRef.current.slice(index + 1)
|
...automationsRef.current.slice(index + 1),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
data: {}
|
data: {},
|
||||||
}
|
};
|
||||||
} else if (method === "DELETE") {
|
} else if (method === "DELETE") {
|
||||||
const { index } = data as any;
|
const { index } = data as any;
|
||||||
automationsRef.current = [
|
automationsRef.current = [
|
||||||
...automationsRef.current.slice(0, index),
|
...automationsRef.current.slice(0, index),
|
||||||
...automationsRef.current.slice(index + 1)
|
...automationsRef.current.slice(index + 1),
|
||||||
];
|
];
|
||||||
return {
|
return {
|
||||||
ok: true,
|
ok: true,
|
||||||
data: {}
|
data: {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (path === AUTOMTAION_ITEM_TAGS) {
|
||||||
|
if (method === "POST") {
|
||||||
|
const { automation_id, tags } = data as any;
|
||||||
|
for (let i = 0; i < automationsRef.current.length; i++) {
|
||||||
|
const auto = automationsRef.current[i];
|
||||||
|
if (auto.metadata.id === automation_id) {
|
||||||
|
automationsRef.current[i].tags = JSON.parse(JSON.stringify(tags));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
ok: false,
|
ok: false,
|
||||||
error: "PATH NOT FOUND " + method + ": " + path,
|
error: "PATH NOT FOUND " + method + ": " + path,
|
||||||
}
|
};
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
|
export const AUTOMTAION_ROOT = "/" as const;
|
||||||
|
|
||||||
export const AUTOMTAION_ROOT = '/' as const;
|
|
||||||
export const AUTOMTAION_LIST = `${AUTOMTAION_ROOT}list` as const;
|
export const AUTOMTAION_LIST = `${AUTOMTAION_ROOT}list` as const;
|
||||||
export const AUTOMTAION_ITEM = `${AUTOMTAION_ROOT}item` as const;
|
export const AUTOMTAION_ITEM = `${AUTOMTAION_ROOT}item` as const;
|
||||||
|
export const AUTOMTAION_ITEM_TAGS = `${AUTOMTAION_ITEM}/tags` as const;
|
||||||
@@ -1,31 +1,16 @@
|
|||||||
.automation-editor--info-box {
|
.automation-editor--info-box {
|
||||||
height: 100%;
|
|
||||||
padding-left: 10px;
|
|
||||||
padding-right: 10px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: flex-start;
|
align-items: center;
|
||||||
overflow: hidden;
|
gap: 0.5em;
|
||||||
position: relative;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.automation-editor--info-box-inner {
|
.automation-editor--info-box-inner {
|
||||||
height: 100%;
|
max-width: 95vw;
|
||||||
|
max-height: 90vh;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.automation-editor--info-box.show {
|
|
||||||
min-width: 20em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-editor--info-box.hide {
|
|
||||||
min-width: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-editor--info-box.hide>.automation-editor--info-box-inner {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-editor--info-box--tags {
|
.automation-editor--info-box--tags {
|
||||||
padding: 0.25em 0.75em 1em 0.75em;
|
padding: 0.25em 0.75em 1em 0.75em;
|
||||||
border-color: var(--mui-grey-400);
|
border-color: var(--mui-grey-400);
|
||||||
|
|||||||
@@ -1,57 +1,53 @@
|
|||||||
|
import { useTagDB } from "components/AutomationManager/TagDB";
|
||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|
||||||
import { makeTagDB } from "components/AutomationList/TagDB";
|
|
||||||
import { Page } from "components/Page";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { AutoInfoBox } from "./AutoInfoBox";
|
import { AutoInfoBox, AutoInfoBoxProps } from "./AutoInfoBox";
|
||||||
import { defaultAutomation } from 'utils/defaults';
|
import { makeStory } from "devUtils";
|
||||||
|
|
||||||
export default {
|
const { componentMeta, make } = makeStory({
|
||||||
title: 'App/AutomationList/Editor/InfoBox',
|
meta: {
|
||||||
component: AutoInfoBox,
|
title: "App/AutomationEditor/InfoBox",
|
||||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
},
|
||||||
args: {
|
Component: (args: {
|
||||||
tagDB: makeTagDB([
|
metadata: AutoInfoBoxProps["metadata"];
|
||||||
defaultAutomation("test")
|
tags: AutoInfoBoxProps["tags"];
|
||||||
])
|
onUpdate: AutoInfoBoxProps["onUpdate"];
|
||||||
}
|
}) => {
|
||||||
} as ComponentMeta<typeof AutoInfoBox>;
|
const [[metadata, tags], setState] = useState([args.metadata, args.tags]);
|
||||||
|
const tagDB = useTagDB(
|
||||||
|
[{ id: metadata.id, tags: Object.fromEntries(tags) }],
|
||||||
|
(_, t) => setState([metadata, Object.entries(t)])
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
export const NoTags: ComponentStory<typeof AutoInfoBox> = args => {
|
|
||||||
const [[metadata, tags], setState] = useState([args.metadata, args.tags])
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<AutoInfoBox
|
<AutoInfoBox
|
||||||
{...args}
|
{...args}
|
||||||
className=""
|
tagDB={tagDB}
|
||||||
metadata={metadata}
|
metadata={metadata}
|
||||||
tags={tags}
|
tags={tags}
|
||||||
onUpdate={(m, t) => {
|
onUpdate={(m, t) => {
|
||||||
args.onUpdate(m, t)
|
args.onUpdate(m, t);
|
||||||
setState([m, t])
|
setState([m, t]);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Page>
|
);
|
||||||
)
|
},
|
||||||
}
|
});
|
||||||
NoTags.args = {
|
|
||||||
...NoTags.args,
|
export default componentMeta;
|
||||||
|
export const NoTags = make({
|
||||||
tags: [],
|
tags: [],
|
||||||
metadata: {
|
metadata: {
|
||||||
id: "random",
|
id: "random",
|
||||||
alias: "Random",
|
alias: "Random",
|
||||||
description: "Example Metadata",
|
description: "Example Metadata",
|
||||||
trigger_variables: {
|
trigger_variables: {
|
||||||
'wowo': '!'
|
wowo: "!",
|
||||||
},
|
},
|
||||||
mode: 'single',
|
mode: "single",
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
|
|
||||||
export const SomeTags: ComponentStory<typeof AutoInfoBox> = NoTags.bind({})
|
export const SomeTags = make({
|
||||||
SomeTags.args = {
|
|
||||||
...SomeTags.args,
|
|
||||||
tags: [
|
tags: [
|
||||||
["Room", "Bathroom"],
|
["Room", "Bathroom"],
|
||||||
["Type", "Climate"],
|
["Type", "Climate"],
|
||||||
@@ -61,8 +57,8 @@ SomeTags.args = {
|
|||||||
alias: "Bathroom Vent",
|
alias: "Bathroom Vent",
|
||||||
description: "Turn the vent when the humidity is high",
|
description: "Turn the vent when the humidity is high",
|
||||||
trigger_variables: {
|
trigger_variables: {
|
||||||
'wowo': '!'
|
wowo: "!",
|
||||||
},
|
},
|
||||||
mode: 'single',
|
mode: "single",
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
@@ -1,26 +1,24 @@
|
|||||||
import "./AutoInfoBox.css";
|
import "./AutoInfoBox.css";
|
||||||
import { AutomationMetadata } from "types/automations";
|
import { AutomationMetadata } from "types/automations";
|
||||||
import { InputList } from "components/Inputs/InputList";
|
import { InputList } from "components/Inputs/InputList";
|
||||||
import InputText from "components/Inputs/InputText";
|
import InputText from "components/Inputs/Base/InputText";
|
||||||
import { FC, ReactNode, useRef, useState } from "react";
|
import { FC, ReactNode, useRef, useState } from "react";
|
||||||
import { AddIcon, TrashIcon } from "components/Icons";
|
import { AddIcon, TrashIcon } from "components/Icons";
|
||||||
import InputAutoText from "components/Inputs/InputAutoText";
|
import InputAutoText from "components/Inputs/InputAutoText";
|
||||||
import { TagDB } from "components/AutomationList/TagDB";
|
import { TagDB } from "components/AutomationManager/TagDB";
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||||
|
|
||||||
interface Props {
|
export interface AutoInfoBoxProps {
|
||||||
className: string;
|
|
||||||
metadata: AutomationMetadata;
|
metadata: AutomationMetadata;
|
||||||
tags: Array<[string, string]>;
|
tags: Array<[string, string]>;
|
||||||
onUpdate: (m: AutomationMetadata, tags: Array<[string, string]>) => void;
|
onUpdate: (m: AutomationMetadata, tags: Array<[string, string]>) => void;
|
||||||
tagDB: TagDB;
|
tagDB: TagDB;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
}
|
}
|
||||||
export const AutoInfoBox: FC<Props> = ({
|
export const AutoInfoBox: FC<AutoInfoBoxProps> = ({
|
||||||
metadata,
|
metadata,
|
||||||
tags,
|
tags,
|
||||||
onUpdate,
|
onUpdate,
|
||||||
className,
|
|
||||||
children,
|
children,
|
||||||
tagDB,
|
tagDB,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -97,7 +95,7 @@ export const AutoInfoBox: FC<Props> = ({
|
|||||||
]);
|
]);
|
||||||
// render
|
// render
|
||||||
return (
|
return (
|
||||||
<div className={`automation-editor--info-box ${className}`}>
|
<div className="automation-editor--info-box">
|
||||||
<div className="automation-editor--info-box-inner">
|
<div className="automation-editor--info-box-inner">
|
||||||
<InputText
|
<InputText
|
||||||
label="ID"
|
label="ID"
|
||||||
|
|||||||
@@ -29,13 +29,54 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
gap: 0.25em;
|
gap: 0.25em;
|
||||||
justify-content: flex-end;
|
justify-content: space-between;
|
||||||
margin-top: 0.25em;
|
margin-top: 0.25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.automation-editor--flow-wrapper.changed>.automation-editor--flow-wrapper--toolbar * {
|
.automation-editor--flow-wrapper--toolbar--title {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.25em;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-editor--flow-wrapper--toolbar--title--text .id {
|
||||||
|
font-size: 0.75em;
|
||||||
|
max-width: 15em;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
white-space: break-word;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
padding-bottom: 0.25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-editor--flow-wrapper--toolbar .automation-editor--flow-wrapper--toolbar--title--text {
|
||||||
|
min-width: 5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-editor--flow-wrapper--toolbar .automation-editor--flow-wrapper--toolbar--modes {
|
||||||
|
min-width: 6em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-editor--flow-wrapper--toolbar .automation-editor--flow-wrapper--toolbar--modes .MuiSelect-select {
|
||||||
|
padding-left: 0.25em;
|
||||||
|
padding-right: 0.25em;
|
||||||
|
padding-top: 1.15em;
|
||||||
|
padding-bottom: 0.25em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-editor--flow-wrapper--toolbar .automation-editor--flow-wrapper--toolbar--modes .MuiInputLabel-root {
|
||||||
|
font-size: 0.9em;
|
||||||
|
left: -0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-editor.changed .automation-editor--flow-wrapper--toolbar--save-btn,
|
||||||
|
.automation-editor--info-box--buttons.changed .automation-editor--flow-wrapper--toolbar--save-btn {
|
||||||
border-color: var(--mui-success-light);
|
border-color: var(--mui-success-light);
|
||||||
color: var(--mui-success-light)
|
color: var(--mui-success-light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -61,21 +102,6 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
.automation-editor .automation-editor--info-box--icon {
|
|
||||||
position: absolute;
|
|
||||||
left: 0.25em;
|
|
||||||
bottom: 0em;
|
|
||||||
z-index: 10;
|
|
||||||
max-width: 1.5em;
|
|
||||||
max-height: 1.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-editor--info-box.hide>.automation-editor--info-box--icon {
|
|
||||||
transform: rotate(180deg);
|
|
||||||
z-index: 2;
|
|
||||||
left: 0.1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-editor.loading .mock-list {
|
.automation-editor.loading .mock-list {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
@@ -96,4 +122,9 @@
|
|||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-editor--info-box--buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 1em;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
.mobile .automation-editor--flow-wrapper--toolbar {
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile .automation-editor--flow-wrapper--toolbar--title {
|
||||||
|
padding-left: 2.5em;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile .automation-editor--flow-wrapper--toolbar--title--text .input-text-view.view span {
|
||||||
|
max-height: 1.25em;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
word-break: break-all;
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile .automation-editor--flow-wrapper--toolbar--title--text .id,
|
||||||
|
.mobile .automation-editor--flow-wrapper--toolbar--title .input-text-view.description,
|
||||||
|
.mobile .automation-editor--flow-wrapper--toolbar--edit-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
import React from "react";
|
|
||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
||||||
import { AutomationEditor } from "./index";
|
import { AutomationEditor } from "./index";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Page } from "components/Page";
|
import { Page } from "components/Page";
|
||||||
import { makeTagDB } from "components/AutomationList/TagDB";
|
import { useTagDB } from "components/AutomationManager/TagDB";
|
||||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: "App/AutomationList/Editor",
|
title: "App/AutomationEditor",
|
||||||
component: AutomationEditor,
|
component: AutomationEditor,
|
||||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||||
args: {
|
args: {
|
||||||
@@ -21,7 +20,10 @@ const Template: ComponentStory<typeof AutomationEditor> = (args) => {
|
|||||||
<Page>
|
<Page>
|
||||||
<AutomationEditor
|
<AutomationEditor
|
||||||
{...args}
|
{...args}
|
||||||
tagDB={makeTagDB(state ? [state] : [])}
|
tagDB={useTagDB(
|
||||||
|
state ? [{ id: state.metadata.id, tags: state.tags }] : [],
|
||||||
|
() => {}
|
||||||
|
)}
|
||||||
automation={state}
|
automation={state}
|
||||||
onUpdate={(s) => {
|
onUpdate={(s) => {
|
||||||
window.setTimeout(() => setState(s), 3000);
|
window.setTimeout(() => setState(s), 3000);
|
||||||
@@ -45,7 +47,8 @@ Simple.args = {
|
|||||||
Use: "Flushing",
|
Use: "Flushing",
|
||||||
},
|
},
|
||||||
metadata: {
|
metadata: {
|
||||||
id: "random",
|
id:
|
||||||
|
"random" + String(Date.now()) + String(Date.now()) + String(Date.now()),
|
||||||
alias: "Random",
|
alias: "Random",
|
||||||
description: "Example Metadata",
|
description: "Example Metadata",
|
||||||
trigger_variables: {
|
trigger_variables: {
|
||||||
|
|||||||
@@ -1,33 +1,54 @@
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import Icon from "@mui/material/Icon";
|
import "./index.mobile.css";
|
||||||
import { CheckMarkIcon } from "components/Icons";
|
|
||||||
import { FC, useState } from "react";
|
import { FC, useState } from "react";
|
||||||
import { AutomationData } from "types/automations";
|
import { useCookies } from "react-cookie";
|
||||||
import { AutoInfoBox } from "./AutoInfoBox";
|
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
|
||||||
import { Button } from "components/Inputs/Button";
|
|
||||||
import { useAutomatioEditorState, EditorData } from "./state";
|
|
||||||
import { MiniFailure } from "types/validators/helper";
|
|
||||||
import InputYaml from "components/Inputs/InputYaml";
|
|
||||||
import { TagDB } from "components/AutomationList/TagDB";
|
|
||||||
import Skeleton from "@mui/material/Skeleton";
|
import Skeleton from "@mui/material/Skeleton";
|
||||||
import LinearProgress from "@mui/material/LinearProgress";
|
import LinearProgress from "@mui/material/LinearProgress";
|
||||||
import { ArrowBack } from "@mui/icons-material";
|
import SpeedDial from "@mui/material/SpeedDial";
|
||||||
import { useCookies } from "react-cookie";
|
import SpeedDialAction from "@mui/material/SpeedDialAction";
|
||||||
|
|
||||||
|
import SpeedDialIcon from "@mui/icons-material/SettingsRounded";
|
||||||
|
import UndoIcon from "@mui/icons-material/UndoSharp";
|
||||||
|
import Icon from "@mui/material/Icon";
|
||||||
|
import EditIcon from "@mui/icons-material/ModeEditOutlineTwoTone";
|
||||||
|
import DeleteIcon from "@mui/icons-material/DeleteForever";
|
||||||
|
import { CheckMarkIcon } from "components/Icons";
|
||||||
|
import RunIcon from "@mui/icons-material/RunCircleOutlined";
|
||||||
|
|
||||||
|
import { Modal } from "components/Modal";
|
||||||
|
import { Button } from "components/Inputs/Buttons/Button";
|
||||||
|
import InputYaml from "components/Inputs/Base/InputYaml";
|
||||||
|
import { TagDB } from "components/AutomationManager/TagDB";
|
||||||
import { DAGDims } from "components/DAGGraph/elements/types";
|
import { DAGDims } from "components/DAGGraph/elements/types";
|
||||||
import { DAGAutomationGraph } from "components/DAGGraph";
|
import { DAGAutomationGraph } from "components/DAGGraph";
|
||||||
|
import { InputList } from "components/Inputs/InputList";
|
||||||
|
import { InputTextView } from "components/Inputs/InputTextView";
|
||||||
|
|
||||||
|
import { AutomationData } from "types/automations";
|
||||||
|
import { MiniFailure } from "types/validators/helper";
|
||||||
|
|
||||||
|
import { AutoInfoBox } from "./AutoInfoBox";
|
||||||
|
import { useAutomatioEditorState, EditorData } from "./state";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
automation?: AutomationData;
|
automation?: AutomationData;
|
||||||
dims: DAGDims;
|
dims: DAGDims;
|
||||||
onUpdate: (auto: AutomationData) => void;
|
onUpdate: (auto: AutomationData) => void;
|
||||||
|
onTrigger: () => void;
|
||||||
|
onDelete: () => void;
|
||||||
tagDB: TagDB;
|
tagDB: TagDB;
|
||||||
|
isNew?: boolean;
|
||||||
}
|
}
|
||||||
export const AutomationEditor: FC<Props> = ({
|
export const AutomationEditor: FC<Props> = ({
|
||||||
dims,
|
dims,
|
||||||
automation: propsAutos,
|
automation: propsAutos,
|
||||||
onUpdate: propsOnUpdate,
|
onUpdate: propsOnUpdate,
|
||||||
|
onDelete,
|
||||||
|
onTrigger,
|
||||||
tagDB,
|
tagDB,
|
||||||
|
isNew,
|
||||||
}) => {
|
}) => {
|
||||||
// state
|
// state
|
||||||
const {
|
const {
|
||||||
@@ -39,8 +60,9 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
validate,
|
validate,
|
||||||
save,
|
save,
|
||||||
saveAndUpdate,
|
saveAndUpdate,
|
||||||
|
undo,
|
||||||
} = useAutomatioEditorState(propsAutos, propsOnUpdate);
|
} = useAutomatioEditorState(propsAutos, propsOnUpdate);
|
||||||
const [closeInfo, setCloseInfo] = useState(false);
|
const [infoBoxOpen, setInfoBox] = useState(false);
|
||||||
const [
|
const [
|
||||||
{ ckFlipped },
|
{ ckFlipped },
|
||||||
setCookies,
|
setCookies,
|
||||||
@@ -71,30 +93,111 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="automation-editor">
|
<div className={["automation-editor", state.status].join(" ")}>
|
||||||
{state.status === "saving" && (
|
{state.status === "saving" && (
|
||||||
<LinearProgress className="linear-loader" />
|
<LinearProgress className="linear-loader" />
|
||||||
)}
|
)}
|
||||||
<AutoInfoBox
|
<Modal open={infoBoxOpen}>
|
||||||
className={closeInfo ? "hide" : "show"}
|
<AutoInfoBox
|
||||||
metadata={state.data.metadata}
|
metadata={state.data.metadata}
|
||||||
tags={state.data.tags}
|
tags={state.data.tags}
|
||||||
onUpdate={updateMetadata}
|
onUpdate={updateMetadata}
|
||||||
tagDB={tagDB}
|
tagDB={tagDB}
|
||||||
>
|
>
|
||||||
<ButtonIcon
|
<div
|
||||||
className="automation-editor--info-box--icon"
|
className={[
|
||||||
onClick={() => setCloseInfo(!closeInfo)}
|
"automation-editor--info-box--buttons",
|
||||||
title={closeInfo ? "Show Metadata" : "Hide Metadata"}
|
state.status,
|
||||||
color="success"
|
].join(" ")}
|
||||||
icon={<ArrowBack />}
|
>
|
||||||
/>
|
<Button onClick={() => setInfoBox(false)}>Close</Button>
|
||||||
</AutoInfoBox>
|
<Button
|
||||||
|
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
||||||
|
onClick={save}
|
||||||
|
disabled={state.status !== "changed"}
|
||||||
|
>
|
||||||
|
Save <CheckMarkIcon color="#bf4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</AutoInfoBox>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className={["automation-editor--flow-wrapper", state.status].join(" ")}
|
className={["automation-editor--flow-wrapper", state.status].join(" ")}
|
||||||
>
|
>
|
||||||
<div className="automation-editor--flow-wrapper--toolbar">
|
<div className="automation-editor--flow-wrapper--toolbar">
|
||||||
|
<div className="automation-editor--flow-wrapper--toolbar--title">
|
||||||
|
<span className="automation-editor--flow-wrapper--toolbar--title--text">
|
||||||
|
<div className="id">{state.data.metadata.id}</div>
|
||||||
|
<InputTextView
|
||||||
|
value={state.data.metadata.alias ?? ""}
|
||||||
|
placeholder="Name"
|
||||||
|
onChange={(alias) =>
|
||||||
|
updateMetadata(
|
||||||
|
{
|
||||||
|
...state.data.metadata,
|
||||||
|
alias,
|
||||||
|
},
|
||||||
|
state.data.tags
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
<InputList
|
||||||
|
fullWidth={false}
|
||||||
|
label="Mode"
|
||||||
|
className="automation-editor--flow-wrapper--toolbar--modes"
|
||||||
|
current={{
|
||||||
|
id: state.data.metadata.mode,
|
||||||
|
label: "",
|
||||||
|
}}
|
||||||
|
onChange={({ id }) =>
|
||||||
|
updateMetadata(
|
||||||
|
{
|
||||||
|
...state.data.metadata,
|
||||||
|
mode: id,
|
||||||
|
},
|
||||||
|
state.data.tags
|
||||||
|
)
|
||||||
|
}
|
||||||
|
getKey={({ id }) => id}
|
||||||
|
getDescription={({ label }) => label}
|
||||||
|
options={[
|
||||||
|
{
|
||||||
|
id: "single",
|
||||||
|
label: "Do not start a new run. Issue a warning.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "parallel",
|
||||||
|
label:
|
||||||
|
"Start a new, independent run in parallel with previous runs.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "queued",
|
||||||
|
label:
|
||||||
|
"Start a new run after all previous runs complete. Runs are guaranteed to execute in the order they were queued.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "restart",
|
||||||
|
label: "Start a new run after first stopping previous run.",
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<InputTextView
|
||||||
|
className="description"
|
||||||
|
value={state.data.metadata.description ?? ""}
|
||||||
|
placeholder="Description"
|
||||||
|
onChange={(description) =>
|
||||||
|
updateMetadata(
|
||||||
|
{
|
||||||
|
...state.data.metadata,
|
||||||
|
description,
|
||||||
|
},
|
||||||
|
state.data.tags
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{!dims.flipped && (
|
{!dims.flipped && (
|
||||||
<Button
|
<Button
|
||||||
className={"automation-editor--flow-wrapper--toolbar--flip-btn"}
|
className={"automation-editor--flow-wrapper--toolbar--flip-btn"}
|
||||||
@@ -104,10 +207,15 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
Flip
|
Flip
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
{state.status === "changed" && (
|
||||||
|
<Button onClick={undo}>
|
||||||
|
<UndoIcon />
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
className={"automation-editor--flow-wrapper--toolbar--save-btn"}
|
||||||
onClick={save}
|
onClick={save}
|
||||||
disabled={state.status !== "changed"}
|
disabled={state.status !== "changed" && !isNew}
|
||||||
>
|
>
|
||||||
Save <CheckMarkIcon color="#bf4" />
|
Save <CheckMarkIcon color="#bf4" />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -121,6 +229,38 @@ export const AutomationEditor: FC<Props> = ({
|
|||||||
onConditionUpdate={updateCondition}
|
onConditionUpdate={updateCondition}
|
||||||
isFlipped={flipped}
|
isFlipped={flipped}
|
||||||
/>
|
/>
|
||||||
|
<SpeedDial
|
||||||
|
ariaLabel="options label"
|
||||||
|
sx={{ position: "absolute", bottom: 16, right: 16 }}
|
||||||
|
icon={<SpeedDialIcon />}
|
||||||
|
>
|
||||||
|
<SpeedDialAction
|
||||||
|
tooltipOpen
|
||||||
|
icon={<RunIcon />}
|
||||||
|
tooltipTitle={"Trigger"}
|
||||||
|
onClick={onTrigger}
|
||||||
|
/>
|
||||||
|
<SpeedDialAction
|
||||||
|
tooltipOpen
|
||||||
|
icon={<DeleteIcon />}
|
||||||
|
tooltipTitle={"Delete"}
|
||||||
|
onClick={onDelete}
|
||||||
|
/>
|
||||||
|
<SpeedDialAction
|
||||||
|
tooltipOpen
|
||||||
|
icon={<EditIcon />}
|
||||||
|
tooltipTitle={"Metadata"}
|
||||||
|
onClick={() => setInfoBox(!infoBoxOpen)}
|
||||||
|
/>
|
||||||
|
{state.status === "changed" && (
|
||||||
|
<SpeedDialAction
|
||||||
|
tooltipOpen
|
||||||
|
icon={<UndoIcon />}
|
||||||
|
tooltipTitle={"Undo"}
|
||||||
|
onClick={undo}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</SpeedDial>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,117 +1,156 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from "react";
|
||||||
import { AutomationData, AutomationMetadata } from "types/automations";
|
import { AutomationData, AutomationMetadata } from "types/automations";
|
||||||
import * as v from "types/validators/autmation";
|
import * as v from "types/validators/autmation";
|
||||||
import { getFailures } from "types/validators/helper";
|
import { getFailures } from "types/validators/helper";
|
||||||
import { MiniFailure } from '../../types/validators/helper';
|
import { MiniFailure } from "../../types/validators/helper";
|
||||||
|
|
||||||
export type EditorData = ReturnType<typeof genEditorData>;
|
export type EditorData = ReturnType<typeof genEditorData>;
|
||||||
export type EditorState = {
|
export type EditorState =
|
||||||
status: 'unchanged' | 'changed' | 'saving',
|
| {
|
||||||
data: EditorData
|
status: "unchanged";
|
||||||
} | {
|
data: EditorData;
|
||||||
status: 'loading'
|
}
|
||||||
} | {
|
| {
|
||||||
status: 'invalid',
|
status: "changed" | "saving";
|
||||||
failures: MiniFailure[],
|
previous: EditorData[];
|
||||||
data: EditorData,
|
data: EditorData;
|
||||||
}
|
}
|
||||||
export type EditorStatus = EditorState['status'];
|
| {
|
||||||
|
status: "loading";
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
status: "invalid";
|
||||||
|
failures: MiniFailure[];
|
||||||
|
data: EditorData;
|
||||||
|
};
|
||||||
|
export type EditorStatus = EditorState["status"];
|
||||||
|
|
||||||
export const useAutomatioEditorState = (
|
export const useAutomatioEditorState = (
|
||||||
automation: AutomationData | undefined,
|
automation: AutomationData | undefined,
|
||||||
onSave: (a: AutomationData) => void,
|
onSave: (a: AutomationData) => void
|
||||||
) => {
|
) => {
|
||||||
const [state, update] = useState<EditorState>({
|
const [state, update] = useState<EditorState>({
|
||||||
status: "loading",
|
status: "loading",
|
||||||
});
|
});
|
||||||
const makeUpdate = <K extends keyof EditorData, D extends EditorData[K]>(name: K) => (
|
const makeUpdate =
|
||||||
data: D
|
<K extends keyof EditorData, D extends EditorData[K]>(name: K) =>
|
||||||
) => ((state.status === 'changed') || (state.status === 'unchanged')) && update({
|
(data: D) =>
|
||||||
status: 'changed',
|
(state.status === "changed" || state.status === "unchanged") &&
|
||||||
|
update({
|
||||||
|
status: "changed",
|
||||||
|
previous:
|
||||||
|
state.status === "unchanged"
|
||||||
|
? [state.data]
|
||||||
|
: state.previous.concat([state.data]),
|
||||||
data: {
|
data: {
|
||||||
...state.data,
|
...state.data,
|
||||||
[name]: data,
|
[name]: data,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
const saveAndUpdate = (data: EditorData) => {
|
const saveAndUpdate = (data: EditorData) => {
|
||||||
const cleanData = {
|
if (state.status === "changed") {
|
||||||
...data,
|
const cleanData = {
|
||||||
tags: data.tags.reduce((all, [tagName, tagValue]) => ({
|
...data,
|
||||||
...all,
|
tags: data.tags.reduce(
|
||||||
[tagName.trim()]: tagValue.trim(),
|
(all, [tagName, tagValue]) => ({
|
||||||
}), {})
|
...all,
|
||||||
};
|
[tagName.trim()]: tagValue.trim(),
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
),
|
||||||
|
};
|
||||||
|
update({
|
||||||
|
status: "saving",
|
||||||
|
previous: state.previous,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
onSave(cleanData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (automation) {
|
||||||
|
const failures = getFailures(automation, v.AutomationData);
|
||||||
|
if (failures) {
|
||||||
update({
|
update({
|
||||||
status: "saving",
|
status: "invalid",
|
||||||
data,
|
failures,
|
||||||
})
|
data: genEditorData(automation),
|
||||||
onSave(cleanData);
|
});
|
||||||
|
} else {
|
||||||
|
update({
|
||||||
|
status: "unchanged",
|
||||||
|
data: genEditorData(automation),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}, [automation]);
|
||||||
|
|
||||||
useEffect(() => {
|
return {
|
||||||
if (automation) {
|
validate: (data: any) => getFailures(data, v.AutomationData),
|
||||||
const failures = getFailures(automation, v.AutomationData);
|
updateTrigger: makeUpdate("trigger"),
|
||||||
if (failures) {
|
updateSequence: makeUpdate("sequence"),
|
||||||
update({
|
updateCondition: makeUpdate("condition"),
|
||||||
status: 'invalid',
|
saveAndUpdate,
|
||||||
failures,
|
updateMetadata: (
|
||||||
data: genEditorData(automation),
|
metadata: AutomationMetadata,
|
||||||
})
|
tags: Array<[string, string]>
|
||||||
} else {
|
) => {
|
||||||
update({
|
if (state.status === "changed" || state.status === "unchanged") {
|
||||||
status: 'unchanged',
|
update({
|
||||||
data: genEditorData(automation),
|
status: "changed",
|
||||||
})
|
previous:
|
||||||
}
|
state.status === "changed"
|
||||||
|
? state.previous.concat([state.data])
|
||||||
|
: [state.data],
|
||||||
|
data: {
|
||||||
|
...state.data,
|
||||||
|
tags,
|
||||||
|
metadata,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
save: () => {
|
||||||
|
if (state.status !== "loading") {
|
||||||
|
saveAndUpdate(state.data);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
undo: () => {
|
||||||
|
if (state.status === "changed") {
|
||||||
|
if (state.previous.length === 1) {
|
||||||
|
update({
|
||||||
|
status: "unchanged",
|
||||||
|
data: state.previous[0],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
update({
|
||||||
|
status: "changed",
|
||||||
|
data: state.previous[state.previous.length - 1],
|
||||||
|
previous: state.previous.slice(0, state.previous.length - 1),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [automation]);
|
}
|
||||||
|
},
|
||||||
return {
|
get state() {
|
||||||
validate: (data: any) => getFailures(data, v.AutomationData),
|
return state;
|
||||||
updateTrigger: makeUpdate('trigger'),
|
},
|
||||||
updateSequence: makeUpdate('sequence'),
|
};
|
||||||
updateCondition: makeUpdate('condition'),
|
};
|
||||||
saveAndUpdate,
|
|
||||||
updateMetadata: (metadata: AutomationMetadata, tags: Array<[string, string]>) => {
|
|
||||||
if ((state.status === 'changed') || (state.status === 'unchanged')) {
|
|
||||||
update({
|
|
||||||
status: 'changed',
|
|
||||||
data: {
|
|
||||||
...state.data,
|
|
||||||
tags,
|
|
||||||
metadata,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
save: () => {
|
|
||||||
if (state.status !== 'loading') {
|
|
||||||
saveAndUpdate(state.data)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
get state() {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const genEditorData = (automation: AutomationData) => {
|
const genEditorData = (automation: AutomationData) => {
|
||||||
const {
|
const { metadata, trigger, sequence, condition } = automation;
|
||||||
metadata,
|
|
||||||
trigger,
|
|
||||||
sequence,
|
|
||||||
condition,
|
|
||||||
} = automation;
|
|
||||||
|
|
||||||
const tags: [string, string][] = Object.keys(automation.tags).map(tagName => [tagName, automation.tags[tagName]]);
|
const tags: [string, string][] = Object.keys(automation.tags).map(
|
||||||
|
(tagName) => [tagName, automation.tags[tagName]]
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
metadata,
|
metadata,
|
||||||
trigger,
|
trigger,
|
||||||
sequence,
|
sequence,
|
||||||
condition,
|
condition,
|
||||||
tags,
|
tags,
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
@@ -1,187 +0,0 @@
|
|||||||
import "styles/root.css";
|
|
||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { AutomationList } from ".";
|
|
||||||
import { bigMockAutoList } from "utils/mocks";
|
|
||||||
import { Page } from "components/Page";
|
|
||||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
|
||||||
import { AutomationData } from "types/automations";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
title: "App/AutomationList",
|
|
||||||
component: AutomationList,
|
|
||||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
|
||||||
args: {
|
|
||||||
dims: DEFAULT_DIMS,
|
|
||||||
},
|
|
||||||
} as ComponentMeta<typeof AutomationList>;
|
|
||||||
|
|
||||||
const Template: ComponentStory<typeof AutomationList> = (args) => {
|
|
||||||
const [autos, setAutos] = useState(args.automations.data);
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<AutomationList
|
|
||||||
{...args}
|
|
||||||
automations={{
|
|
||||||
...args.automations,
|
|
||||||
data: autos,
|
|
||||||
}}
|
|
||||||
onAdd={(a) => {
|
|
||||||
args.onAdd(a);
|
|
||||||
setAutos([...autos, a]);
|
|
||||||
}}
|
|
||||||
onRemove={(i) => {
|
|
||||||
args.onRemove(i);
|
|
||||||
setAutos([...autos.slice(0, i), ...autos.slice(i + 1)]);
|
|
||||||
}}
|
|
||||||
onUpdate={(i, a) => {
|
|
||||||
args.onUpdate(i, a);
|
|
||||||
setAutos([...autos.slice(0, i), a, ...autos.slice(i + 1)]);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Page>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const make = (autos: AutomationData[]) => {
|
|
||||||
const NewTemp = Template.bind({});
|
|
||||||
NewTemp.args = {
|
|
||||||
...NewTemp.args,
|
|
||||||
automations: {
|
|
||||||
data: autos,
|
|
||||||
params: {
|
|
||||||
offset: 0,
|
|
||||||
limit: 100,
|
|
||||||
},
|
|
||||||
totalItems: autos.length,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return NewTemp;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const EmptyStart = make([]);
|
|
||||||
|
|
||||||
export const FewAutos = make(bigMockAutoList);
|
|
||||||
|
|
||||||
export const BadAutmations = make([
|
|
||||||
{
|
|
||||||
metadata: {
|
|
||||||
alias: "Set Thermostat to 76 at 8am",
|
|
||||||
description: "",
|
|
||||||
mode: "single",
|
|
||||||
} as any,
|
|
||||||
trigger: [
|
|
||||||
{
|
|
||||||
at: "08:00:00",
|
|
||||||
platform: "time",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
condition: [
|
|
||||||
{
|
|
||||||
condition: "state",
|
|
||||||
entity_id: "climate.thermostat",
|
|
||||||
state: "cool",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
sequence: [
|
|
||||||
{
|
|
||||||
data: {
|
|
||||||
temperature: 76,
|
|
||||||
},
|
|
||||||
service: "climate.set_temperature",
|
|
||||||
target: {
|
|
||||||
entity_id: "climate.thermostat",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
tags: {},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
condition: [],
|
|
||||||
tags: {},
|
|
||||||
metadata: {
|
|
||||||
id: "Bad Choose Sequence",
|
|
||||||
alias: "Bad Choose",
|
|
||||||
description: "Example Metadata",
|
|
||||||
trigger_variables: {
|
|
||||||
wowo: "!",
|
|
||||||
},
|
|
||||||
mode: "single",
|
|
||||||
},
|
|
||||||
trigger: [],
|
|
||||||
sequence: [
|
|
||||||
{
|
|
||||||
choose: {},
|
|
||||||
},
|
|
||||||
] as any,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
condition: [],
|
|
||||||
tags: {},
|
|
||||||
metadata: {
|
|
||||||
id: "random",
|
|
||||||
alias: "Bad Trigger",
|
|
||||||
description: "Example Metadata",
|
|
||||||
trigger_variables: {
|
|
||||||
wowo: "!",
|
|
||||||
},
|
|
||||||
mode: "single",
|
|
||||||
},
|
|
||||||
trigger: ["haha I am a string"] as any,
|
|
||||||
sequence: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
condition: [],
|
|
||||||
tags: {},
|
|
||||||
metadata: {} as any,
|
|
||||||
trigger: [],
|
|
||||||
sequence: [],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const FewAutosWithSlowLoader: ComponentStory<typeof AutomationList> = (
|
|
||||||
args
|
|
||||||
) => {
|
|
||||||
const [autos, setAutos] = useState(args.automations.data);
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<AutomationList
|
|
||||||
{...args}
|
|
||||||
automations={{
|
|
||||||
...args.automations,
|
|
||||||
data: autos,
|
|
||||||
}}
|
|
||||||
onAdd={(a) => {
|
|
||||||
window.setTimeout(() => {
|
|
||||||
args.onAdd(a);
|
|
||||||
setAutos([...autos, a]);
|
|
||||||
}, 10000);
|
|
||||||
}}
|
|
||||||
onRemove={(i) => {
|
|
||||||
window.setTimeout(() => {
|
|
||||||
args.onRemove(i);
|
|
||||||
setAutos([...autos.slice(0, i), ...autos.slice(i + 1)]);
|
|
||||||
}, 10000);
|
|
||||||
}}
|
|
||||||
onUpdate={(i, a) => {
|
|
||||||
window.setTimeout(() => {
|
|
||||||
args.onUpdate(i, a);
|
|
||||||
setAutos([...autos.slice(0, i), a, ...autos.slice(i + 1)]);
|
|
||||||
}, 10000);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Page>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
FewAutosWithSlowLoader.args = {
|
|
||||||
...FewAutosWithSlowLoader.args,
|
|
||||||
automations: {
|
|
||||||
data: bigMockAutoList,
|
|
||||||
params: {
|
|
||||||
limit: 100,
|
|
||||||
offset: 0,
|
|
||||||
},
|
|
||||||
totalItems: 100,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
.automation-list-box {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body {
|
|
||||||
overflow-y: auto;
|
|
||||||
overflow-x: hidden;
|
|
||||||
height: 100%;
|
|
||||||
flex: 1;
|
|
||||||
user-select: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body>* {
|
|
||||||
padding-top: 0.5em;
|
|
||||||
padding-bottom: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--group {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding-left: 1em;
|
|
||||||
border-radius: 10px;
|
|
||||||
padding-bottom: 0.5em;
|
|
||||||
border-width: 1px;
|
|
||||||
border-bottom-style: solid;
|
|
||||||
border-color: var(--mui-grey-400);
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--group.other {
|
|
||||||
border-color: var(--mui-success-main);
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--group.other>b {
|
|
||||||
color: var(--mui-success-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--group>.automation-list-box--body--group {
|
|
||||||
border-left-style: solid;
|
|
||||||
border-top-left-radius: 0;
|
|
||||||
margin-left: 0.75em;
|
|
||||||
padding-left: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--group>b {
|
|
||||||
width: 100%;
|
|
||||||
cursor: pointer;
|
|
||||||
padding: 0.1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--group>b:hover,
|
|
||||||
.automation-list-box--body--group.selected>b {
|
|
||||||
background-color: var(--mui-grey-700);
|
|
||||||
color: var(--mui-secondary-contrastText);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.automation-list-box--bottom {
|
|
||||||
margin-top: 0.5em;
|
|
||||||
margin-bottom: 0.5em;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: space-around;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--bottom>.automation-list-box--bottom--add {
|
|
||||||
background-color: var(--mui-primary-main);
|
|
||||||
color: var(--mui-primary-contrastText);
|
|
||||||
padding: 0.5em 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--bottom>.automation-list-box--bottom--add:hover {
|
|
||||||
color: var(--mui-primary-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--bottom--load svg {
|
|
||||||
color: var(--mui-primary-main);
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--bottom--load.less svg {
|
|
||||||
transform: rotate(180deg);
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { AutomationListBox } from "./AutomationListBox";
|
|
||||||
import { createMockAuto } from "utils/mocks";
|
|
||||||
import { Page } from "components/Page";
|
|
||||||
import { CookiesProvider } from "react-cookie";
|
|
||||||
import { makeTagDB } from "./TagDB";
|
|
||||||
import { AutomationData } from "types/automations";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
title: "App/AutomationList/Box",
|
|
||||||
component: AutomationListBox,
|
|
||||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
|
||||||
args: {},
|
|
||||||
} as ComponentMeta<typeof AutomationListBox>;
|
|
||||||
|
|
||||||
const Template: ComponentStory<typeof AutomationListBox> = (args) => {
|
|
||||||
const [selected, setSelected] = useState(args.selected);
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<CookiesProvider>
|
|
||||||
<AutomationListBox
|
|
||||||
{...args}
|
|
||||||
tagsDB={makeTagDB(args.automations.data)}
|
|
||||||
automations={args.automations}
|
|
||||||
selected={selected}
|
|
||||||
onSelectAutomation={(i) => {
|
|
||||||
setSelected(i);
|
|
||||||
args.onSelectAutomation(i);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</CookiesProvider>
|
|
||||||
</Page>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const make = (autos: AutomationData[]) => {
|
|
||||||
const NewTemp = Template.bind({});
|
|
||||||
NewTemp.args = {
|
|
||||||
...NewTemp.args,
|
|
||||||
automations: {
|
|
||||||
data: autos,
|
|
||||||
params: {
|
|
||||||
offset: 0,
|
|
||||||
limit: 100,
|
|
||||||
},
|
|
||||||
totalItems: autos.length,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return NewTemp;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const EmptyStart = make([]);
|
|
||||||
|
|
||||||
export const FewAutos = make([
|
|
||||||
createMockAuto({
|
|
||||||
Room: "Bathroom",
|
|
||||||
Type: "Lights",
|
|
||||||
NewDevice: "Yes",
|
|
||||||
Remote: "No",
|
|
||||||
Floor: "1",
|
|
||||||
}),
|
|
||||||
createMockAuto({ Room: "Bathroom", Type: "Climate" }),
|
|
||||||
createMockAuto({ Room: "Living Room", Type: "Climate" }),
|
|
||||||
createMockAuto({ Type: "Climate" }),
|
|
||||||
createMockAuto({ Type: "Lights", Routine: "Myself" }),
|
|
||||||
createMockAuto({ Routine: "DNS", Type: "SSL" }),
|
|
||||||
createMockAuto({ Room: "Bedroom", Type: "Lights", Routine: "Baby" }),
|
|
||||||
createMockAuto({ Room: "Office", Type: "Lights" }),
|
|
||||||
createMockAuto({ Room: "Office" }),
|
|
||||||
createMockAuto(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const OneAuto = make([
|
|
||||||
createMockAuto({
|
|
||||||
Type: "Climate",
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import { getTagList } from "./AutomationListBox";
|
|
||||||
import { createMockAuto } from "utils/mocks";
|
|
||||||
|
|
||||||
test("getTagList", () => {
|
|
||||||
expect(
|
|
||||||
getTagList([
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
])
|
|
||||||
).toStrictEqual([]);
|
|
||||||
|
|
||||||
expect(
|
|
||||||
getTagList([
|
|
||||||
createMockAuto({ Room: "Kitchen", Area: "Oven" }),
|
|
||||||
createMockAuto({ Room: "Attic" }),
|
|
||||||
createMockAuto({ Room: "Office" }),
|
|
||||||
createMockAuto({ Area: "Balcony" }),
|
|
||||||
])
|
|
||||||
).toStrictEqual(["Room", "Area"]);
|
|
||||||
});
|
|
||||||
@@ -1,193 +0,0 @@
|
|||||||
import "./AutomationListBox.css";
|
|
||||||
import { FC, useState } from "react";
|
|
||||||
import { AutomationData } from "types/automations";
|
|
||||||
import InputMultiSelect from "components/Inputs/InputMultiSelect";
|
|
||||||
import InputText from "components/Inputs/InputText";
|
|
||||||
import { Button } from "components/Inputs/Button";
|
|
||||||
import { makeGrouping } from "./automationGrouper";
|
|
||||||
import { AutomationListBoxGroup } from "./AutomationListBoxGroup";
|
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
import { TagDB } from "components/AutomationList/TagDB";
|
|
||||||
// import { ButtonIcon } from "components/Icons/ButtonIcons";
|
|
||||||
// import ReadMoreOutlinedIcon from "@mui/icons-material/ReadMoreOutlined";
|
|
||||||
import { ListData, ListParams } from "apiService/types";
|
|
||||||
import Chip from "@mui/material/Chip";
|
|
||||||
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
|
||||||
|
|
||||||
export type AutomationListBoxProps = {
|
|
||||||
automations: ListData<AutomationData>;
|
|
||||||
selected: number;
|
|
||||||
onSelectAutomation: (i: number) => void;
|
|
||||||
onRemove: (i: number) => void;
|
|
||||||
onAdd: () => void;
|
|
||||||
onUpdate: (a: AutomationData, i: number) => void;
|
|
||||||
onLoadMore: (p: ListParams) => void;
|
|
||||||
tagsDB: TagDB;
|
|
||||||
};
|
|
||||||
|
|
||||||
const useAutomationListBoxState = () => {
|
|
||||||
const [
|
|
||||||
cookies,
|
|
||||||
setCookies,
|
|
||||||
// eslint-disable-next-line
|
|
||||||
_,
|
|
||||||
] = useCookies(["albSearchText", "albSelected"]);
|
|
||||||
let initialSelected = [];
|
|
||||||
try {
|
|
||||||
initialSelected = JSON.parse(cookies.albSelected);
|
|
||||||
if (!Array.isArray(initialSelected)) {
|
|
||||||
initialSelected = [initialSelected];
|
|
||||||
}
|
|
||||||
initialSelected = initialSelected.map(Number);
|
|
||||||
// eslint-disable-next-line
|
|
||||||
} catch (_) {}
|
|
||||||
const [searchText, setSearchText] = useState(cookies.albSearchText ?? "");
|
|
||||||
const [selectedTagIdx, setSelectedTagIdx] =
|
|
||||||
useState<number[]>(initialSelected);
|
|
||||||
|
|
||||||
return {
|
|
||||||
searchText,
|
|
||||||
setSearchText(v: string) {
|
|
||||||
setSearchText(v);
|
|
||||||
setCookies("albSearchText", v);
|
|
||||||
},
|
|
||||||
setSelectedTagIdx(n: number[]) {
|
|
||||||
setSelectedTagIdx(n);
|
|
||||||
setCookies("albSelected", JSON.stringify(n));
|
|
||||||
},
|
|
||||||
selectedTagIdx,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const AutomationListBox: FC<AutomationListBoxProps> = ({
|
|
||||||
automations: {
|
|
||||||
data: automations,
|
|
||||||
params: autoParams,
|
|
||||||
totalItems: totalAutomations,
|
|
||||||
},
|
|
||||||
selected,
|
|
||||||
onSelectAutomation,
|
|
||||||
onAdd,
|
|
||||||
onRemove,
|
|
||||||
onLoadMore,
|
|
||||||
tagsDB,
|
|
||||||
onUpdate,
|
|
||||||
}) => {
|
|
||||||
const tags = getTagList(automations);
|
|
||||||
const { searchText, setSearchText, selectedTagIdx, setSelectedTagIdx } =
|
|
||||||
useAutomationListBoxState();
|
|
||||||
const filteredAutomations = filterAutomations(
|
|
||||||
automations,
|
|
||||||
searchText.toLowerCase()
|
|
||||||
);
|
|
||||||
const grouping = makeGrouping(
|
|
||||||
filteredAutomations.map(([a, _]) => a),
|
|
||||||
selectedTagIdx.map((i) => tags[i]),
|
|
||||||
selected
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="automation-list-box">
|
|
||||||
<div className="automation-list-box--nav">
|
|
||||||
<InputText label="Search" value={searchText} onChange={setSearchText} />
|
|
||||||
<InputMultiSelect
|
|
||||||
label="Tags"
|
|
||||||
selected={selectedTagIdx}
|
|
||||||
onChange={setSelectedTagIdx}
|
|
||||||
options={tags}
|
|
||||||
max={3}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="automation-list-box--body">
|
|
||||||
<AutomationListBoxGroup
|
|
||||||
events={{
|
|
||||||
onSelectAutomation,
|
|
||||||
onRemove,
|
|
||||||
}}
|
|
||||||
autos={filteredAutomations}
|
|
||||||
grouping={grouping}
|
|
||||||
selectedAutomationIdx={selected}
|
|
||||||
tagsDB={tagsDB}
|
|
||||||
onSave={onUpdate}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="automation-list-box--bottom">
|
|
||||||
<Button className="automation-list-box--bottom--add" onClick={onAdd}>
|
|
||||||
Add
|
|
||||||
</Button>
|
|
||||||
{automations.length < totalAutomations ? (
|
|
||||||
<>
|
|
||||||
<Chip
|
|
||||||
label={`Only loaded ${automations.length} out of ${totalAutomations}`}
|
|
||||||
variant="outlined"
|
|
||||||
color="warning"
|
|
||||||
icon={<InfoOutlinedIcon />}
|
|
||||||
onClick={() =>
|
|
||||||
window.open(
|
|
||||||
"https://github.com/asosnovsky/Shortumation/issues/78",
|
|
||||||
"_blank"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<small>support for more is not yet implemented</small>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
""
|
|
||||||
)}
|
|
||||||
{/* {autoParams.offset > 0 && (
|
|
||||||
<ButtonIcon
|
|
||||||
borderless
|
|
||||||
className="automation-list-box--bottom--load less"
|
|
||||||
icon={<ReadMoreOutlinedIcon />}
|
|
||||||
onClick={() => onLoadMore()}
|
|
||||||
/>
|
|
||||||
)} */}
|
|
||||||
{/* {filteredAutomations.length} out of {totalAutomations} */}
|
|
||||||
{/* {autoParams.offset + automations.length < totalAutomations && (
|
|
||||||
<ButtonIcon
|
|
||||||
borderless
|
|
||||||
className="automation-list-box--bottom--load more"
|
|
||||||
icon={<ReadMoreOutlinedIcon />}
|
|
||||||
/>
|
|
||||||
)} */}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getTagList = (autos: AutomationData[]): string[] =>
|
|
||||||
Object.keys(
|
|
||||||
autos
|
|
||||||
.map((a) => Object.keys(a.tags))
|
|
||||||
.reduce((all: any, keys) => {
|
|
||||||
for (const k of keys) {
|
|
||||||
all[k] = 1;
|
|
||||||
}
|
|
||||||
return all;
|
|
||||||
}, {})
|
|
||||||
);
|
|
||||||
|
|
||||||
const filterAutomations = (
|
|
||||||
autos: AutomationData[],
|
|
||||||
searchText: string
|
|
||||||
): Array<[AutomationData, number]> =>
|
|
||||||
autos
|
|
||||||
.map<[AutomationData, number]>((a, i) => [a, i])
|
|
||||||
.filter(([a, i]) => {
|
|
||||||
if (!a.metadata) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (searchText.length > 0) {
|
|
||||||
if (
|
|
||||||
!(
|
|
||||||
(a.metadata.description ?? "")
|
|
||||||
.toLocaleLowerCase()
|
|
||||||
.includes(searchText) ||
|
|
||||||
(a.metadata.alias ?? "").toLocaleLowerCase().includes(searchText)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
.automation-list-box--body--item:hover, .automation-list-box--body--item.selected {
|
|
||||||
outline-color: var(--mui-grey-400);
|
|
||||||
outline-style: solid;
|
|
||||||
outline-width: 1px;
|
|
||||||
background-color: var(--mui-secondary-contrastText);
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item:hover>.automation-list-box--body--item--tags>span {
|
|
||||||
border-color: var(--mui-common-black);
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags--add:hover {
|
|
||||||
border-color: var(--mui-common-black);
|
|
||||||
color: var(--mui-grey-400);
|
|
||||||
background-color: var(--mui-secondary-contrastText);
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item {
|
|
||||||
padding-left: 1em;
|
|
||||||
cursor: pointer;
|
|
||||||
display: flex;
|
|
||||||
gap: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item::before {
|
|
||||||
content: "⊚ ";
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--buttons {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
height: 100%;
|
|
||||||
gap: 0.25em;
|
|
||||||
margin: 0.5em
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--buttons>button {
|
|
||||||
padding: 0.25em;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--buttons .save {
|
|
||||||
color: var(--mui-success-light)
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--buttons .save:hover {
|
|
||||||
color: var(--mui-success-main)
|
|
||||||
}
|
|
||||||
@@ -1,240 +0,0 @@
|
|||||||
import "./AutomationListBoxGroup.css";
|
|
||||||
|
|
||||||
import { TrashIcon } from "components/Icons";
|
|
||||||
import { MetadataBox } from "./AutomationMetadataBox";
|
|
||||||
import { AutomationData } from "types/automations";
|
|
||||||
import { AutomationGrouping } from "./automationGrouper";
|
|
||||||
import { FC, useEffect, useState } from "react";
|
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
|
||||||
import { TagDB } from "./TagDB";
|
|
||||||
import Save from "@mui/icons-material/Save";
|
|
||||||
|
|
||||||
export type AutomationListBoxEvents = {
|
|
||||||
onSelectAutomation: (i: number) => void;
|
|
||||||
onRemove: (i: number) => void;
|
|
||||||
};
|
|
||||||
export type AutomationListBoxGroups = {
|
|
||||||
grouping: AutomationGrouping;
|
|
||||||
currentNode: number;
|
|
||||||
};
|
|
||||||
export type AutomationListBoxProps = {
|
|
||||||
events: AutomationListBoxEvents;
|
|
||||||
groups: AutomationListBoxGroups;
|
|
||||||
autos: Array<[AutomationData, number]>;
|
|
||||||
selectedAutomationIdx: number;
|
|
||||||
};
|
|
||||||
export type AutomationListBoxGroupProps = {
|
|
||||||
events: AutomationListBoxEvents;
|
|
||||||
grouping: AutomationGrouping;
|
|
||||||
autos: Array<[AutomationData, number]>;
|
|
||||||
selectedAutomationIdx: number;
|
|
||||||
tagsDB: TagDB;
|
|
||||||
onSave: (a: AutomationData, i: number) => void;
|
|
||||||
};
|
|
||||||
export const AutomationListBoxGroup: FC<AutomationListBoxGroupProps> = ({
|
|
||||||
events,
|
|
||||||
grouping,
|
|
||||||
autos,
|
|
||||||
selectedAutomationIdx,
|
|
||||||
tagsDB,
|
|
||||||
onSave,
|
|
||||||
}) => {
|
|
||||||
if (grouping.top.length === 1) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{convertGroupsToItems(
|
|
||||||
autos,
|
|
||||||
{
|
|
||||||
grouping,
|
|
||||||
currentNode: grouping.top[0],
|
|
||||||
},
|
|
||||||
events,
|
|
||||||
selectedAutomationIdx,
|
|
||||||
tagsDB,
|
|
||||||
onSave
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{grouping.top.map((groupIdx) => (
|
|
||||||
<AutomationListBoxGroupItem
|
|
||||||
key={groupIdx}
|
|
||||||
autos={autos}
|
|
||||||
groups={{
|
|
||||||
grouping,
|
|
||||||
currentNode: groupIdx,
|
|
||||||
}}
|
|
||||||
events={events}
|
|
||||||
selectedAutomationIdx={selectedAutomationIdx}
|
|
||||||
tagsDB={tagsDB}
|
|
||||||
onSave={onSave}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const convertGroupsToItems = (
|
|
||||||
autos: Array<[AutomationData, number]>,
|
|
||||||
{ grouping, currentNode }: AutomationListBoxGroups,
|
|
||||||
events: AutomationListBoxEvents,
|
|
||||||
selectedAutomationIdx: number,
|
|
||||||
tagsDB: TagDB,
|
|
||||||
onSave: (a: AutomationData, i: number) => void
|
|
||||||
) => {
|
|
||||||
const automations = grouping.getAutomations(currentNode);
|
|
||||||
if (automations.length > 0) {
|
|
||||||
return automations.map((autoIndex) => (
|
|
||||||
<AutomationListBoxItem
|
|
||||||
key={`${autoIndex}-${autos[autoIndex][1]}`}
|
|
||||||
events={events}
|
|
||||||
auto={autos[autoIndex]}
|
|
||||||
isSelected={selectedAutomationIdx === autos[autoIndex][1]}
|
|
||||||
tagsDB={tagsDB}
|
|
||||||
onSave={(a) => onSave(a, autoIndex)}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
}
|
|
||||||
const subgroups = grouping.getSubGroups(currentNode);
|
|
||||||
if (subgroups.length > 0) {
|
|
||||||
return subgroups.map((groupIdx) => (
|
|
||||||
<AutomationListBoxGroupItem
|
|
||||||
key={groupIdx}
|
|
||||||
autos={autos}
|
|
||||||
groups={{
|
|
||||||
grouping,
|
|
||||||
currentNode: groupIdx,
|
|
||||||
}}
|
|
||||||
events={events}
|
|
||||||
selectedAutomationIdx={selectedAutomationIdx}
|
|
||||||
tagsDB={tagsDB}
|
|
||||||
onSave={onSave}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
}
|
|
||||||
return <></>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const AutomationListBoxGroupItem: FC<{
|
|
||||||
events: AutomationListBoxEvents;
|
|
||||||
groups: AutomationListBoxGroups;
|
|
||||||
autos: Array<[AutomationData, number]>;
|
|
||||||
selectedAutomationIdx: number;
|
|
||||||
tagsDB: TagDB;
|
|
||||||
onSave: (a: AutomationData, i: number) => void;
|
|
||||||
}> = ({ autos, groups, events, selectedAutomationIdx, tagsDB, onSave }) => {
|
|
||||||
const groupData = groups.grouping.getData(groups.currentNode);
|
|
||||||
const automations = groups.grouping.getAutomations(groups.currentNode);
|
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
const isOther = groupData.isOther;
|
|
||||||
const openIcon = !open ? "⊕" : "⊖";
|
|
||||||
const total = isOther ? (
|
|
||||||
<small>
|
|
||||||
{automations.length} automation{automations.length !== 1 ? "s" : ""}{" "}
|
|
||||||
{groupData.isOther ? "" : "(untagged)"}
|
|
||||||
</small>
|
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
);
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={[
|
|
||||||
"automation-list-box--body--group",
|
|
||||||
isOther ? "other" : "",
|
|
||||||
groupData.selected ? "selected" : "",
|
|
||||||
].join(" ")}
|
|
||||||
>
|
|
||||||
<b onClick={() => setOpen(!open)}>
|
|
||||||
{groupData.name} {openIcon} {total}
|
|
||||||
</b>
|
|
||||||
{open &&
|
|
||||||
convertGroupsToItems(
|
|
||||||
autos,
|
|
||||||
groups,
|
|
||||||
events,
|
|
||||||
selectedAutomationIdx,
|
|
||||||
tagsDB,
|
|
||||||
onSave
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const AutomationListBoxItem: FC<{
|
|
||||||
auto: [AutomationData, number];
|
|
||||||
isSelected: boolean;
|
|
||||||
events: AutomationListBoxEvents;
|
|
||||||
tagsDB: TagDB;
|
|
||||||
onSave: (a: AutomationData) => void;
|
|
||||||
}> = ({
|
|
||||||
events: { onRemove, onSelectAutomation },
|
|
||||||
auto: [auto, autoIndex],
|
|
||||||
isSelected,
|
|
||||||
tagsDB,
|
|
||||||
onSave,
|
|
||||||
}) => {
|
|
||||||
// state
|
|
||||||
const [{ tags, isModified }, setState] = useState({
|
|
||||||
isModified: false,
|
|
||||||
tags: Object.entries(auto.tags),
|
|
||||||
});
|
|
||||||
|
|
||||||
// effects
|
|
||||||
useEffect(() => {
|
|
||||||
setState({
|
|
||||||
isModified: false,
|
|
||||||
tags: Object.entries(auto.tags),
|
|
||||||
});
|
|
||||||
}, [auto]);
|
|
||||||
|
|
||||||
// alias
|
|
||||||
const setTags = (t: [string, string][]) =>
|
|
||||||
setState({
|
|
||||||
isModified: true,
|
|
||||||
tags: t,
|
|
||||||
});
|
|
||||||
// sub elements
|
|
||||||
let title = "BadAuto<<Missing Metadata>>";
|
|
||||||
if (auto.metadata) {
|
|
||||||
title = `Name = ${auto.metadata.alias}\nID = ${auto.metadata.id}\nDescription = ${auto.metadata.description}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// render
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
key={autoIndex}
|
|
||||||
className={[
|
|
||||||
"automation-list-box--body--item",
|
|
||||||
isSelected ? "selected" : "",
|
|
||||||
isModified ? "modded" : "",
|
|
||||||
].join(" ")}
|
|
||||||
title={title}
|
|
||||||
onClick={() => onSelectAutomation(autoIndex)}
|
|
||||||
>
|
|
||||||
<MetadataBox
|
|
||||||
metadata={auto.metadata}
|
|
||||||
tags={tags}
|
|
||||||
tagsDB={tagsDB}
|
|
||||||
onUpdate={setTags}
|
|
||||||
/>
|
|
||||||
<div className="automation-list-box--body--item--buttons">
|
|
||||||
{isModified && (
|
|
||||||
<ButtonIcon
|
|
||||||
className="save"
|
|
||||||
icon={<Save />}
|
|
||||||
onClick={() =>
|
|
||||||
onSave({
|
|
||||||
...auto,
|
|
||||||
tags: Object.fromEntries(tags),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<ButtonIcon onClick={() => onRemove(autoIndex)} icon={<TrashIcon />} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
.automation-list-box--body--item--title {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding-left: 0.25em;
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--title>b {
|
|
||||||
font-size: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--title>span, .automation-list-box--body--item--title>b>span {
|
|
||||||
font-size: 0.75em;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags {
|
|
||||||
flex: 1;
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
font-size: 0.75em;
|
|
||||||
justify-content: left;
|
|
||||||
align-items: flex-start;
|
|
||||||
overflow: auto;
|
|
||||||
max-height: 100%;
|
|
||||||
gap: 0.25em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags>span {
|
|
||||||
border-color: var(--mui-grey-400);
|
|
||||||
border-style: solid;
|
|
||||||
border-width: 1px;
|
|
||||||
border-radius: 0.5em;
|
|
||||||
padding: 0.1em 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags--item {
|
|
||||||
color: white;
|
|
||||||
border-color: white;
|
|
||||||
border-style: solid;
|
|
||||||
border-width: 1px;
|
|
||||||
border-radius: 0.5em;
|
|
||||||
padding: 0.1em 0.5em;
|
|
||||||
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
gap: 0.25em;
|
|
||||||
max-width: min-content;
|
|
||||||
align-items: center;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags--item>.text:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags--item>.text {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags--item>.text .MuiFilledInput-root {
|
|
||||||
padding: 0;
|
|
||||||
min-width: 6em;
|
|
||||||
max-width: 10em;
|
|
||||||
background-color: var(--mui-common-black);
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags--item>.text .icon {
|
|
||||||
position: absolute;
|
|
||||||
right: 0.5em;
|
|
||||||
top: 0.5em;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags--item>.text .icon:hover {
|
|
||||||
background-color: var(--mui-grey-400);
|
|
||||||
border-radius: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list-box--body--item--tags--item>.text .icon:hover svg {
|
|
||||||
fill: var(--mui-common-black);
|
|
||||||
}
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
import "./AutomationMetadataBox.css";
|
|
||||||
import { CheckMarkIcon } from "components/Icons";
|
|
||||||
import { FC, useState } from "react";
|
|
||||||
import { AutomationMetadata } from "types/automations";
|
|
||||||
import { InputAutoComplete } from "components/Inputs/InputAutoComplete";
|
|
||||||
import { TagDB } from "./TagDB";
|
|
||||||
|
|
||||||
export const MetadataBox: FC<{
|
|
||||||
metadata: AutomationMetadata;
|
|
||||||
onUpdate: (t: [string, string][]) => void;
|
|
||||||
tags: [string, string][];
|
|
||||||
tagsDB: TagDB;
|
|
||||||
}> = ({ tags, onUpdate, tagsDB, metadata }) => {
|
|
||||||
// state
|
|
||||||
const [newTag, setNewTag] = useState<
|
|
||||||
| {
|
|
||||||
on: false;
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
on: true;
|
|
||||||
name: string;
|
|
||||||
value: string;
|
|
||||||
}
|
|
||||||
>({ on: false });
|
|
||||||
// alias
|
|
||||||
const tagOptions = tagsDB.getTagNames(tags.map((t) => t[0]));
|
|
||||||
|
|
||||||
// render
|
|
||||||
let title = <span>{"BadAuto<<Missing Metadata>>"}</span>;
|
|
||||||
if (metadata) {
|
|
||||||
title = (
|
|
||||||
<>
|
|
||||||
<b>
|
|
||||||
{String(metadata.alias ?? "").slice(0, 15)}{" "}
|
|
||||||
<span>({String(metadata.id).slice(0, 5)})</span>
|
|
||||||
</b>
|
|
||||||
<span>{String(metadata.description ?? "").slice(0, 25)}</span>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div className="automation-list-box--body--item--title">
|
|
||||||
{title}
|
|
||||||
<div className="automation-list-box--body--item--tags">
|
|
||||||
{tags.map(([tagName, tagValue], tagIndex) => (
|
|
||||||
<MetadataBoxTag
|
|
||||||
options={[tagOptions, tagsDB.getTagValues(tagName)]}
|
|
||||||
key={tagIndex}
|
|
||||||
value={[tagName, tagValue]}
|
|
||||||
onChange={([newName, newValue]) =>
|
|
||||||
onUpdate([
|
|
||||||
...tags.slice(0, tagIndex),
|
|
||||||
[newName, newValue],
|
|
||||||
...tags.slice(tagIndex + 1),
|
|
||||||
])
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
{newTag.on && (
|
|
||||||
<MetadataBoxTag
|
|
||||||
options={[tagOptions, tagsDB.getTagValues(newTag.name)]}
|
|
||||||
key="new"
|
|
||||||
value={[newTag.name, newTag.value]}
|
|
||||||
initialState={[true, true]}
|
|
||||||
onChange={([name, value]) => {
|
|
||||||
if (name.trim() !== "" && value.trim() !== "") {
|
|
||||||
setNewTag({
|
|
||||||
on: false,
|
|
||||||
});
|
|
||||||
onUpdate([...tags, [name, value]]);
|
|
||||||
} else {
|
|
||||||
setNewTag({
|
|
||||||
on: true,
|
|
||||||
name,
|
|
||||||
value,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{!newTag.on && (
|
|
||||||
<span
|
|
||||||
className="automation-list-box--body--item--tags--add"
|
|
||||||
onClick={() =>
|
|
||||||
setNewTag({
|
|
||||||
on: true,
|
|
||||||
name: "",
|
|
||||||
value: "",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
+
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const MetadataBoxTag: FC<{
|
|
||||||
value: [string, string];
|
|
||||||
onChange: (t: [string, string]) => void;
|
|
||||||
options: [string[], string[]];
|
|
||||||
initialState?: [boolean, boolean];
|
|
||||||
}> = (props) => {
|
|
||||||
const [[editMode1, editMode2], setEditMode] = useState(
|
|
||||||
props.initialState ? props.initialState : [false, false]
|
|
||||||
);
|
|
||||||
const toggle1 = () => setEditMode([!editMode1, editMode2]);
|
|
||||||
const toggle2 = () => setEditMode([editMode1, !editMode2]);
|
|
||||||
return (
|
|
||||||
<span className="automation-list-box--body--item--tags--item">
|
|
||||||
{editMode1 ? (
|
|
||||||
<InputAutoComplete
|
|
||||||
multiple={false}
|
|
||||||
className="text"
|
|
||||||
disableChips
|
|
||||||
options={props.options[0]}
|
|
||||||
label=""
|
|
||||||
value={props.value[0]}
|
|
||||||
onEnter={toggle1}
|
|
||||||
onChange={(v) => props.onChange([v ?? "", props.value[1]])}
|
|
||||||
onlyShowLabel
|
|
||||||
endAdornment={<CheckMarkIcon className="icon" onClick={toggle1} />}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<b className="text" onClick={toggle1}>
|
|
||||||
{props.value[0]}:
|
|
||||||
</b>
|
|
||||||
)}
|
|
||||||
{editMode2 ? (
|
|
||||||
<InputAutoComplete
|
|
||||||
multiple={false}
|
|
||||||
className="text"
|
|
||||||
disableChips
|
|
||||||
options={props.options[1]}
|
|
||||||
label=""
|
|
||||||
value={props.value[1]}
|
|
||||||
onEnter={toggle2}
|
|
||||||
onChange={(v) => props.onChange([props.value[0], v ?? ""])}
|
|
||||||
onlyShowLabel
|
|
||||||
endAdornment={<CheckMarkIcon className="icon" onClick={toggle2} />}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<span className="text" onClick={toggle2}>
|
|
||||||
{props.value[1]}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|
||||||
import { Page } from "components/Page";
|
|
||||||
import { MetadataBoxTag } from "./AutomationMetadataBox";
|
|
||||||
import { useState } from "react";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
title: "App/AutomationList/Box",
|
|
||||||
component: MetadataBoxTag,
|
|
||||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
|
||||||
args: {
|
|
||||||
value: ["Type", "Climate"],
|
|
||||||
options: [[], []],
|
|
||||||
},
|
|
||||||
} as ComponentMeta<typeof MetadataBoxTag>;
|
|
||||||
|
|
||||||
export const BoxTag: ComponentStory<typeof MetadataBoxTag> = (args) => {
|
|
||||||
const [state, setState] = useState(args.value);
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<MetadataBoxTag
|
|
||||||
options={args.options}
|
|
||||||
value={state}
|
|
||||||
onChange={(v) => {
|
|
||||||
setState(v);
|
|
||||||
args.onChange(v);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Page>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|
||||||
import { ConnectedAutomationList } from ".";
|
|
||||||
import { createMockAuto } from "utils/mocks";
|
|
||||||
import { useMockApiService } from "apiService";
|
|
||||||
import { Page } from "components/Page";
|
|
||||||
import { DEFAULT_DIMS } from "components/DAGGraph/elements/constants";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
title: "App/AutomationList/MockConnected",
|
|
||||||
component: ConnectedAutomationList,
|
|
||||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
|
||||||
args: {
|
|
||||||
dims: DEFAULT_DIMS,
|
|
||||||
initialAutomations: [],
|
|
||||||
},
|
|
||||||
} as ComponentMeta<typeof ConnectedAutomationList>;
|
|
||||||
|
|
||||||
const Template: ComponentStory<any> = (args) => {
|
|
||||||
const api = useMockApiService(args.initialAutomations);
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<ConnectedAutomationList {...args} api={api} />
|
|
||||||
</Page>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const EmptyStart = Template.bind({});
|
|
||||||
|
|
||||||
export const FewAutos = Template.bind({});
|
|
||||||
FewAutos.args = {
|
|
||||||
...FewAutos.args,
|
|
||||||
initialAutomations: [
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
createMockAuto(),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Loading: ComponentStory<any> = (args) => {
|
|
||||||
const api = useMockApiService(args.initialAutomations);
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<ConnectedAutomationList
|
|
||||||
{...args}
|
|
||||||
api={{
|
|
||||||
...api,
|
|
||||||
state: {
|
|
||||||
automations: {
|
|
||||||
ready: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Page>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import { AutomationData } from "types/automations";
|
|
||||||
|
|
||||||
export type TagDB = ReturnType<typeof makeTagDB>;
|
|
||||||
export const makeTagDB = (automations: AutomationData[]) => {
|
|
||||||
const allTags: Record<string, Set<string>> = {};
|
|
||||||
automations.forEach(({ tags }) =>
|
|
||||||
Object.keys(tags).forEach((tagName) => {
|
|
||||||
const tagValue = tags[tagName];
|
|
||||||
if (!allTags[tagName]) {
|
|
||||||
allTags[tagName] = new Set();
|
|
||||||
}
|
|
||||||
allTags[tagName].add(tagValue);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const allTagNames = Object.keys(allTags);
|
|
||||||
return {
|
|
||||||
getTagNames(myTags: string[]): string[] {
|
|
||||||
return allTagNames.filter((n) => !myTags.includes(n)).sort();
|
|
||||||
},
|
|
||||||
getTagValues(tagName: string): string[] {
|
|
||||||
return allTags[tagName]
|
|
||||||
? Array.from(allTags[tagName].values()).sort()
|
|
||||||
: [];
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
import { makeGrouping } from "./automationGrouper";
|
|
||||||
import { AutomationData } from 'types/automations/index';
|
|
||||||
import { bigMockAutoList, createMockAuto } from 'utils/mocks';
|
|
||||||
|
|
||||||
const automations: AutomationData[] = [
|
|
||||||
createMockAuto({
|
|
||||||
"Room": 'Living Room',
|
|
||||||
"Type": 'Lights'
|
|
||||||
}),
|
|
||||||
createMockAuto({
|
|
||||||
"Room": 'Living Room',
|
|
||||||
"Type": 'Climate'
|
|
||||||
}),
|
|
||||||
createMockAuto({
|
|
||||||
"Room": 'Kitchen',
|
|
||||||
"Type": 'Climate'
|
|
||||||
}),
|
|
||||||
createMockAuto({
|
|
||||||
"Type": 'Climate'
|
|
||||||
}),
|
|
||||||
createMockAuto({
|
|
||||||
"Room": 'Living Room'
|
|
||||||
}),
|
|
||||||
createMockAuto({}),
|
|
||||||
];
|
|
||||||
|
|
||||||
test('no grouping', () => {
|
|
||||||
const grouped = makeGrouping(automations, [], 0);
|
|
||||||
expect(grouped.top).toStrictEqual([0])
|
|
||||||
expect(grouped.getAutomations(0)).toStrictEqual([0, 1, 2, 3, 4, 5])
|
|
||||||
});
|
|
||||||
test('1 grouping', () => {
|
|
||||||
const grouped = makeGrouping(automations, ["Room"], 0);
|
|
||||||
expect(grouped.top).toHaveLength(3);
|
|
||||||
expect(grouped.getAutomations(0)).toStrictEqual([0, 1, 4])
|
|
||||||
expect(grouped.getAutomations(1)).toStrictEqual([2])
|
|
||||||
expect(grouped.getAutomations(2)).toStrictEqual([3, 5])
|
|
||||||
});
|
|
||||||
test('2 groupings', () => {
|
|
||||||
const grouped = makeGrouping(automations, ["Room", "Type"], 0);
|
|
||||||
expect(grouped.top).toHaveLength(3);
|
|
||||||
expect(grouped.getAutomations(grouped.top[0])).toHaveLength(0)
|
|
||||||
expect(grouped.getSubGroups(grouped.top[0])).toHaveLength(3)
|
|
||||||
expect(grouped.getAutomations(grouped.top[1])).toHaveLength(0)
|
|
||||||
expect(grouped.getSubGroups(grouped.top[1])).toHaveLength(1)
|
|
||||||
expect(grouped.getAutomations(grouped.top[2])).toHaveLength(2)
|
|
||||||
expect(grouped.getSubGroups(grouped.top[2])).toHaveLength(0)
|
|
||||||
});
|
|
||||||
test('bigAutoList groupings has not duplicate ids', () => {
|
|
||||||
const grouped = makeGrouping(bigMockAutoList, ['Room', "Remote"], 0);
|
|
||||||
const flattenAndCount = (gid: number): Record<number, number[]> => {
|
|
||||||
const subgroups = grouped.getSubGroups(gid);
|
|
||||||
if (subgroups.length > 0) {
|
|
||||||
return flattenAndConsolidate(subgroups)
|
|
||||||
} else {
|
|
||||||
return grouped.getAutomations(gid).reduce((sum: Record<number, number[]>, b) => {
|
|
||||||
sum[b] = (sum[b] ?? []).concat(gid)
|
|
||||||
return sum
|
|
||||||
}, {})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const flattenAndConsolidate = (gids: number[]): Record<number, number[]> => gids.map(flattenAndCount).reduce((a, b) => {
|
|
||||||
for (const k of Object.keys(b).map(Number)) {
|
|
||||||
a[k] = (a[k] ?? []).concat(b[k])
|
|
||||||
}
|
|
||||||
return a
|
|
||||||
}, {})
|
|
||||||
const countedAutos = flattenAndConsolidate(grouped.top)
|
|
||||||
for (const key of Object.keys(countedAutos).map(Number)) {
|
|
||||||
expect(countedAutos[key]).toHaveLength(1)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
import { AutomationData } from "types/automations";
|
|
||||||
|
|
||||||
const makeGrouper = () => {
|
|
||||||
const groupIdNames: string[] = []
|
|
||||||
const groupSubGroups: Array<Set<number>> = []
|
|
||||||
const groupAutomations: number[][] = []
|
|
||||||
const groupData: Array<{
|
|
||||||
name: string;
|
|
||||||
selected: boolean;
|
|
||||||
isOther: boolean;
|
|
||||||
isTop: boolean;
|
|
||||||
}> = [];
|
|
||||||
const topGroups: number[] = [];
|
|
||||||
|
|
||||||
return {
|
|
||||||
groupIdNames,
|
|
||||||
groupSubGroups,
|
|
||||||
groupAutomations,
|
|
||||||
groupData,
|
|
||||||
topGroups,
|
|
||||||
addNew(groupId: string, groupName: string, theChosenOne: boolean, isTopLevel: boolean, isOther: boolean = false): number {
|
|
||||||
groupIdNames.push(groupId);
|
|
||||||
groupSubGroups.push(new Set());
|
|
||||||
groupAutomations.push([]);
|
|
||||||
groupData.push({
|
|
||||||
name: groupName,
|
|
||||||
selected: theChosenOne,
|
|
||||||
isTop: isTopLevel,
|
|
||||||
isOther
|
|
||||||
})
|
|
||||||
const groupIdx = groupIdNames.length - 1;
|
|
||||||
if (isTopLevel) {
|
|
||||||
topGroups.push(groupIdx);
|
|
||||||
}
|
|
||||||
return groupIdx;
|
|
||||||
},
|
|
||||||
updateGroup(
|
|
||||||
groupIdx: number,
|
|
||||||
update: {
|
|
||||||
isChosen: boolean,
|
|
||||||
lastGroupIdx: number | null,
|
|
||||||
autoIdx: number | null,
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
if (update.isChosen) {
|
|
||||||
groupData[groupIdx].selected = true;
|
|
||||||
}
|
|
||||||
if (update.lastGroupIdx !== null) {
|
|
||||||
groupSubGroups[update.lastGroupIdx].add(groupIdx);
|
|
||||||
}
|
|
||||||
if (update.autoIdx !== null) {
|
|
||||||
groupAutomations[groupIdx].push(update.autoIdx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type AutomationGrouping = ReturnType<typeof makeGrouping>;
|
|
||||||
export const makeGrouping = (
|
|
||||||
autos: AutomationData[],
|
|
||||||
selectedTags: string[],
|
|
||||||
selectedAutomationIdx: number,
|
|
||||||
) => {
|
|
||||||
const grouper = makeGrouper();
|
|
||||||
|
|
||||||
if (selectedTags.length === 0) {
|
|
||||||
grouper.addNew("$", "", selectedAutomationIdx >= 0, true, true)
|
|
||||||
grouper.groupAutomations = [autos.map((_, i) => i)];
|
|
||||||
} else {
|
|
||||||
autos.forEach((auto, autoIdx) => {
|
|
||||||
const theChosenOne = selectedAutomationIdx === autoIdx;
|
|
||||||
let lastGroupIdx: number | null = null;
|
|
||||||
let lastGroupId: string = "$";
|
|
||||||
for (let ti = 0; ti < selectedTags.length; ti++) {
|
|
||||||
const isTopLevel = ti === 0;
|
|
||||||
const selTag = selectedTags[ti];
|
|
||||||
if (selTag in auto.tags) {
|
|
||||||
const groupName = auto.tags[selTag];
|
|
||||||
const groupId = `${lastGroupId}>${selTag}:${groupName}`;
|
|
||||||
let groupIdx = grouper.groupIdNames.indexOf(groupId);
|
|
||||||
if (groupIdx < 0) {
|
|
||||||
groupIdx = grouper.addNew(groupId, groupName, theChosenOne, isTopLevel);
|
|
||||||
}
|
|
||||||
grouper.updateGroup(groupIdx, {
|
|
||||||
isChosen: theChosenOne,
|
|
||||||
lastGroupIdx,
|
|
||||||
autoIdx: ti === selectedTags.length - 1 ? autoIdx : null,
|
|
||||||
})
|
|
||||||
lastGroupIdx = groupIdx;
|
|
||||||
lastGroupId = groupId;
|
|
||||||
} else {
|
|
||||||
const groupId = `${lastGroupId}>${selTag}:$`;
|
|
||||||
let groupIdx = grouper.groupIdNames.indexOf(groupId);
|
|
||||||
if (groupIdx < 0) {
|
|
||||||
groupIdx = grouper.addNew(groupId, "", theChosenOne, isTopLevel, true);
|
|
||||||
}
|
|
||||||
grouper.updateGroup(groupIdx, {
|
|
||||||
isChosen: theChosenOne,
|
|
||||||
lastGroupIdx,
|
|
||||||
autoIdx,
|
|
||||||
})
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const sortGroupIds = (groupIds: number[]) => groupIds.sort((a, b) => {
|
|
||||||
const adata = grouper.groupData[a];
|
|
||||||
const bdata = grouper.groupData[b];
|
|
||||||
if (adata.isOther) {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return adata.name > bdata.name ? -1 : 1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
top: sortGroupIds(grouper.topGroups),
|
|
||||||
getSubGroups(groupIdx: number) {
|
|
||||||
return sortGroupIds(Array.from(grouper.groupSubGroups[groupIdx].values()))
|
|
||||||
},
|
|
||||||
getAutomations(groupIdx: number) {
|
|
||||||
return grouper.groupAutomations[groupIdx]
|
|
||||||
},
|
|
||||||
getData(groupIdx: number) {
|
|
||||||
return grouper.groupData[groupIdx]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
/* root elements */
|
|
||||||
.automation-list--root {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--list {
|
|
||||||
flex: 1;
|
|
||||||
max-width: 400px;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--viewer {
|
|
||||||
overflow: hidden;
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Loading state */
|
|
||||||
.automation-list--root.loading {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.loading>* {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.loading .automation-list--circle-loader {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* list children: on hide */
|
|
||||||
.automation-list--list.hide>.automation-list-box {
|
|
||||||
width: 0;
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--list.hide {
|
|
||||||
min-width: 35px;
|
|
||||||
max-width: 35px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--list.hide>.automation-list--list-hide {
|
|
||||||
transform: rotate(180deg);
|
|
||||||
left: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* list children: normal */
|
|
||||||
.automation-list--list {
|
|
||||||
border-right: solid;
|
|
||||||
border-width: 1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--list .automation-list--list-hide {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0em;
|
|
||||||
left: 0.5em;
|
|
||||||
max-width: 1.5em;
|
|
||||||
max-height: 1.5em;
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
/* none-hidden */
|
|
||||||
.automation-list--root.mobile {
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.mobile>.automation-list--list {
|
|
||||||
max-width: 100vw;
|
|
||||||
min-height: 100vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.mobile .automation-editor {
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.mobile .automation-list--list-hide {
|
|
||||||
transform: rotate(90deg);
|
|
||||||
left: 0.25em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.mobile .automation-editor--info-box {
|
|
||||||
min-width: 100vw;
|
|
||||||
min-height: calc(100vh - 5em);
|
|
||||||
max-width: 100vw;
|
|
||||||
max-height: calc(100vh - 5em);
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.mobile .automation-editor--info-box-inner {
|
|
||||||
margin-top: 2.5em;
|
|
||||||
padding-left: 0.5em;
|
|
||||||
padding-right: 0.5em;
|
|
||||||
margin-bottom: 2em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.mobile .automation-editor--info-box--icon {
|
|
||||||
left: 0.5em;
|
|
||||||
bottom: 0em;
|
|
||||||
background-color: var(--mui-common-black);
|
|
||||||
transform: rotate(90deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* list hide */
|
|
||||||
.automation-list--root.mobile .automation-list--list.hide {
|
|
||||||
width: 100vw;
|
|
||||||
min-height: 0;
|
|
||||||
max-height: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.mobile .automation-list--list.hide .automation-list--list-hide {
|
|
||||||
transform: rotate(270deg);
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
z-index: 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* info box hide */
|
|
||||||
.automation-list--root.mobile .automation-editor--info-box.hide {
|
|
||||||
width: 100vw;
|
|
||||||
min-height: 0;
|
|
||||||
max-height: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.automation-list--root.mobile .automation-editor--info-box.hide .automation-editor--info-box--icon {
|
|
||||||
transform: rotate(270deg);
|
|
||||||
position: fixed;
|
|
||||||
top: 0em;
|
|
||||||
left: 0.25em;
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.automation-list--root.mobile .automation-editor--flow-wrapper.unchanged>.automation-editor--flow-wrapper--toolbar {
|
|
||||||
height: 0;
|
|
||||||
opacity: 0;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
import "./index.css";
|
|
||||||
import "./index.mobile.css";
|
|
||||||
import { AutomationEditor } from "components/AutomationEditor";
|
|
||||||
import { FC, ReactNode, useState, useRef, useEffect } from "react";
|
|
||||||
import { AutomationData } from "types/automations";
|
|
||||||
import { defaultAutomation } from "utils/defaults";
|
|
||||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
|
||||||
import { ApiService } from "apiService/core";
|
|
||||||
import { AutomationListBox } from "./AutomationListBox";
|
|
||||||
import useWindowSize from "utils/useWindowSize";
|
|
||||||
import { makeTagDB } from "./TagDB";
|
|
||||||
import LinearProgress from "@mui/material/LinearProgress";
|
|
||||||
import CircularProgress from "@mui/material/CircularProgress";
|
|
||||||
import { useCookies } from "react-cookie";
|
|
||||||
import { useHA } from "haService";
|
|
||||||
import { ArrowBack } from "@mui/icons-material";
|
|
||||||
import { useSnackbar } from "notistack";
|
|
||||||
import { DAGDims } from "components/DAGGraph/elements/types";
|
|
||||||
import { ListData, ListParams } from "apiService/types";
|
|
||||||
|
|
||||||
interface AutomationListParams {
|
|
||||||
automations: ListData<AutomationData>;
|
|
||||||
onUpdate: (i: number, auto: AutomationData) => void;
|
|
||||||
onAdd: (auto: AutomationData) => void;
|
|
||||||
onRemove: (i: number) => void;
|
|
||||||
onLoadMore: (p: ListParams) => void;
|
|
||||||
dims: DAGDims;
|
|
||||||
children?: ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAutomationListState = () => {
|
|
||||||
const [
|
|
||||||
cookies,
|
|
||||||
setCookies,
|
|
||||||
// eslint-disable-next-line
|
|
||||||
_,
|
|
||||||
] = useCookies(["alCurrent"]);
|
|
||||||
let initialCurrent = 0;
|
|
||||||
try {
|
|
||||||
initialCurrent = Number(cookies.alCurrent ?? "0");
|
|
||||||
} catch (_) {}
|
|
||||||
|
|
||||||
const [hideList, setHideList] = useState(false);
|
|
||||||
const [current, setCurrent] = useState(initialCurrent);
|
|
||||||
|
|
||||||
return {
|
|
||||||
hideList,
|
|
||||||
setHideList,
|
|
||||||
current,
|
|
||||||
setCurrent(i: number) {
|
|
||||||
setCurrent(i);
|
|
||||||
setCookies("alCurrent", String(i));
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const AutomationList: FC<AutomationListParams> = ({
|
|
||||||
automations,
|
|
||||||
onLoadMore,
|
|
||||||
onUpdate,
|
|
||||||
onAdd,
|
|
||||||
onRemove,
|
|
||||||
dims,
|
|
||||||
children,
|
|
||||||
}) => {
|
|
||||||
// state
|
|
||||||
const snackbr = useSnackbar();
|
|
||||||
const { hideList, setHideList, current, setCurrent } =
|
|
||||||
useAutomationListState();
|
|
||||||
const { isMobile } = useWindowSize();
|
|
||||||
const firstRender = useRef(true);
|
|
||||||
// alias
|
|
||||||
const currentAuto =
|
|
||||||
automations.data.length > 0
|
|
||||||
? automations.data[current - automations.params.offset]
|
|
||||||
: null;
|
|
||||||
const tagDB = makeTagDB(automations.data);
|
|
||||||
// effect
|
|
||||||
useEffect(() => {
|
|
||||||
if (firstRender.current) {
|
|
||||||
snackbr.enqueueSnackbar("Saved.", { variant: "info" });
|
|
||||||
}
|
|
||||||
firstRender.current = true;
|
|
||||||
// eslint-disable-next-line
|
|
||||||
}, [automations]);
|
|
||||||
// render
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={["automation-list--root", isMobile ? "mobile" : ""].join(" ")}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={["automation-list--list", hideList ? "hide" : "show"].join(
|
|
||||||
" "
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<AutomationListBox
|
|
||||||
automations={automations}
|
|
||||||
onUpdate={(a, i) => onUpdate(i, a)}
|
|
||||||
onAdd={() => {
|
|
||||||
onAdd(defaultAutomation(String(Date.now())));
|
|
||||||
setCurrent(automations.data.length);
|
|
||||||
if (isMobile) {
|
|
||||||
setHideList(true);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onSelectAutomation={(i) => {
|
|
||||||
setCurrent(i);
|
|
||||||
if (isMobile) {
|
|
||||||
setHideList(true);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onLoadMore={onLoadMore}
|
|
||||||
selected={current}
|
|
||||||
onRemove={onRemove}
|
|
||||||
tagsDB={tagDB}
|
|
||||||
/>
|
|
||||||
<ButtonIcon
|
|
||||||
onClick={() => setHideList(!hideList)}
|
|
||||||
className="automation-list--list-hide"
|
|
||||||
icon={<ArrowBack />}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="automation-list--viewer">
|
|
||||||
{currentAuto ? (
|
|
||||||
<AutomationEditor
|
|
||||||
automation={currentAuto}
|
|
||||||
onUpdate={(a) => onUpdate(current, a)}
|
|
||||||
dims={{
|
|
||||||
...dims,
|
|
||||||
flipped: isMobile,
|
|
||||||
}}
|
|
||||||
tagDB={tagDB}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface ConnectedAutomationListParams {
|
|
||||||
dims: DAGDims;
|
|
||||||
api: ApiService;
|
|
||||||
}
|
|
||||||
export const ConnectedAutomationList: FC<ConnectedAutomationListParams> = ({
|
|
||||||
api: {
|
|
||||||
state: { automations },
|
|
||||||
...methods
|
|
||||||
},
|
|
||||||
dims,
|
|
||||||
}) => {
|
|
||||||
const { reloadAutomations } = useHA();
|
|
||||||
const removeAutomation = async (args: any) => {
|
|
||||||
const resp = await methods.removeAutomation(args);
|
|
||||||
await reloadAutomations();
|
|
||||||
return resp;
|
|
||||||
};
|
|
||||||
const updateAutomation = async (args: any) => {
|
|
||||||
const resp = await methods.updateAutomation(args);
|
|
||||||
await reloadAutomations();
|
|
||||||
return resp;
|
|
||||||
};
|
|
||||||
if (!automations.ready) {
|
|
||||||
return (
|
|
||||||
<div className="automation-list--root loading">
|
|
||||||
<LinearProgress />
|
|
||||||
<div className="automation-list--circle-loader">
|
|
||||||
<CircularProgress />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!automations.ok) {
|
|
||||||
return <span>Error {automations.error}</span>;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<AutomationList
|
|
||||||
dims={dims}
|
|
||||||
automations={automations.data}
|
|
||||||
onLoadMore={() => {}}
|
|
||||||
onAdd={(auto) =>
|
|
||||||
updateAutomation({ auto, index: automations.data.totalItems + 1 })
|
|
||||||
}
|
|
||||||
onRemove={(index) => removeAutomation({ index })}
|
|
||||||
onUpdate={(index, auto) => updateAutomation({ index, auto })}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
.automation-manager--list-box-group--title {
|
||||||
|
margin: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-manager--list-box-group--title .icon {
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-manager--list-box-group--title:hover,
|
||||||
|
.automation-manager--list-box-group.selected .automation-manager--list-box-group--title {
|
||||||
|
color: var(--mui-primary-main);
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-manager--list-box-group.modified {
|
||||||
|
border: 1px var(--mui-success-main) solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-manager--list-box-group {
|
||||||
|
border-color: var(--mui-text-secondary);
|
||||||
|
border-width: 0.125px;
|
||||||
|
border-bottom-style: solid;
|
||||||
|
border-radius: 10px;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-manager--list-box-group--list.close {
|
||||||
|
height: 0;
|
||||||
|
opacity: 0;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.automation-manager--list-box-group .automation-manager--list-box-group {
|
||||||
|
margin-left: 0.5em;
|
||||||
|
margin-bottom: 0.5em;
|
||||||
|
border-left: 1px solid var(--mui-text-secondary);
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
import { ListBoxGroup } from ".";
|
||||||
|
|
||||||
|
import { makeStory } from "devUtils";
|
||||||
|
import { useTagDB } from "../TagDB";
|
||||||
|
|
||||||
|
const { make, componentMeta } = makeStory({
|
||||||
|
Component: ListBoxGroup,
|
||||||
|
BaseTemplate: (args) => {
|
||||||
|
const tagsDB = useTagDB([], () => {});
|
||||||
|
return <ListBoxGroup {...args} tagsDB={tagsDB} />;
|
||||||
|
},
|
||||||
|
meta: {
|
||||||
|
title: "App/AutomationManager/ListBoxGroup",
|
||||||
|
args: {
|
||||||
|
title: "Example",
|
||||||
|
type: "items",
|
||||||
|
flags: {
|
||||||
|
isSelected: false,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: "1",
|
||||||
|
title: "Example",
|
||||||
|
entityId: "automation.1",
|
||||||
|
description: "Amazing automation!",
|
||||||
|
tags: {},
|
||||||
|
state: "on",
|
||||||
|
flags: {
|
||||||
|
isSelected: false,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "2",
|
||||||
|
title: "Example 2",
|
||||||
|
entityId: "automation.2",
|
||||||
|
description: "Cool!",
|
||||||
|
state: "on",
|
||||||
|
flags: {
|
||||||
|
isSelected: false,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
tags: {
|
||||||
|
room: "main bedroom",
|
||||||
|
routine: "night time",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default componentMeta;
|
||||||
|
|
||||||
|
export const Basic = make({});
|
||||||
|
export const Nested = make({
|
||||||
|
title: "Top Group",
|
||||||
|
type: "group",
|
||||||
|
flags: {
|
||||||
|
isSelected: false,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
title: "Subgroup 1",
|
||||||
|
type: "group",
|
||||||
|
flags: {
|
||||||
|
isSelected: true,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
type: "items",
|
||||||
|
flags: {
|
||||||
|
isSelected: true,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
title: "Subsub group",
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: "1",
|
||||||
|
entityId: "automation.1",
|
||||||
|
description: "",
|
||||||
|
title: "Automation #1",
|
||||||
|
state: "on",
|
||||||
|
flags: {
|
||||||
|
isSelected: true,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
tags: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "2",
|
||||||
|
entityId: "automation.2",
|
||||||
|
description: "another one",
|
||||||
|
title: "Automation #2",
|
||||||
|
state: "off",
|
||||||
|
flags: {
|
||||||
|
isSelected: false,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
tags: {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "3",
|
||||||
|
entityId: "automation.3",
|
||||||
|
description: "bad one",
|
||||||
|
title: "Automation #3",
|
||||||
|
state: "offing",
|
||||||
|
flags: {
|
||||||
|
isSelected: false,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
tags: {
|
||||||
|
type: "bad",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Subgroup 2",
|
||||||
|
type: "group",
|
||||||
|
flags: {
|
||||||
|
isSelected: false,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
data: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "Other",
|
||||||
|
type: "items",
|
||||||
|
flags: {
|
||||||
|
isSelected: false,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: "4",
|
||||||
|
entityId: "automation.4",
|
||||||
|
description: "Cool thing",
|
||||||
|
title: "Automation #4",
|
||||||
|
flags: {
|
||||||
|
isSelected: false,
|
||||||
|
isModified: false,
|
||||||
|
},
|
||||||
|
state: "on",
|
||||||
|
tags: {
|
||||||
|
type: "good",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
import "./index.css";
|
||||||
|
|
||||||
|
import { FC, useState } from "react";
|
||||||
|
import { MetadataBox } from "../MetadataBox";
|
||||||
|
import {
|
||||||
|
AutomationManagerAutoUpdatable,
|
||||||
|
AutomationManagerItem,
|
||||||
|
} from "../types";
|
||||||
|
import { TagDB } from "../TagDB";
|
||||||
|
|
||||||
|
export type ListBoxGroupProps = AutomationManagerItem & {
|
||||||
|
onAutomationUpdate: (
|
||||||
|
a: AutomationManagerAutoUpdatable,
|
||||||
|
aid: string,
|
||||||
|
eid: string
|
||||||
|
) => void;
|
||||||
|
onAutomationDelete: (aid: string, eid: string) => void;
|
||||||
|
onSelect: (aid: string) => void;
|
||||||
|
onRun: (eid: string) => void;
|
||||||
|
initialOpenState?: boolean;
|
||||||
|
tagsDB: TagDB;
|
||||||
|
};
|
||||||
|
export const ListBoxGroup: FC<ListBoxGroupProps> = ({
|
||||||
|
title,
|
||||||
|
type,
|
||||||
|
data,
|
||||||
|
flags,
|
||||||
|
initialOpenState,
|
||||||
|
tagsDB,
|
||||||
|
...events
|
||||||
|
}) => {
|
||||||
|
const [open, setOpen] = useState(initialOpenState ?? false);
|
||||||
|
|
||||||
|
const openIcon = !open ? "⊕" : "⊖";
|
||||||
|
const totalAutomations = countAutomations({
|
||||||
|
title,
|
||||||
|
type,
|
||||||
|
data,
|
||||||
|
} as any);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={[
|
||||||
|
"automation-manager--list-box-group",
|
||||||
|
flags.isSelected ? "selected" : "",
|
||||||
|
flags.isModified ? "modified" : "",
|
||||||
|
].join(" ")}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
onClick={() => setOpen(!open)}
|
||||||
|
className="automation-manager--list-box-group--title"
|
||||||
|
>
|
||||||
|
<b>{title}</b> <span className="icon">{openIcon}</span> (
|
||||||
|
{totalAutomations} automation
|
||||||
|
{totalAutomations === 1 ? "" : "s"})
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={[
|
||||||
|
"automation-manager--list-box-group--list",
|
||||||
|
open ? "open" : "close",
|
||||||
|
].join(" ")}
|
||||||
|
>
|
||||||
|
{type === "items"
|
||||||
|
? data.map((auto, i) => (
|
||||||
|
<MetadataBox
|
||||||
|
key={`${i}-${auto.id}`}
|
||||||
|
{...auto}
|
||||||
|
tagsDB={tagsDB}
|
||||||
|
onDelete={() =>
|
||||||
|
events.onAutomationDelete(auto.id, auto.entityId)
|
||||||
|
}
|
||||||
|
isSelected={auto.flags.isSelected}
|
||||||
|
onSelect={() => events.onSelect(auto.id)}
|
||||||
|
onRun={() => events.onRun(auto.entityId)}
|
||||||
|
onDescriptionUpdate={(description) =>
|
||||||
|
events.onAutomationUpdate(
|
||||||
|
{
|
||||||
|
...auto,
|
||||||
|
description,
|
||||||
|
},
|
||||||
|
auto.id,
|
||||||
|
auto.entityId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onTitleUpdate={(title) =>
|
||||||
|
events.onAutomationUpdate(
|
||||||
|
{
|
||||||
|
...auto,
|
||||||
|
title,
|
||||||
|
},
|
||||||
|
auto.id,
|
||||||
|
auto.entityId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onStateUpdate={(state) =>
|
||||||
|
events.onAutomationUpdate(
|
||||||
|
{
|
||||||
|
...auto,
|
||||||
|
state,
|
||||||
|
},
|
||||||
|
auto.id,
|
||||||
|
auto.entityId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
: data.map((group, i) => (
|
||||||
|
<ListBoxGroup {...events} {...group} tagsDB={tagsDB} key={i} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const countAutomations = (item: AutomationManagerItem): number => {
|
||||||
|
if (item.type === "items") {
|
||||||
|
return item.data.length;
|
||||||
|
} else {
|
||||||
|
return item.data.reduce((total = 0, n) => total + countAutomations(n), 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
import { HassEntities } from "home-assistant-js-websocket";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { AutomationData } from "types/automations";
|
||||||
|
import { defaultAutomation } from "utils/defaults";
|
||||||
|
import { TagDB } from "../TagDB";
|
||||||
|
import { AutomationManagerAuto } from "../types";
|
||||||
|
|
||||||
|
export const useAutomationDB = (
|
||||||
|
haEntities: HassEntities,
|
||||||
|
configAutomations: AutomationData[],
|
||||||
|
tagsDB: TagDB
|
||||||
|
) => {
|
||||||
|
const autoMap = genMapping(haEntities, configAutomations, tagsDB);
|
||||||
|
const [newAuto, setNewAuto] =
|
||||||
|
useState<null | [AutomationManagerAuto, AutomationData]>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (newAuto && autoMap[newAuto[0].id]) {
|
||||||
|
setNewAuto(null);
|
||||||
|
}
|
||||||
|
}, [autoMap, newAuto]);
|
||||||
|
return {
|
||||||
|
get managerAutoList() {
|
||||||
|
const out = Object.values(autoMap).map(([m, _]) => m);
|
||||||
|
if (newAuto) {
|
||||||
|
return out.concat([newAuto[0]]);
|
||||||
|
} else {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getAutomationData(
|
||||||
|
autoId: string
|
||||||
|
): null | [AutomationManagerAuto, AutomationData | null] {
|
||||||
|
if (newAuto && newAuto[0].id === autoId) {
|
||||||
|
return newAuto;
|
||||||
|
}
|
||||||
|
return autoMap[autoId] ?? null;
|
||||||
|
},
|
||||||
|
isAutoNew(autoId: string) {
|
||||||
|
return (newAuto && newAuto[0].id === autoId) ?? false;
|
||||||
|
},
|
||||||
|
removeNew() {
|
||||||
|
setNewAuto(null);
|
||||||
|
},
|
||||||
|
addNew() {
|
||||||
|
const auto = defaultAutomation(String(Date.now()));
|
||||||
|
setNewAuto([
|
||||||
|
{
|
||||||
|
id: auto.metadata.id,
|
||||||
|
entityId: "",
|
||||||
|
title: auto.metadata.alias ?? "",
|
||||||
|
description: auto.metadata.description ?? "",
|
||||||
|
state: "unregistered",
|
||||||
|
tags: {},
|
||||||
|
issue: "New Automation",
|
||||||
|
isNew: true,
|
||||||
|
},
|
||||||
|
auto,
|
||||||
|
]);
|
||||||
|
return auto;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const genMapping = (
|
||||||
|
haEntities: HassEntities,
|
||||||
|
configAutomations: AutomationData[],
|
||||||
|
tagsDB: TagDB
|
||||||
|
) => {
|
||||||
|
const configData: Record<string, AutomationData> = configAutomations.reduce(
|
||||||
|
(all, n) => ({
|
||||||
|
...all,
|
||||||
|
[n.metadata.id]: n,
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
const automatioinMap: Record<
|
||||||
|
string,
|
||||||
|
[AutomationManagerAuto, AutomationData | null]
|
||||||
|
> = {};
|
||||||
|
Object.entries(haEntities)
|
||||||
|
.filter(([entityId, _]) => entityId.toLowerCase().startsWith("automation."))
|
||||||
|
.forEach(([entityId, entityData]) => {
|
||||||
|
const autoId = entityData.attributes.id;
|
||||||
|
let title = entityData.attributes.friendly_name ?? "";
|
||||||
|
let description = "";
|
||||||
|
let issue: string | undefined = ["on", "off"].includes(entityData.state)
|
||||||
|
? undefined
|
||||||
|
: `recived invalid state "${entityData.state}, this could be because you have a lingering automation that was not cleared by homeassistant, try to reboot HA or manually clear this automation from HA Database."`;
|
||||||
|
let found: AutomationData | null = null;
|
||||||
|
|
||||||
|
if (configData[autoId]) {
|
||||||
|
found = configData[entityData.attributes.id];
|
||||||
|
title = found.metadata.alias ?? title;
|
||||||
|
description = found.metadata.description ?? description;
|
||||||
|
delete configData[autoId];
|
||||||
|
} else {
|
||||||
|
issue = "failed to find this automation in '/config' folder";
|
||||||
|
}
|
||||||
|
|
||||||
|
automatioinMap[autoId] = [
|
||||||
|
{
|
||||||
|
id: autoId,
|
||||||
|
entityId,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
state: entityData.state,
|
||||||
|
tags: tagsDB.getTags(autoId),
|
||||||
|
issue,
|
||||||
|
},
|
||||||
|
found,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.values(configData).forEach((auto) => {
|
||||||
|
automatioinMap[auto.metadata.id] = [
|
||||||
|
{
|
||||||
|
id: auto.metadata.id,
|
||||||
|
entityId: "",
|
||||||
|
title: auto.metadata.alias ?? "",
|
||||||
|
description: auto.metadata.description ?? "",
|
||||||
|
state: "unregistered",
|
||||||
|
tags: tagsDB.getTags(auto.metadata.id),
|
||||||
|
issue:
|
||||||
|
"homeassistant did not load this automation, try to manually reload automations or restart homeassistant.",
|
||||||
|
},
|
||||||
|
auto,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return automatioinMap;
|
||||||
|
};
|
||||||
Loaded 100 of 258 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user