Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03dda555a0 | ||
|
|
dc0ce5ba41 | ||
|
|
b886bca3f6 | ||
|
|
5f18fd6315 | ||
|
|
44c999437b | ||
|
|
0c6d89e38b |
No files matched your search
Executable
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
if [[ ! -d "/mnt/Data/Projects/flic2hass" ]]; then
|
||||||
|
echo "Cannot find source directory; Did you move it?"
|
||||||
|
echo "(Looking for "/mnt/Data/Projects/flic2hass")"
|
||||||
|
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# rebuild the cache forcefully
|
||||||
|
_nix_direnv_force_reload=1 direnv exec "/mnt/Data/Projects/flic2hass" true
|
||||||
|
|
||||||
|
# Update the mtime for .envrc.
|
||||||
|
# This will cause direnv to reload again - but without re-building.
|
||||||
|
touch "/mnt/Data/Projects/flic2hass/.envrc"
|
||||||
|
|
||||||
|
# Also update the timestamp of whatever profile_rc we have.
|
||||||
|
# This makes sure that we know we are up to date.
|
||||||
|
touch -r "/mnt/Data/Projects/flic2hass/.envrc" "/mnt/Data/Projects/flic2hass/.direnv"/*.rc
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/nix/store/01x5k4nlxcpyd85nnr0b9gm89rm8ff4x-source
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/nix/store/b14gvgfs5i16wq8h26grmxdxa62lnaa7-source
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/nix/store/cjjpqrp9xy44j5fjh3mygyxy3i7mslj2-source
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/nix/store/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/nix/store/45gfi0xqahibazd3mwkcbxx18slzjcv7-nix-shell-env
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
|||||||
|
if ! has nix_direnv_version || ! nix_direnv_version 3.1.0; then
|
||||||
|
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.1.0/direnvrc" "sha256-yMJ2OVMzrFaDPn7q8nCBZFRYpL/f0RcHzhmw/i6btJM="
|
||||||
|
fi
|
||||||
|
|
||||||
|
nix_direnv_manual_reload
|
||||||
|
use flake
|
||||||
Generated
+61
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1762844143,
|
||||||
|
"narHash": "sha256-SlybxLZ1/e4T2lb1czEtWVzDCVSTvk9WLwGhmxFmBxI=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "9da7f1cf7f8a6e2a7cb3001b048546c92a8258b4",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
description = "A TypeScript project with Nix flakes";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { nixpkgs, flake-utils, ... }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
nodejs = pkgs.nodejs_20; # or nodejs_22, etc.
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
nodejs
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
echo "TypeScript dev environment loaded"
|
||||||
|
echo "Node.js: $(node --version)"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
Generated
+465
-139
@@ -70,156 +70,308 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-android-arm-eabi": {
|
"node_modules/@rollup/rollup-android-arm-eabi": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.53.2.tgz",
|
||||||
"integrity": "sha512-8PlggAxGxavr+pkCNeV1TM2wTb2o+cUWDg9M1cm9nR27Dsn287uZtSLYXoQqQcmq+sYfF7lHfd3sWJJinH9GmA==",
|
"integrity": "sha512-yDPzwsgiFO26RJA4nZo8I+xqzh7sJTZIWQOxn+/XOdPE31lAvLIYCKqjV+lNH/vxE2L2iH3plKxDCRK6i+CwhA==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm"
|
"arm"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"android"
|
"android"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-android-arm64": {
|
"node_modules/@rollup/rollup-android-arm64": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.53.2.tgz",
|
||||||
"integrity": "sha512-+71T85hbMFrJI+zKQULNmSYBeIhru55PYoF/u75MyeN2FcxE4HSPw20319b+FcZ4lWx2Nx/Ql9tN+hoaD3GH/A==",
|
"integrity": "sha512-k8FontTxIE7b0/OGKeSN5B6j25EuppBcWM33Z19JoVT7UTXFSo3D9CdU39wGTeb29NO3XxpMNauh09B+Ibw+9g==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"android"
|
"android"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-darwin-arm64": {
|
"node_modules/@rollup/rollup-darwin-arm64": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.53.2.tgz",
|
||||||
"integrity": "sha512-IIIQLuG43QIElT1JZqUP/zqIdiJl4t9U/boa0GZnQTw9m1X0k3mlBuysbgYXeloLT1RozdL7bgw4lpSaI8GOXw==",
|
"integrity": "sha512-A6s4gJpomNBtJ2yioj8bflM2oogDwzUiMl2yNJ2v9E7++sHrSrsQ29fOfn5DM/iCzpWcebNYEdXpaK4tr2RhfQ==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-darwin-x64": {
|
"node_modules/@rollup/rollup-darwin-x64": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.53.2.tgz",
|
||||||
"integrity": "sha512-BXcXvnLaea1Xz900omrGJhxHFJfH9jZ0CpJuVsbjjhpniJ6qiLXz3xA8Lekaa4MuhFcJd4f0r+Ky1G4VFbYhWw==",
|
"integrity": "sha512-e6XqVmXlHrBlG56obu9gDRPW3O3hLxpwHpLsBJvuI8qqnsrtSZ9ERoWUXtPOkY8c78WghyPHZdmPhHLWNdAGEw==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"node_modules/@rollup/rollup-freebsd-arm64": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-v0E9lJW8VsrwPux5Qe5CwmH/CF/2mQs6xU1MF3nmUxmZUCHazCjLgYvToOk+YuuUqLQBio1qkkREhxhc656ViA==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"freebsd"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@rollup/rollup-freebsd-x64": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-ClAmAPx3ZCHtp6ysl4XEhWU69GUB1D+s7G9YjHGhIGCSrsg00nEGRRZHmINYxkdoJehde8VIsDC5t9C0gb6yqA==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"freebsd"
|
||||||
|
]
|
||||||
|
},
|
||||||
"node_modules/@rollup/rollup-linux-arm-gnueabihf": {
|
"node_modules/@rollup/rollup-linux-arm-gnueabihf": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.53.2.tgz",
|
||||||
"integrity": "sha512-f4K3MKw9Y4AKi4ANGnmPIglr+S+8tO858YrGVuqAHXxJdVghBmz9CPU9kDpOnGvT4g4vg5uNyIFpOOFvffXyMA==",
|
"integrity": "sha512-EPlb95nUsz6Dd9Qy13fI5kUPXNSljaG9FiJ4YUGU1O/Q77i5DYFW5KR8g1OzTcdZUqQQ1KdDqsTohdFVwCwjqg==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm"
|
"arm"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@rollup/rollup-linux-arm-musleabihf": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-BOmnVW+khAUX+YZvNfa0tGTEMVVEerOxN0pDk2E6N6DsEIa2Ctj48FOMfNDdrwinocKaC7YXUZ1pHlKpnkja/Q==",
|
||||||
|
"cpu": [
|
||||||
|
"arm"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-linux-arm64-gnu": {
|
"node_modules/@rollup/rollup-linux-arm64-gnu": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.53.2.tgz",
|
||||||
"integrity": "sha512-bNsTYQBgp4H7w6cT7FZhesxpcUPahsSIy4NgdZjH1ZwEoZHxi4XKglj+CsSEkhsKi+x6toVvMylhjRKhEMYfnA==",
|
"integrity": "sha512-Xt2byDZ+6OVNuREgBXr4+CZDJtrVso5woFtpKdGPhpTPHcNG7D8YXeQzpNbFRxzTVqJf7kvPMCub/pcGUWgBjA==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-linux-arm64-musl": {
|
"node_modules/@rollup/rollup-linux-arm64-musl": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.53.2.tgz",
|
||||||
"integrity": "sha512-Jp1NxBJpGLuxRU2ihrQk4IZ+ia5nffobG6sOFUPW5PMYkF0kQtxEbeDuCa69Xif211vUOcxlOnf5IOEIpTEySA==",
|
"integrity": "sha512-+LdZSldy/I9N8+klim/Y1HsKbJ3BbInHav5qE9Iy77dtHC/pibw1SR/fXlWyAk0ThnpRKoODwnAuSjqxFRDHUQ==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@rollup/rollup-linux-loong64-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-8ms8sjmyc1jWJS6WdNSA23rEfdjWB30LH8Wqj0Cqvv7qSHnvw6kgMMXRdop6hkmGPlyYBdRPkjJnj3KCUHV/uQ==",
|
||||||
|
"cpu": [
|
||||||
|
"loong64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@rollup/rollup-linux-ppc64-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-3HRQLUQbpBDMmzoxPJYd3W6vrVHOo2cVW8RUo87Xz0JPJcBLBr5kZ1pGcQAhdZgX9VV7NbGNipah1omKKe23/g==",
|
||||||
|
"cpu": [
|
||||||
|
"ppc64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@rollup/rollup-linux-riscv64-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-fMjKi+ojnmIvhk34gZP94vjogXNNUKMEYs+EDaB/5TG/wUkoeua7p7VCHnE6T2Tx+iaghAqQX8teQzcvrYpaQA==",
|
||||||
|
"cpu": [
|
||||||
|
"riscv64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@rollup/rollup-linux-riscv64-musl": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-XuGFGU+VwUUV5kLvoAdi0Wz5Xbh2SrjIxCtZj6Wq8MDp4bflb/+ThZsVxokM7n0pcbkEr2h5/pzqzDYI7cCgLQ==",
|
||||||
|
"cpu": [
|
||||||
|
"riscv64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@rollup/rollup-linux-s390x-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-w6yjZF0P+NGzWR3AXWX9zc0DNEGdtvykB03uhonSHMRa+oWA6novflo2WaJr6JZakG2ucsyb+rvhrKac6NIy+w==",
|
||||||
|
"cpu": [
|
||||||
|
"s390x"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-linux-x64-gnu": {
|
"node_modules/@rollup/rollup-linux-x64-gnu": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.53.2.tgz",
|
||||||
"integrity": "sha512-3p3iRtQmv2aXw+vtKNyZMLOQ+LSRsqArXjKAh2Oj9cqwfIRe7OXvdkOzWfZOIp1F/x5KJzVAxGxnniF4cMbnsQ==",
|
"integrity": "sha512-yo8d6tdfdeBArzC7T/PnHd7OypfI9cbuZzPnzLJIyKYFhAQ8SvlkKtKBMbXDxe1h03Rcr7u++nFS7tqXz87Gtw==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-linux-x64-musl": {
|
"node_modules/@rollup/rollup-linux-x64-musl": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.53.2.tgz",
|
||||||
"integrity": "sha512-atih7IF/reUZe4LBLC5Izd44hth2tfDIG8LaPp4/cQXdHh9jabcZEvIeRPrpDq0i/Uu487Qu5gl5KwyAnWajnw==",
|
"integrity": "sha512-ah59c1YkCxKExPP8O9PwOvs+XRLKwh/mV+3YdKqQ5AMQ0r4M4ZDuOrpWkUaqO7fzAHdINzV9tEVu8vNw48z0lA==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-win32-arm64-msvc": {
|
"node_modules/@rollup/rollup-openharmony-arm64": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.53.2.tgz",
|
||||||
"integrity": "sha512-vYxF3tKJeUE4ceYzpNe2p84RXk/fGK30I8frpRfv/MyPStej/mRlojztkN7Jtd1014HHVeq/tYaMBz/3IxkxZw==",
|
"integrity": "sha512-4VEd19Wmhr+Zy7hbUsFZ6YXEiP48hE//KPLCSVNY5RMGX2/7HZ+QkN55a3atM1C/BZCGIgqN+xrVgtdak2S9+A==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"openharmony"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@rollup/rollup-win32-arm64-msvc": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-IlbHFYc/pQCgew/d5fslcy1KEaYVCJ44G8pajugd8VoOEI8ODhtb/j8XMhLpwHCMB3yk2J07ctup10gpw2nyMA==",
|
||||||
|
"cpu": [
|
||||||
|
"arm64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-win32-ia32-msvc": {
|
"node_modules/@rollup/rollup-win32-ia32-msvc": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.53.2.tgz",
|
||||||
"integrity": "sha512-1LZJ6zpl93SaPQvas618bMFarVwufWTaczH4ESAbFcwiC4OtznA6Ym+hFPyIGaJaGEB8uMWWac0uXGPXOg5FGA==",
|
"integrity": "sha512-lNlPEGgdUfSzdCWU176ku/dQRnA7W+Gp8d+cWv73jYrb8uT7HTVVxq62DUYxjbaByuf1Yk0RIIAbDzp+CnOTFg==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"ia32"
|
"ia32"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"node_modules/@rollup/rollup-win32-x64-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-S6YojNVrHybQis2lYov1sd+uj7K0Q05NxHcGktuMMdIQ2VixGwAfbJ23NnlvvVV1bdpR2m5MsNBViHJKcA4ADw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"node_modules/@rollup/rollup-win32-x64-msvc": {
|
"node_modules/@rollup/rollup-win32-x64-msvc": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.53.2.tgz",
|
||||||
"integrity": "sha512-dgQfFdHCNg08nM5zBmqxqc9vrm0DVzhWotpavbPa0j4//MAOKZEB75yGAfzQE9fUJ+4pvM1239Y4IhL8f6sSog==",
|
"integrity": "sha512-k+/Rkcyx//P6fetPoLMb8pBeqJBNGx81uuf7iljX9++yNBVRDQgD04L+SVXmXmh5ZP4/WOp4mWF0kmi06PW2tA==",
|
||||||
"cpu": [
|
"cpu": [
|
||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
@@ -238,14 +390,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@swc/cli": {
|
"node_modules/@swc/cli": {
|
||||||
"version": "0.1.62",
|
"version": "0.1.65",
|
||||||
"resolved": "https://registry.npmjs.org/@swc/cli/-/cli-0.1.62.tgz",
|
"resolved": "https://registry.npmjs.org/@swc/cli/-/cli-0.1.65.tgz",
|
||||||
"integrity": "sha512-kOFLjKY3XH1DWLfXL1/B5MizeNorHR8wHKEi92S/Zi9Md/AK17KSqR8MgyRJ6C1fhKHvbBCl8wboyKAFXStkYw==",
|
"integrity": "sha512-4NcgsvJVHhA7trDnMmkGLLvWMHu2kSy+qHx6QwRhhJhdiYdNUrhdp+ERxen73sYtaeEOYeLJcWrQ60nzKi6rpg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mole-inc/bin-wrapper": "^8.0.1",
|
"@mole-inc/bin-wrapper": "^8.0.1",
|
||||||
"commander": "^7.1.0",
|
"commander": "^7.1.0",
|
||||||
"fast-glob": "^3.2.5",
|
"fast-glob": "^3.2.5",
|
||||||
|
"minimatch": "^9.0.3",
|
||||||
"semver": "^7.3.8",
|
"semver": "^7.3.8",
|
||||||
"slash": "3.0.0",
|
"slash": "3.0.0",
|
||||||
"source-map": "^0.7.3"
|
"source-map": "^0.7.3"
|
||||||
@@ -508,6 +662,13 @@
|
|||||||
"@types/responselike": "^1.0.0"
|
"@types/responselike": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/estree": {
|
||||||
|
"version": "1.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
|
||||||
|
"integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/http-cache-semantics": {
|
"node_modules/@types/http-cache-semantics": {
|
||||||
"version": "4.0.3",
|
"version": "4.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz",
|
||||||
@@ -561,6 +722,13 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"node_modules/balanced-match": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/bin-check": {
|
"node_modules/bin-check": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/bin-check/-/bin-check-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/bin-check/-/bin-check-4.1.0.tgz",
|
||||||
@@ -608,10 +776,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/bin-version/node_modules/cross-spawn": {
|
"node_modules/bin-version/node_modules/cross-spawn": {
|
||||||
"version": "7.0.3",
|
"version": "7.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||||
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
|
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"path-key": "^3.1.0",
|
"path-key": "^3.1.0",
|
||||||
"shebang-command": "^2.0.0",
|
"shebang-command": "^2.0.0",
|
||||||
@@ -725,13 +894,24 @@
|
|||||||
"node": ">= 8"
|
"node": ">= 8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/braces": {
|
"node_modules/brace-expansion": {
|
||||||
"version": "3.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
||||||
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
|
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fill-range": "^7.0.1"
|
"balanced-match": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/braces": {
|
||||||
|
"version": "3.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||||
|
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"fill-range": "^7.1.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
@@ -1007,10 +1187,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fill-range": {
|
"node_modules/fill-range": {
|
||||||
"version": "7.0.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||||
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
|
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"to-regex-range": "^5.0.1"
|
"to-regex-range": "^5.0.1"
|
||||||
},
|
},
|
||||||
@@ -1173,6 +1354,7 @@
|
|||||||
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
||||||
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.12.0"
|
"node": ">=0.12.0"
|
||||||
}
|
}
|
||||||
@@ -1251,12 +1433,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/micromatch": {
|
"node_modules/micromatch": {
|
||||||
"version": "4.0.5",
|
"version": "4.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
|
||||||
"integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==",
|
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"braces": "^3.0.2",
|
"braces": "^3.0.3",
|
||||||
"picomatch": "^2.3.1"
|
"picomatch": "^2.3.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -1290,6 +1473,22 @@
|
|||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/minimatch": {
|
||||||
|
"version": "9.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz",
|
||||||
|
"integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"brace-expansion": "^2.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16 || 14 >=14.17"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/normalize-url": {
|
"node_modules/normalize-url": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
||||||
@@ -1518,10 +1717,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/rollup": {
|
"node_modules/rollup": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.53.2.tgz",
|
||||||
"integrity": "sha512-deaMa9Z+jPVeBD2dKXv+h7EbdKte9++V2potc/ADqvVgEr6DEJ3ia9u0joarjC2lX/ubaCRYz3QVx0TzuVqAJA==",
|
"integrity": "sha512-MHngMYwGJVi6Fmnk6ISmnk7JAHRNF0UkuucA0CUW3N3a4KnONPEZz+vUanQP/ZC/iY1Qkf3bwPWzyY84wEks1g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/estree": "1.0.8"
|
||||||
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"rollup": "dist/bin/rollup"
|
"rollup": "dist/bin/rollup"
|
||||||
},
|
},
|
||||||
@@ -1530,18 +1733,28 @@
|
|||||||
"npm": ">=8.0.0"
|
"npm": ">=8.0.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@rollup/rollup-android-arm-eabi": "4.2.0",
|
"@rollup/rollup-android-arm-eabi": "4.53.2",
|
||||||
"@rollup/rollup-android-arm64": "4.2.0",
|
"@rollup/rollup-android-arm64": "4.53.2",
|
||||||
"@rollup/rollup-darwin-arm64": "4.2.0",
|
"@rollup/rollup-darwin-arm64": "4.53.2",
|
||||||
"@rollup/rollup-darwin-x64": "4.2.0",
|
"@rollup/rollup-darwin-x64": "4.53.2",
|
||||||
"@rollup/rollup-linux-arm-gnueabihf": "4.2.0",
|
"@rollup/rollup-freebsd-arm64": "4.53.2",
|
||||||
"@rollup/rollup-linux-arm64-gnu": "4.2.0",
|
"@rollup/rollup-freebsd-x64": "4.53.2",
|
||||||
"@rollup/rollup-linux-arm64-musl": "4.2.0",
|
"@rollup/rollup-linux-arm-gnueabihf": "4.53.2",
|
||||||
"@rollup/rollup-linux-x64-gnu": "4.2.0",
|
"@rollup/rollup-linux-arm-musleabihf": "4.53.2",
|
||||||
"@rollup/rollup-linux-x64-musl": "4.2.0",
|
"@rollup/rollup-linux-arm64-gnu": "4.53.2",
|
||||||
"@rollup/rollup-win32-arm64-msvc": "4.2.0",
|
"@rollup/rollup-linux-arm64-musl": "4.53.2",
|
||||||
"@rollup/rollup-win32-ia32-msvc": "4.2.0",
|
"@rollup/rollup-linux-loong64-gnu": "4.53.2",
|
||||||
"@rollup/rollup-win32-x64-msvc": "4.2.0",
|
"@rollup/rollup-linux-ppc64-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-riscv64-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-riscv64-musl": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-s390x-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-x64-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-x64-musl": "4.53.2",
|
||||||
|
"@rollup/rollup-openharmony-arm64": "4.53.2",
|
||||||
|
"@rollup/rollup-win32-arm64-msvc": "4.53.2",
|
||||||
|
"@rollup/rollup-win32-ia32-msvc": "4.53.2",
|
||||||
|
"@rollup/rollup-win32-x64-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-win32-x64-msvc": "4.53.2",
|
||||||
"fsevents": "~2.3.2"
|
"fsevents": "~2.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1778,6 +1991,7 @@
|
|||||||
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
||||||
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"is-number": "^7.0.0"
|
"is-number": "^7.0.0"
|
||||||
},
|
},
|
||||||
@@ -1908,86 +2122,156 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@rollup/rollup-android-arm-eabi": {
|
"@rollup/rollup-android-arm-eabi": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.53.2.tgz",
|
||||||
"integrity": "sha512-8PlggAxGxavr+pkCNeV1TM2wTb2o+cUWDg9M1cm9nR27Dsn287uZtSLYXoQqQcmq+sYfF7lHfd3sWJJinH9GmA==",
|
"integrity": "sha512-yDPzwsgiFO26RJA4nZo8I+xqzh7sJTZIWQOxn+/XOdPE31lAvLIYCKqjV+lNH/vxE2L2iH3plKxDCRK6i+CwhA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-android-arm64": {
|
"@rollup/rollup-android-arm64": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.53.2.tgz",
|
||||||
"integrity": "sha512-+71T85hbMFrJI+zKQULNmSYBeIhru55PYoF/u75MyeN2FcxE4HSPw20319b+FcZ4lWx2Nx/Ql9tN+hoaD3GH/A==",
|
"integrity": "sha512-k8FontTxIE7b0/OGKeSN5B6j25EuppBcWM33Z19JoVT7UTXFSo3D9CdU39wGTeb29NO3XxpMNauh09B+Ibw+9g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-darwin-arm64": {
|
"@rollup/rollup-darwin-arm64": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.53.2.tgz",
|
||||||
"integrity": "sha512-IIIQLuG43QIElT1JZqUP/zqIdiJl4t9U/boa0GZnQTw9m1X0k3mlBuysbgYXeloLT1RozdL7bgw4lpSaI8GOXw==",
|
"integrity": "sha512-A6s4gJpomNBtJ2yioj8bflM2oogDwzUiMl2yNJ2v9E7++sHrSrsQ29fOfn5DM/iCzpWcebNYEdXpaK4tr2RhfQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-darwin-x64": {
|
"@rollup/rollup-darwin-x64": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.53.2.tgz",
|
||||||
"integrity": "sha512-BXcXvnLaea1Xz900omrGJhxHFJfH9jZ0CpJuVsbjjhpniJ6qiLXz3xA8Lekaa4MuhFcJd4f0r+Ky1G4VFbYhWw==",
|
"integrity": "sha512-e6XqVmXlHrBlG56obu9gDRPW3O3hLxpwHpLsBJvuI8qqnsrtSZ9ERoWUXtPOkY8c78WghyPHZdmPhHLWNdAGEw==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-freebsd-arm64": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-v0E9lJW8VsrwPux5Qe5CwmH/CF/2mQs6xU1MF3nmUxmZUCHazCjLgYvToOk+YuuUqLQBio1qkkREhxhc656ViA==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-freebsd-x64": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-ClAmAPx3ZCHtp6ysl4XEhWU69GUB1D+s7G9YjHGhIGCSrsg00nEGRRZHmINYxkdoJehde8VIsDC5t9C0gb6yqA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-linux-arm-gnueabihf": {
|
"@rollup/rollup-linux-arm-gnueabihf": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.53.2.tgz",
|
||||||
"integrity": "sha512-f4K3MKw9Y4AKi4ANGnmPIglr+S+8tO858YrGVuqAHXxJdVghBmz9CPU9kDpOnGvT4g4vg5uNyIFpOOFvffXyMA==",
|
"integrity": "sha512-EPlb95nUsz6Dd9Qy13fI5kUPXNSljaG9FiJ4YUGU1O/Q77i5DYFW5KR8g1OzTcdZUqQQ1KdDqsTohdFVwCwjqg==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-linux-arm-musleabihf": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-BOmnVW+khAUX+YZvNfa0tGTEMVVEerOxN0pDk2E6N6DsEIa2Ctj48FOMfNDdrwinocKaC7YXUZ1pHlKpnkja/Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-linux-arm64-gnu": {
|
"@rollup/rollup-linux-arm64-gnu": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.53.2.tgz",
|
||||||
"integrity": "sha512-bNsTYQBgp4H7w6cT7FZhesxpcUPahsSIy4NgdZjH1ZwEoZHxi4XKglj+CsSEkhsKi+x6toVvMylhjRKhEMYfnA==",
|
"integrity": "sha512-Xt2byDZ+6OVNuREgBXr4+CZDJtrVso5woFtpKdGPhpTPHcNG7D8YXeQzpNbFRxzTVqJf7kvPMCub/pcGUWgBjA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-linux-arm64-musl": {
|
"@rollup/rollup-linux-arm64-musl": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.53.2.tgz",
|
||||||
"integrity": "sha512-Jp1NxBJpGLuxRU2ihrQk4IZ+ia5nffobG6sOFUPW5PMYkF0kQtxEbeDuCa69Xif211vUOcxlOnf5IOEIpTEySA==",
|
"integrity": "sha512-+LdZSldy/I9N8+klim/Y1HsKbJ3BbInHav5qE9Iy77dtHC/pibw1SR/fXlWyAk0ThnpRKoODwnAuSjqxFRDHUQ==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-linux-loong64-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-8ms8sjmyc1jWJS6WdNSA23rEfdjWB30LH8Wqj0Cqvv7qSHnvw6kgMMXRdop6hkmGPlyYBdRPkjJnj3KCUHV/uQ==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-linux-ppc64-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-3HRQLUQbpBDMmzoxPJYd3W6vrVHOo2cVW8RUo87Xz0JPJcBLBr5kZ1pGcQAhdZgX9VV7NbGNipah1omKKe23/g==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-linux-riscv64-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-fMjKi+ojnmIvhk34gZP94vjogXNNUKMEYs+EDaB/5TG/wUkoeua7p7VCHnE6T2Tx+iaghAqQX8teQzcvrYpaQA==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-linux-riscv64-musl": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-XuGFGU+VwUUV5kLvoAdi0Wz5Xbh2SrjIxCtZj6Wq8MDp4bflb/+ThZsVxokM7n0pcbkEr2h5/pzqzDYI7cCgLQ==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-linux-s390x-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-w6yjZF0P+NGzWR3AXWX9zc0DNEGdtvykB03uhonSHMRa+oWA6novflo2WaJr6JZakG2ucsyb+rvhrKac6NIy+w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-linux-x64-gnu": {
|
"@rollup/rollup-linux-x64-gnu": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.53.2.tgz",
|
||||||
"integrity": "sha512-3p3iRtQmv2aXw+vtKNyZMLOQ+LSRsqArXjKAh2Oj9cqwfIRe7OXvdkOzWfZOIp1F/x5KJzVAxGxnniF4cMbnsQ==",
|
"integrity": "sha512-yo8d6tdfdeBArzC7T/PnHd7OypfI9cbuZzPnzLJIyKYFhAQ8SvlkKtKBMbXDxe1h03Rcr7u++nFS7tqXz87Gtw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-linux-x64-musl": {
|
"@rollup/rollup-linux-x64-musl": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.53.2.tgz",
|
||||||
"integrity": "sha512-atih7IF/reUZe4LBLC5Izd44hth2tfDIG8LaPp4/cQXdHh9jabcZEvIeRPrpDq0i/Uu487Qu5gl5KwyAnWajnw==",
|
"integrity": "sha512-ah59c1YkCxKExPP8O9PwOvs+XRLKwh/mV+3YdKqQ5AMQ0r4M4ZDuOrpWkUaqO7fzAHdINzV9tEVu8vNw48z0lA==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-openharmony-arm64": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-4VEd19Wmhr+Zy7hbUsFZ6YXEiP48hE//KPLCSVNY5RMGX2/7HZ+QkN55a3atM1C/BZCGIgqN+xrVgtdak2S9+A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-win32-arm64-msvc": {
|
"@rollup/rollup-win32-arm64-msvc": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.53.2.tgz",
|
||||||
"integrity": "sha512-vYxF3tKJeUE4ceYzpNe2p84RXk/fGK30I8frpRfv/MyPStej/mRlojztkN7Jtd1014HHVeq/tYaMBz/3IxkxZw==",
|
"integrity": "sha512-IlbHFYc/pQCgew/d5fslcy1KEaYVCJ44G8pajugd8VoOEI8ODhtb/j8XMhLpwHCMB3yk2J07ctup10gpw2nyMA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-win32-ia32-msvc": {
|
"@rollup/rollup-win32-ia32-msvc": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.53.2.tgz",
|
||||||
"integrity": "sha512-1LZJ6zpl93SaPQvas618bMFarVwufWTaczH4ESAbFcwiC4OtznA6Ym+hFPyIGaJaGEB8uMWWac0uXGPXOg5FGA==",
|
"integrity": "sha512-lNlPEGgdUfSzdCWU176ku/dQRnA7W+Gp8d+cWv73jYrb8uT7HTVVxq62DUYxjbaByuf1Yk0RIIAbDzp+CnOTFg==",
|
||||||
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@rollup/rollup-win32-x64-gnu": {
|
||||||
|
"version": "4.53.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.53.2.tgz",
|
||||||
|
"integrity": "sha512-S6YojNVrHybQis2lYov1sd+uj7K0Q05NxHcGktuMMdIQ2VixGwAfbJ23NnlvvVV1bdpR2m5MsNBViHJKcA4ADw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
"@rollup/rollup-win32-x64-msvc": {
|
"@rollup/rollup-win32-x64-msvc": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.53.2.tgz",
|
||||||
"integrity": "sha512-dgQfFdHCNg08nM5zBmqxqc9vrm0DVzhWotpavbPa0j4//MAOKZEB75yGAfzQE9fUJ+4pvM1239Y4IhL8f6sSog==",
|
"integrity": "sha512-k+/Rkcyx//P6fetPoLMb8pBeqJBNGx81uuf7iljX9++yNBVRDQgD04L+SVXmXmh5ZP4/WOp4mWF0kmi06PW2tA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
@@ -1998,14 +2282,15 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@swc/cli": {
|
"@swc/cli": {
|
||||||
"version": "0.1.62",
|
"version": "0.1.65",
|
||||||
"resolved": "https://registry.npmjs.org/@swc/cli/-/cli-0.1.62.tgz",
|
"resolved": "https://registry.npmjs.org/@swc/cli/-/cli-0.1.65.tgz",
|
||||||
"integrity": "sha512-kOFLjKY3XH1DWLfXL1/B5MizeNorHR8wHKEi92S/Zi9Md/AK17KSqR8MgyRJ6C1fhKHvbBCl8wboyKAFXStkYw==",
|
"integrity": "sha512-4NcgsvJVHhA7trDnMmkGLLvWMHu2kSy+qHx6QwRhhJhdiYdNUrhdp+ERxen73sYtaeEOYeLJcWrQ60nzKi6rpg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@mole-inc/bin-wrapper": "^8.0.1",
|
"@mole-inc/bin-wrapper": "^8.0.1",
|
||||||
"commander": "^7.1.0",
|
"commander": "^7.1.0",
|
||||||
"fast-glob": "^3.2.5",
|
"fast-glob": "^3.2.5",
|
||||||
|
"minimatch": "^9.0.3",
|
||||||
"semver": "^7.3.8",
|
"semver": "^7.3.8",
|
||||||
"slash": "3.0.0",
|
"slash": "3.0.0",
|
||||||
"source-map": "^0.7.3"
|
"source-map": "^0.7.3"
|
||||||
@@ -2140,6 +2425,12 @@
|
|||||||
"@types/responselike": "^1.0.0"
|
"@types/responselike": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/estree": {
|
||||||
|
"version": "1.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
|
||||||
|
"integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@types/http-cache-semantics": {
|
"@types/http-cache-semantics": {
|
||||||
"version": "4.0.3",
|
"version": "4.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz",
|
||||||
@@ -2179,6 +2470,12 @@
|
|||||||
"integrity": "sha512-Of/R0wqp83cgHozfIYLbBMnej79U/SVGOOyuB3VVFv1NRM/PSFMK12x9KVtiYzJqmnU5WR2qp0Z5rHb7sWGnFQ==",
|
"integrity": "sha512-Of/R0wqp83cgHozfIYLbBMnej79U/SVGOOyuB3VVFv1NRM/PSFMK12x9KVtiYzJqmnU5WR2qp0Z5rHb7sWGnFQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"balanced-match": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"bin-check": {
|
"bin-check": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/bin-check/-/bin-check-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/bin-check/-/bin-check-4.1.0.tgz",
|
||||||
@@ -2200,9 +2497,9 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cross-spawn": {
|
"cross-spawn": {
|
||||||
"version": "7.0.3",
|
"version": "7.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||||
"integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
|
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"path-key": "^3.1.0",
|
"path-key": "^3.1.0",
|
||||||
@@ -2291,13 +2588,22 @@
|
|||||||
"semver-truncate": "^3.0.0"
|
"semver-truncate": "^3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"braces": {
|
"brace-expansion": {
|
||||||
"version": "3.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz",
|
||||||
"integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==",
|
"integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"fill-range": "^7.0.1"
|
"balanced-match": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"braces": {
|
||||||
|
"version": "3.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
||||||
|
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"fill-range": "^7.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cacheable-lookup": {
|
"cacheable-lookup": {
|
||||||
@@ -2499,9 +2805,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"fill-range": {
|
"fill-range": {
|
||||||
"version": "7.0.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
||||||
"integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==",
|
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"to-regex-range": "^5.0.1"
|
"to-regex-range": "^5.0.1"
|
||||||
@@ -2674,12 +2980,12 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"micromatch": {
|
"micromatch": {
|
||||||
"version": "4.0.5",
|
"version": "4.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
|
||||||
"integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==",
|
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"braces": "^3.0.2",
|
"braces": "^3.0.3",
|
||||||
"picomatch": "^2.3.1"
|
"picomatch": "^2.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -2701,6 +3007,15 @@
|
|||||||
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==",
|
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"minimatch": {
|
||||||
|
"version": "9.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz",
|
||||||
|
"integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"brace-expansion": "^2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"normalize-url": {
|
"normalize-url": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
||||||
@@ -2849,23 +3164,34 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"rollup": {
|
"rollup": {
|
||||||
"version": "4.2.0",
|
"version": "4.53.2",
|
||||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.53.2.tgz",
|
||||||
"integrity": "sha512-deaMa9Z+jPVeBD2dKXv+h7EbdKte9++V2potc/ADqvVgEr6DEJ3ia9u0joarjC2lX/ubaCRYz3QVx0TzuVqAJA==",
|
"integrity": "sha512-MHngMYwGJVi6Fmnk6ISmnk7JAHRNF0UkuucA0CUW3N3a4KnONPEZz+vUanQP/ZC/iY1Qkf3bwPWzyY84wEks1g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@rollup/rollup-android-arm-eabi": "4.2.0",
|
"@rollup/rollup-android-arm-eabi": "4.53.2",
|
||||||
"@rollup/rollup-android-arm64": "4.2.0",
|
"@rollup/rollup-android-arm64": "4.53.2",
|
||||||
"@rollup/rollup-darwin-arm64": "4.2.0",
|
"@rollup/rollup-darwin-arm64": "4.53.2",
|
||||||
"@rollup/rollup-darwin-x64": "4.2.0",
|
"@rollup/rollup-darwin-x64": "4.53.2",
|
||||||
"@rollup/rollup-linux-arm-gnueabihf": "4.2.0",
|
"@rollup/rollup-freebsd-arm64": "4.53.2",
|
||||||
"@rollup/rollup-linux-arm64-gnu": "4.2.0",
|
"@rollup/rollup-freebsd-x64": "4.53.2",
|
||||||
"@rollup/rollup-linux-arm64-musl": "4.2.0",
|
"@rollup/rollup-linux-arm-gnueabihf": "4.53.2",
|
||||||
"@rollup/rollup-linux-x64-gnu": "4.2.0",
|
"@rollup/rollup-linux-arm-musleabihf": "4.53.2",
|
||||||
"@rollup/rollup-linux-x64-musl": "4.2.0",
|
"@rollup/rollup-linux-arm64-gnu": "4.53.2",
|
||||||
"@rollup/rollup-win32-arm64-msvc": "4.2.0",
|
"@rollup/rollup-linux-arm64-musl": "4.53.2",
|
||||||
"@rollup/rollup-win32-ia32-msvc": "4.2.0",
|
"@rollup/rollup-linux-loong64-gnu": "4.53.2",
|
||||||
"@rollup/rollup-win32-x64-msvc": "4.2.0",
|
"@rollup/rollup-linux-ppc64-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-riscv64-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-riscv64-musl": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-s390x-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-x64-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-linux-x64-musl": "4.53.2",
|
||||||
|
"@rollup/rollup-openharmony-arm64": "4.53.2",
|
||||||
|
"@rollup/rollup-win32-arm64-msvc": "4.53.2",
|
||||||
|
"@rollup/rollup-win32-ia32-msvc": "4.53.2",
|
||||||
|
"@rollup/rollup-win32-x64-gnu": "4.53.2",
|
||||||
|
"@rollup/rollup-win32-x64-msvc": "4.53.2",
|
||||||
|
"@types/estree": "1.0.8",
|
||||||
"fsevents": "~2.3.2"
|
"fsevents": "~2.3.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"description": "Flic Hub MQTT Server",
|
"description": "Flic Hub MQTT Server",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "swc src/ -d dist/ && rollup dist/index.js --file lib.js -f cjs"
|
"build": "rm -rf dist/* && swc src/ -d dist/ && rollup dist/index.js --file lib.js -f cjs"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -1,194 +0,0 @@
|
|||||||
import { HAComponent, HADevice, HAmqtt } from "./HAmqtt";
|
|
||||||
import { makeLogger } from "./Logger";
|
|
||||||
import { Button, ButtonModule } from "./flicTypes";
|
|
||||||
|
|
||||||
const ms2ISO8601 = (ms: number): string =>
|
|
||||||
(new Date(ms)).toISOString().slice(0, 19).replace('T', ' ')
|
|
||||||
|
|
||||||
export type ButtonControllerOpt = {
|
|
||||||
debug: boolean;
|
|
||||||
}
|
|
||||||
export const makeOptions = (opt: Partial<ButtonControllerOpt>): ButtonControllerOpt => ({
|
|
||||||
debug: false,
|
|
||||||
...opt,
|
|
||||||
})
|
|
||||||
const ENTITIES: Record<string, [HAComponent, Record<string, any>]> = {
|
|
||||||
"action": ['sensor', { icon: 'mdi:gesture-tap-button', name: "Click Action" }],
|
|
||||||
"state": ['sensor', { icon: 'mdi:radiobox-indeterminate-variant' }],
|
|
||||||
"battery": ['sensor', { expire_after: 5, unit_of_measurement: '%', device_class: 'battery' }],
|
|
||||||
"batteryLastUpdate": ['sensor', { entity_category: "diagnostic", expire_after: 5, name: "Battery Last Update Time", device_class: "duration", unit_of_measurement: "s" }],
|
|
||||||
"lifeline": ['binary_sensor', { entity_category: "diagnostic", expire_after: 5, name: "Flichub Connected", device_class: "connectivity", unit_of_measurement: "s", payload_not_available: "OFF" }],
|
|
||||||
"connected": ['binary_sensor', { entity_category: "diagnostic", expire_after: 5, device_class: 'connectivity', name: "Connection Established", payload_not_available: "OFF" }],
|
|
||||||
"ready": ['binary_sensor', { entity_category: "config", expire_after: 5, device_class: 'connectivity', name: "Connection Verified" }],
|
|
||||||
"activeDisconnect": ['binary_sensor', { entity_category: "config", expire_after: 5, name: "User Active Disconnect" }],
|
|
||||||
"passive": ['binary_sensor', { entity_category: "config", expire_after: 5, name: "Passive Mode" }],
|
|
||||||
"button_short_press": [
|
|
||||||
'device_automation',
|
|
||||||
{ 'type': 'button_short_press', 'subtype': 'button_1', 'automation_type': 'trigger', 'payload': 'ON' }
|
|
||||||
],
|
|
||||||
"button_long_press": [
|
|
||||||
'device_automation',
|
|
||||||
{ 'type': 'button_long_press', 'subtype': 'button_1', 'automation_type': 'trigger', 'payload': 'ON' }
|
|
||||||
],
|
|
||||||
"button_double_press": [
|
|
||||||
'device_automation',
|
|
||||||
{ 'type': 'button_double_press', 'subtype': 'button_1', 'automation_type': 'trigger', 'payload': 'ON' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
export type ButtonController = ReturnType<typeof makeButtonController>;
|
|
||||||
export function makeButtonController(
|
|
||||||
ha: HAmqtt,
|
|
||||||
buttonModule: ButtonModule,
|
|
||||||
options: Partial<ButtonControllerOpt> = {},
|
|
||||||
) {
|
|
||||||
options = makeOptions(options);
|
|
||||||
const logger = makeLogger('btnc', options.debug)
|
|
||||||
logger.info("Starting Flic ButtonController with", JSON.stringify(options, null, 4));
|
|
||||||
|
|
||||||
const getDeviceFromButton = (button: Button): HADevice => {
|
|
||||||
return {
|
|
||||||
name: button.name,
|
|
||||||
identifiers: [button.serialNumber, button.uuid],
|
|
||||||
manufacturer: 'Flic',
|
|
||||||
model: `v${button.flicVersion}_${button.color.trim().length > 0 ? button.color : 'white'}`,
|
|
||||||
sw: String(button.firmwareVersion),
|
|
||||||
hw: String(button.flicVersion),
|
|
||||||
configuration_url: "https://hubsdk.flic.io/",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const genButtonUniqueId = (bdaddr: string): string => bdaddr.replace(/:/g, '_')
|
|
||||||
const registerButton = (button: Button) => {
|
|
||||||
logger.info('Registering', JSON.stringify(button, null, 4))
|
|
||||||
const haDevice = getDeviceFromButton(button);
|
|
||||||
Object.keys(ENTITIES).forEach(objectId => {
|
|
||||||
let avl: any = {
|
|
||||||
availability: [
|
|
||||||
{
|
|
||||||
payload_available: 'ON',
|
|
||||||
payload_not_available: 'unavailable',
|
|
||||||
topic: ha.genFlicPrefix(genButtonUniqueId(button.bdaddr), 'ready')
|
|
||||||
},
|
|
||||||
{
|
|
||||||
payload_available: 'ON',
|
|
||||||
payload_not_available: 'unavailable',
|
|
||||||
topic: ha.genFlicPrefix(genButtonUniqueId(button.bdaddr), 'lifeline')
|
|
||||||
},
|
|
||||||
],
|
|
||||||
availability_mode: 'all',
|
|
||||||
};
|
|
||||||
if (objectId === 'lifeline') {
|
|
||||||
avl = {}
|
|
||||||
}
|
|
||||||
if (objectId === 'ready' || objectId == 'connected') {
|
|
||||||
avl.availability = [avl.availability[1]]
|
|
||||||
}
|
|
||||||
if (ENTITIES[objectId][0] === 'device_automation') {
|
|
||||||
avl = {}
|
|
||||||
}
|
|
||||||
ha.registerEntity(
|
|
||||||
`Button ${objectId}`,
|
|
||||||
ENTITIES[objectId][0],
|
|
||||||
genButtonUniqueId(button.bdaddr),
|
|
||||||
objectId,
|
|
||||||
haDevice,
|
|
||||||
{
|
|
||||||
...ENTITIES[objectId][1],
|
|
||||||
...avl
|
|
||||||
},
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const deregisterButton = (button: Button) => {
|
|
||||||
logger.info('Deregistering', JSON.stringify(button, null, 4))
|
|
||||||
Object.keys(ENTITIES).forEach(objectId => {
|
|
||||||
ha.deregisterEntity(
|
|
||||||
ENTITIES[objectId][0],
|
|
||||||
genButtonUniqueId(button.bdaddr),
|
|
||||||
objectId,
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const publishButtonState = (button: Button, state: 'released' | 'pressed') => {
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'state', state);
|
|
||||||
}
|
|
||||||
const publishButtonAction = (button: Button, state: 'click' | 'double_click' | 'hold') => {
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'action', state);
|
|
||||||
if (state === 'click') {
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'button_short_press', 'ON')
|
|
||||||
} else if (state === 'double_click') {
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'button_double_press', 'ON')
|
|
||||||
} else if (state === 'hold') {
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'button_long_press', 'ON')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const publishButtonMeta = (button: Button) => {
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'battery', button.batteryStatus);
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'batteryLastUpdate', button.batteryTimestamp ? `${Math.round((Date.now() - button.batteryTimestamp) / 1000)}` : 'unknown');
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'connected', button.connected ? 'ON' : "OFF");
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'ready', button.ready ? 'ON' : "OFF");
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'activeDisconnect', button.activeDisconnect ? 'ON' : "OFF");
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'passive', button.activeDisconnect ? 'ON' : "OFF");
|
|
||||||
ha.publishState(genButtonUniqueId(button.bdaddr), 'lifeline', 'ON');
|
|
||||||
}
|
|
||||||
const addBtn = (eventName: string) => (obj: { bdaddr: string }) => {
|
|
||||||
const button = buttonModule.getButton(obj.bdaddr);
|
|
||||||
logger.info(eventName, "upserting", button.name, genButtonUniqueId(button.bdaddr));
|
|
||||||
registerButton(button);
|
|
||||||
}
|
|
||||||
const start = () => {
|
|
||||||
logger.info("Starting...")
|
|
||||||
let resetActiontInv: null | any = null;
|
|
||||||
buttonModule.on('buttonAdded', addBtn('buttonAdded'));
|
|
||||||
buttonModule.on('buttonConnected', addBtn('buttonConnected'));
|
|
||||||
buttonModule.on('buttonReady', (btn) => {
|
|
||||||
addBtn('buttonReady')(btn);
|
|
||||||
const button = buttonModule.getButton(btn.bdaddr);
|
|
||||||
publishButtonState(button, 'released')
|
|
||||||
publishButtonAction(button, 'none')
|
|
||||||
});
|
|
||||||
buttonModule.on('buttonUpdated', addBtn('buttonUpdated'));
|
|
||||||
buttonModule.on('buttonDeleted', (btn) => {
|
|
||||||
logger.debug('buttonDeleted', JSON.stringify(btn, null, 4))
|
|
||||||
deregisterButton(btn);
|
|
||||||
publishButtonMeta(btn);
|
|
||||||
});
|
|
||||||
buttonModule.on('buttonDisconnected', ({ bdaddr }) => {
|
|
||||||
publishButtonMeta(buttonModule.getButton(bdaddr));
|
|
||||||
});
|
|
||||||
buttonModule.on('buttonDown', ({ bdaddr }) => {
|
|
||||||
const btn = buttonModule.getButton(bdaddr);
|
|
||||||
publishButtonState(btn, 'pressed');
|
|
||||||
publishButtonMeta(btn);
|
|
||||||
});
|
|
||||||
buttonModule.on('buttonUp', ({ bdaddr }) => {
|
|
||||||
const btn = buttonModule.getButton(bdaddr);
|
|
||||||
publishButtonState(btn, 'released');
|
|
||||||
publishButtonMeta(btn);
|
|
||||||
});
|
|
||||||
buttonModule.on('buttonSingleOrDoubleClickOrHold', obj => {
|
|
||||||
if (resetActiontInv !== null) {
|
|
||||||
clearTimeout(resetActiontInv);
|
|
||||||
}
|
|
||||||
const btn = buttonModule.getButton(obj.bdaddr);
|
|
||||||
publishButtonAction(
|
|
||||||
btn,
|
|
||||||
obj.isSingleClick ? "click" : obj.isDoubleClick ? "double_click" : "hold",
|
|
||||||
);
|
|
||||||
publishButtonMeta(btn);
|
|
||||||
resetActiontInv = setTimeout(() => {
|
|
||||||
publishButtonAction(btn, 'none');
|
|
||||||
}, 500)
|
|
||||||
});
|
|
||||||
logger.info("Registering all buttons...")
|
|
||||||
buttonModule.getButtons().forEach(registerButton);
|
|
||||||
setInterval(() => buttonModule.getButtons().forEach(publishButtonMeta), 3000);
|
|
||||||
logger.info('is up')
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
start,
|
|
||||||
publishButtonAction,
|
|
||||||
publishButtonMeta,
|
|
||||||
publishButtonState,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
import { makeLogger } from "./Logger";
|
|
||||||
import { MQTT } from "./mqtt";
|
|
||||||
|
|
||||||
export type HAmqttOptions = {
|
|
||||||
debug: boolean,
|
|
||||||
topics: {
|
|
||||||
homeassistant: string,
|
|
||||||
flic: string,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export type MQTTPublishOpt = {
|
|
||||||
retain?: boolean // the server should retain this message and send it out again to new subscribers
|
|
||||||
dup?: boolean // indicate the message is a duplicate because original wasn't ACKed (QoS > 0 only)
|
|
||||||
}
|
|
||||||
export type HADevice = {
|
|
||||||
name: string,
|
|
||||||
identifiers: string[],
|
|
||||||
manufacturer: string,
|
|
||||||
model: string,
|
|
||||||
sw?: string,
|
|
||||||
hw?: string,
|
|
||||||
configuration_url?: string,
|
|
||||||
}
|
|
||||||
export type HAComponent = 'sensor' | 'binary_sensor' | 'button' | 'switch' | 'text' | 'device_automation';
|
|
||||||
export const makeOptions = (opt: Partial<HAmqttOptions>): HAmqttOptions => ({
|
|
||||||
debug: false,
|
|
||||||
...opt,
|
|
||||||
topics: {
|
|
||||||
homeassistant: 'homeassistant',
|
|
||||||
flic: 'flic',
|
|
||||||
...opt.topics,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
export type HAmqtt = ReturnType<typeof makeHAmqtt>;
|
|
||||||
export function makeHAmqtt(
|
|
||||||
mqttServer: MQTT,
|
|
||||||
options: Partial<HAmqttOptions> = {},
|
|
||||||
) {
|
|
||||||
options = makeOptions(options);
|
|
||||||
const logger = makeLogger('mqtt:ha', options.debug);
|
|
||||||
logger.info("starting...", JSON.stringify(options, null, 4));
|
|
||||||
|
|
||||||
const genFlicPrefix = (nodeId: string, objectId: string): string => {
|
|
||||||
return `${options.topics.flic}/${nodeId}/${objectId}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const genHAPrefix = (component: HAComponent, nodeId: string, objectId: string) => {
|
|
||||||
return `${options.topics.homeassistant}/${component}/${nodeId}/${objectId}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const publishState = (nodeId: string, objectId: string, state: any, opt: MQTTPublishOpt = {}) => {
|
|
||||||
const btntopic = genFlicPrefix(nodeId, objectId);
|
|
||||||
mqttServer.publish(btntopic, state + "", opt);
|
|
||||||
logger.debug(btntopic, state, JSON.stringify(opt))
|
|
||||||
}
|
|
||||||
const registerEntity = (
|
|
||||||
name: string,
|
|
||||||
component: HAComponent,
|
|
||||||
nodeId: string,
|
|
||||||
objectId: string,
|
|
||||||
device: HADevice,
|
|
||||||
additionalProps: Record<string, any> = {},
|
|
||||||
) => {
|
|
||||||
const configtopic = genHAPrefix(component, nodeId, objectId) + "/config"
|
|
||||||
if (component === 'device_automation') {
|
|
||||||
additionalProps.topic = genFlicPrefix(nodeId, objectId)
|
|
||||||
} else {
|
|
||||||
additionalProps.state_topic = genFlicPrefix(nodeId, objectId)
|
|
||||||
}
|
|
||||||
const configObj = {
|
|
||||||
name,
|
|
||||||
...additionalProps,
|
|
||||||
unique_id: `Flic_${nodeId}_${objectId}`,
|
|
||||||
device,
|
|
||||||
};
|
|
||||||
mqttServer.publish(configtopic, JSON.stringify(configObj), {
|
|
||||||
retain: true,
|
|
||||||
});
|
|
||||||
logger.debug(configtopic, JSON.stringify(configObj, null, 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
const deregisterEntity = (
|
|
||||||
component: HAComponent,
|
|
||||||
nodeId: string,
|
|
||||||
objectId: string,
|
|
||||||
) => {
|
|
||||||
const configtopic = genHAPrefix(component, nodeId, objectId) + "/config"
|
|
||||||
mqttServer.publish(configtopic, null, { retain: false });
|
|
||||||
logger.debug(configtopic, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
deregisterEntity,
|
|
||||||
registerEntity,
|
|
||||||
publishState,
|
|
||||||
genFlicPrefix,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,176 +0,0 @@
|
|||||||
import { HADevice, HAmqtt } from "./HAmqtt";
|
|
||||||
import { makeLogger } from "./Logger";
|
|
||||||
import { IRModule } from "./flicTypes";
|
|
||||||
import { MQTT } from "./mqtt";
|
|
||||||
|
|
||||||
const NODE_ID = 'FlicHubIR';
|
|
||||||
const convertUint32Array2Str = (arr: Uint32Array): string => {
|
|
||||||
let outStr = []
|
|
||||||
for (let i = 0; i < arr.length; i++) {
|
|
||||||
outStr.push(arr[i].toString(32))
|
|
||||||
}
|
|
||||||
return outStr.join('_')
|
|
||||||
}
|
|
||||||
const convertStr2Uint32Array = (s: string): Uint32Array => {
|
|
||||||
const a = s.split('_');
|
|
||||||
return new Uint32Array(a.slice(0, a.length - 2).map(v => parseInt(v, 32)))
|
|
||||||
}
|
|
||||||
export type IRControllerOpt = {
|
|
||||||
uniqueId: string,
|
|
||||||
debug: boolean;
|
|
||||||
}
|
|
||||||
export const makeOptions = (opt: Partial<IRControllerOpt>): IRControllerOpt => ({
|
|
||||||
debug: false,
|
|
||||||
uniqueId: "0",
|
|
||||||
...opt,
|
|
||||||
})
|
|
||||||
export const makeIRController = (
|
|
||||||
ir: IRModule,
|
|
||||||
ha: HAmqtt,
|
|
||||||
mqtt: MQTT,
|
|
||||||
options: Partial<IRControllerOpt> = {},
|
|
||||||
) => {
|
|
||||||
options = makeOptions(options);
|
|
||||||
const logger = makeLogger('ir', options.debug);
|
|
||||||
const haDevice: HADevice = {
|
|
||||||
name: 'IR',
|
|
||||||
manufacturer: 'Flic',
|
|
||||||
model: `${NODE_ID}${options.uniqueId}`,
|
|
||||||
identifiers: ['FlicHubIR'],
|
|
||||||
configuration_url: "https://hubsdk.flic.io/",
|
|
||||||
}
|
|
||||||
const nodeId = `${NODE_ID}${options.uniqueId}`;
|
|
||||||
const LIFELINE_SGINAL = ha.genFlicPrefix(nodeId, 'lifeline');
|
|
||||||
const RECORD_SIGNAL_SET = ha.genFlicPrefix(nodeId, 'record/set');
|
|
||||||
const VALUE_SIGNAL_SET = ha.genFlicPrefix(nodeId, 'signal/set');
|
|
||||||
const VALUE_SIGNAL_STATE = ha.genFlicPrefix(nodeId, 'signal');
|
|
||||||
const PLAY_SIGNAL_SET = ha.genFlicPrefix(nodeId, 'play/set');
|
|
||||||
const availability = [
|
|
||||||
{
|
|
||||||
"payload_available": "ON",
|
|
||||||
"payload_not_available": "unavailable",
|
|
||||||
"topic": LIFELINE_SGINAL,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
let currentSignal: string | null = null;
|
|
||||||
|
|
||||||
const set_topics = [
|
|
||||||
RECORD_SIGNAL_SET,
|
|
||||||
VALUE_SIGNAL_SET,
|
|
||||||
PLAY_SIGNAL_SET,
|
|
||||||
VALUE_SIGNAL_STATE,
|
|
||||||
];
|
|
||||||
|
|
||||||
return {
|
|
||||||
start() {
|
|
||||||
logger.info('starting...')
|
|
||||||
logger.debug('setting up entities...')
|
|
||||||
ha.registerEntity(
|
|
||||||
'IR Available',
|
|
||||||
'binary_sensor',
|
|
||||||
nodeId,
|
|
||||||
'lifeline',
|
|
||||||
haDevice,
|
|
||||||
{
|
|
||||||
device_class: 'connectivity',
|
|
||||||
expire_after: 5,
|
|
||||||
off_delay: 3,
|
|
||||||
entity_category: "diagnostic",
|
|
||||||
payload_available: "ON",
|
|
||||||
payload_not_available: "OFF",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
ha.registerEntity(
|
|
||||||
'Record Signal',
|
|
||||||
'switch',
|
|
||||||
nodeId,
|
|
||||||
'record',
|
|
||||||
haDevice,
|
|
||||||
{
|
|
||||||
icon: 'mdi:record-rec',
|
|
||||||
command_topic: RECORD_SIGNAL_SET,
|
|
||||||
device_class: 'switch',
|
|
||||||
availability,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
ha.registerEntity(
|
|
||||||
'Signal',
|
|
||||||
'text',
|
|
||||||
nodeId,
|
|
||||||
'signal',
|
|
||||||
haDevice,
|
|
||||||
{
|
|
||||||
command_topic: VALUE_SIGNAL_SET,
|
|
||||||
icon: 'mdi:broadcast',
|
|
||||||
max: 255,
|
|
||||||
availability,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
ha.registerEntity(
|
|
||||||
'Play Signal',
|
|
||||||
'button',
|
|
||||||
nodeId,
|
|
||||||
'play',
|
|
||||||
haDevice,
|
|
||||||
{
|
|
||||||
icon: 'mdi:play',
|
|
||||||
command_topic: PLAY_SIGNAL_SET,
|
|
||||||
availability,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
logger.debug('setting default states....')
|
|
||||||
ha.publishState(nodeId, 'record', 'OFF')
|
|
||||||
ha.publishState(nodeId, 'play', 'OFF')
|
|
||||||
logger.debug('registering events')
|
|
||||||
mqtt.on('message', (topic, message) => {
|
|
||||||
logger.debug('message:', JSON.stringify({ topic, message }))
|
|
||||||
if (topic === RECORD_SIGNAL_SET) {
|
|
||||||
logger.debug('starting record')
|
|
||||||
ir.record()
|
|
||||||
ha.publishState(nodeId, 'record', 'ON')
|
|
||||||
} else if (topic === PLAY_SIGNAL_SET) {
|
|
||||||
if (currentSignal !== null) {
|
|
||||||
logger.info('playing', currentSignal)
|
|
||||||
let arr: Uint32Array | null = null
|
|
||||||
try {
|
|
||||||
arr = convertStr2Uint32Array(currentSignal)
|
|
||||||
} catch (err) {
|
|
||||||
logger.error('invalid string signal set', JSON.stringify(err), err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ir.play(arr, (err) => {
|
|
||||||
if (err) {
|
|
||||||
logger.error('failed to play signal', JSON.stringify(err), err)
|
|
||||||
} else {
|
|
||||||
logger.debug('signal played!')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
logger.error('cannot play an unset signal')
|
|
||||||
}
|
|
||||||
} else if (topic === VALUE_SIGNAL_STATE) {
|
|
||||||
currentSignal = message
|
|
||||||
logger.info('setting currentSignal', currentSignal)
|
|
||||||
} else if (topic === VALUE_SIGNAL_SET) {
|
|
||||||
ha.publishState(nodeId, 'signal', message, { retain: true })
|
|
||||||
}
|
|
||||||
})
|
|
||||||
ir.on('recordComplete', data => {
|
|
||||||
const stringMessage = convertUint32Array2Str(data)
|
|
||||||
logger.debug('recording completed with', JSON.stringify({ data, stringMessage, rev: convertStr2Uint32Array(stringMessage) }))
|
|
||||||
if (stringMessage.length > 255) {
|
|
||||||
logger.error("stringMessage is too big! size=", stringMessage.length, 'max=255')
|
|
||||||
}
|
|
||||||
ha.publishState(nodeId, 'signal', stringMessage, { retain: true })
|
|
||||||
ha.publishState(nodeId, 'record', 'OFF')
|
|
||||||
})
|
|
||||||
|
|
||||||
logger.debug('subscribing to', set_topics)
|
|
||||||
mqtt.subscribe(set_topics)
|
|
||||||
setInterval(() => {
|
|
||||||
ha.publishState(nodeId, 'lifeline', 'ON')
|
|
||||||
}, 2500)
|
|
||||||
logger.info('is up')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
import buttonModule, { Button } from "buttons";
|
||||||
|
import { Logger } from "../Logger";
|
||||||
|
import {
|
||||||
|
ButtonConstants,
|
||||||
|
deregisterButton,
|
||||||
|
genButtonUniqueId,
|
||||||
|
getConstants,
|
||||||
|
registerEntities,
|
||||||
|
} from "./utils";
|
||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
|
||||||
|
export const createHandleBtnCreation =
|
||||||
|
(ha: HAmqtt, logger: Logger) =>
|
||||||
|
(eventName: string) =>
|
||||||
|
(button: Button): ButtonConstants => {
|
||||||
|
logger.info(
|
||||||
|
eventName,
|
||||||
|
"upserting",
|
||||||
|
button.name,
|
||||||
|
genButtonUniqueId(button.bdaddr),
|
||||||
|
);
|
||||||
|
const constants = registerEntities(ha, button, logger);
|
||||||
|
publishButtonMeta(ha, button, constants, logger);
|
||||||
|
return constants;
|
||||||
|
};
|
||||||
|
|
||||||
|
const publishButtonMeta = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
button: Button,
|
||||||
|
constants: ButtonConstants,
|
||||||
|
logger: Logger,
|
||||||
|
): ButtonConstants => {
|
||||||
|
logger.debug(`Publishing Button Metadata ${JSON.stringify(button)}`);
|
||||||
|
ha.publishStateFromObject(constants.states.BATTERY, button.batteryStatus);
|
||||||
|
ha.publishStateFromObject(
|
||||||
|
constants.signals.CONNECTED,
|
||||||
|
button.connected ? "ON" : "OFF",
|
||||||
|
);
|
||||||
|
ha.publishStateFromObject(
|
||||||
|
constants.signals.READY,
|
||||||
|
button.ready ? "ON" : "OFF",
|
||||||
|
);
|
||||||
|
ha.publishStateFromObject(
|
||||||
|
constants.states.ACTIVE_DISCONNECT,
|
||||||
|
button.activeDisconnect ? "ON" : "OFF",
|
||||||
|
);
|
||||||
|
return constants;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const publishButtonMetaByBdaddr = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
bdaddr: string,
|
||||||
|
logger: Logger,
|
||||||
|
): ButtonConstants | null => {
|
||||||
|
const button = buttonModule.getButton(bdaddr);
|
||||||
|
if (!button) {
|
||||||
|
logger.error(`Cannot publish metadata for ${{ bdaddr }}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const constants = getConstants(ha, bdaddr);
|
||||||
|
return publishButtonMeta(ha, button, constants, logger);
|
||||||
|
};
|
||||||
|
|
||||||
|
const publishButtonAction = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
logger: Logger,
|
||||||
|
constants: ButtonConstants,
|
||||||
|
state: "click" | "double_click" | "hold" | "none",
|
||||||
|
) => {
|
||||||
|
ha.publishStateFromObject(constants.states.ACTION, state);
|
||||||
|
logger.debug(
|
||||||
|
`Publishing click for uniqId="${constants.uniqId}" state=${state}`,
|
||||||
|
);
|
||||||
|
if (state === "click") {
|
||||||
|
ha.publishStateFromObject(
|
||||||
|
constants.actions.SHORT_PRESS,
|
||||||
|
constants.actions.SHORT_PRESS.objectId,
|
||||||
|
);
|
||||||
|
} else if (state === "double_click") {
|
||||||
|
ha.publishStateFromObject(
|
||||||
|
constants.actions.DOUBLE_PRESS,
|
||||||
|
constants.actions.DOUBLE_PRESS.objectId,
|
||||||
|
);
|
||||||
|
} else if (state === "hold") {
|
||||||
|
ha.publishStateFromObject(
|
||||||
|
constants.actions.LONG_PRESS,
|
||||||
|
constants.actions.LONG_PRESS.objectId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export const setListeners = (ha: HAmqtt, logger: Logger) => {
|
||||||
|
const resetActiontInv: Record<string, any> = {};
|
||||||
|
const handleButtonCreation = createHandleBtnCreation(ha, logger);
|
||||||
|
buttonModule.on("buttonAdded", (btn) =>
|
||||||
|
handleButtonCreation("buttonAdded")(btn.button),
|
||||||
|
);
|
||||||
|
buttonModule.on("buttonUpdated", (btn) =>
|
||||||
|
handleButtonCreation("buttonUpdated")(btn.button),
|
||||||
|
);
|
||||||
|
buttonModule.on("buttonDeleted", ({ bdaddr }) => {
|
||||||
|
deregisterButton(ha, bdaddr, logger);
|
||||||
|
if (resetActiontInv[bdaddr]) {
|
||||||
|
clearTimeout(resetActiontInv[bdaddr]);
|
||||||
|
resetActiontInv[bdaddr] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonModule.on("buttonConnected", ({ bdaddr }) => {
|
||||||
|
const btn = buttonModule.getButton(bdaddr);
|
||||||
|
if (btn) {
|
||||||
|
handleButtonCreation("buttonConnected")(btn);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonModule.on("buttonReady", ({ bdaddr }) => {
|
||||||
|
const btn = buttonModule.getButton(bdaddr);
|
||||||
|
if (btn) {
|
||||||
|
const constants = handleButtonCreation("buttonReady")(btn);
|
||||||
|
ha.publishStateFromObject(constants.states.STATE, "released");
|
||||||
|
publishButtonAction(ha, logger, constants, "none");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonModule.on("buttonDisconnected", ({ bdaddr }) => {
|
||||||
|
if (resetActiontInv[bdaddr]) {
|
||||||
|
clearTimeout(resetActiontInv[bdaddr]);
|
||||||
|
resetActiontInv[bdaddr] = null;
|
||||||
|
}
|
||||||
|
publishButtonMetaByBdaddr(ha, bdaddr, logger);
|
||||||
|
});
|
||||||
|
buttonModule.on("buttonDown", ({ bdaddr }) => {
|
||||||
|
const constants = publishButtonMetaByBdaddr(ha, bdaddr, logger);
|
||||||
|
if (constants) {
|
||||||
|
ha.publishStateFromObject(constants.states.STATE, "pressed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonModule.on("buttonUp", ({ bdaddr }) => {
|
||||||
|
const constants = publishButtonMetaByBdaddr(ha, bdaddr, logger);
|
||||||
|
if (constants) {
|
||||||
|
ha.publishStateFromObject(constants.states.STATE, "released");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonModule.on("buttonSingleOrDoubleClickOrHold", (obj) => {
|
||||||
|
const constants = publishButtonMetaByBdaddr(ha, obj.bdaddr, logger);
|
||||||
|
if (constants) {
|
||||||
|
if (resetActiontInv[obj.bdaddr]) {
|
||||||
|
clearTimeout(resetActiontInv[obj.bdaddr]);
|
||||||
|
resetActiontInv[obj.bdaddr] = null;
|
||||||
|
}
|
||||||
|
publishButtonAction(
|
||||||
|
ha,
|
||||||
|
logger,
|
||||||
|
constants,
|
||||||
|
obj.isSingleClick
|
||||||
|
? "click"
|
||||||
|
: obj.isDoubleClick
|
||||||
|
? "double_click"
|
||||||
|
: "hold",
|
||||||
|
);
|
||||||
|
resetActiontInv[obj.bdaddr] = setTimeout(() => {
|
||||||
|
publishButtonAction(ha, logger, constants, "none");
|
||||||
|
}, 750);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { makeLogger } from "../Logger";
|
||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
import {
|
||||||
|
createHandleBtnCreation,
|
||||||
|
publishButtonMetaByBdaddr,
|
||||||
|
setListeners,
|
||||||
|
} from "./button_module_handler";
|
||||||
|
import { makeOptions } from "./utils";
|
||||||
|
import buttonModule from "buttons";
|
||||||
|
|
||||||
|
export const startButtinStateHandler = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
_options: Partial<ButtonControllerOpt> = {},
|
||||||
|
) => {
|
||||||
|
const options = makeOptions(_options);
|
||||||
|
const logger = makeLogger("btnc", options.debug);
|
||||||
|
logger.info(
|
||||||
|
"Starting Flic ButtonController with",
|
||||||
|
JSON.stringify(options, null, 4),
|
||||||
|
);
|
||||||
|
logger.info("Setting listeners...");
|
||||||
|
setListeners(ha, logger);
|
||||||
|
logger.info("Registering all buttons...");
|
||||||
|
const handleCreation = createHandleBtnCreation(ha, logger)("kickStart");
|
||||||
|
buttonModule.getButtons().forEach(handleCreation);
|
||||||
|
setInterval(() => {
|
||||||
|
logger.debug("Updating button state!");
|
||||||
|
buttonModule
|
||||||
|
.getButtons()
|
||||||
|
.forEach((btn) => publishButtonMetaByBdaddr(ha, btn.bdaddr, logger));
|
||||||
|
}, 3000);
|
||||||
|
logger.info("is up");
|
||||||
|
};
|
||||||
@@ -0,0 +1,255 @@
|
|||||||
|
import { Button } from "buttons";
|
||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
import { Logger } from "../Logger";
|
||||||
|
|
||||||
|
export const makeOptions = (
|
||||||
|
opt: Partial<ButtonControllerOpt>,
|
||||||
|
): ButtonControllerOpt => ({
|
||||||
|
debug: false,
|
||||||
|
...opt,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const genButtonUniqueId = (bdaddr: string): string =>
|
||||||
|
bdaddr.replace(/:/g, "_");
|
||||||
|
|
||||||
|
export type ButtonMqttEntity = FlicMqttPrefix & {
|
||||||
|
component: HAComponent;
|
||||||
|
additionalProps: Record<string, any>;
|
||||||
|
};
|
||||||
|
export type ButtonConstants = ReturnType<typeof getConstants>;
|
||||||
|
export type ButtonConstantsNames = keyof ButtonConstants;
|
||||||
|
export const getConstants = (ha: HAmqtt, bdaddr: string) => {
|
||||||
|
const uniqId = genButtonUniqueId(bdaddr);
|
||||||
|
const lifeline = ha.genFlicPrefixObject(uniqId, "lifeline");
|
||||||
|
const ready = ha.genFlicPrefixObject(uniqId, "ready");
|
||||||
|
const connected = ha.genFlicPrefixObject(uniqId, "connected");
|
||||||
|
const key_availability = [
|
||||||
|
{
|
||||||
|
payload_available: "ON",
|
||||||
|
payload_not_available: "unavailable",
|
||||||
|
topic: lifeline.mqttPrefix,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const availability = {
|
||||||
|
availability: [
|
||||||
|
...key_availability,
|
||||||
|
{
|
||||||
|
payload_available: "ON",
|
||||||
|
payload_not_available: "unavailable",
|
||||||
|
topic: ready.mqttPrefix,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
payload_available: "ON",
|
||||||
|
payload_not_available: "unavailable",
|
||||||
|
topic: connected.mqttPrefix,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
availability_mode: "all",
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
uniqId,
|
||||||
|
LIFELINE_SIGNAL: {
|
||||||
|
...lifeline,
|
||||||
|
component: "binary_sensor",
|
||||||
|
additionalProps: {
|
||||||
|
entity_category: "diagnostic",
|
||||||
|
expire_after: 5,
|
||||||
|
device_class: "connectivity",
|
||||||
|
name: "Button Controller Connected",
|
||||||
|
payload_not_available: "OFF",
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
|
||||||
|
signals: {
|
||||||
|
READY: {
|
||||||
|
...ready,
|
||||||
|
component: "binary_sensor",
|
||||||
|
additionalProps: {
|
||||||
|
entity_category: "diagnostic",
|
||||||
|
expire_after: 5,
|
||||||
|
device_class: "connectivity",
|
||||||
|
name: "Button Ready",
|
||||||
|
payload_not_available: "OFF",
|
||||||
|
availability: key_availability,
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
CONNECTED: {
|
||||||
|
...connected,
|
||||||
|
component: "binary_sensor",
|
||||||
|
additionalProps: {
|
||||||
|
entity_category: "diagnostic",
|
||||||
|
expire_after: 5,
|
||||||
|
device_class: "connectivity",
|
||||||
|
name: "Button Connected",
|
||||||
|
payload_not_available: "OFF",
|
||||||
|
availability: key_availability,
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
},
|
||||||
|
|
||||||
|
states: {
|
||||||
|
ACTION: {
|
||||||
|
...ha.genFlicPrefixObject(uniqId, "action"),
|
||||||
|
component: "sensor",
|
||||||
|
additionalProps: {
|
||||||
|
icon: "mdi:gesture-tap-button",
|
||||||
|
name: "Click Action",
|
||||||
|
availability,
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
STATE: {
|
||||||
|
...ha.genFlicPrefixObject(uniqId, "state"),
|
||||||
|
component: "sensor",
|
||||||
|
additionalProps: {
|
||||||
|
icon: "mdi:radiobox-indeterminate-variant",
|
||||||
|
availability,
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
BATTERY: {
|
||||||
|
...ha.genFlicPrefixObject(uniqId, "battery"),
|
||||||
|
component: "sensor",
|
||||||
|
additionalProps: {
|
||||||
|
expire_after: 5,
|
||||||
|
unit_of_measurement: "%",
|
||||||
|
device_class: "battery",
|
||||||
|
availability,
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
ACTIVE_DISCONNECT: {
|
||||||
|
...ha.genFlicPrefixObject(uniqId, "activeDisconnect"),
|
||||||
|
component: "binary_sensor",
|
||||||
|
additionalProps: {
|
||||||
|
entity_category: "config",
|
||||||
|
expire_after: 5,
|
||||||
|
name: "Explicitly disconnected button by user",
|
||||||
|
availability,
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
SHORT_PRESS: {
|
||||||
|
...ha.genFlicPrefixObject(uniqId, "button_short_press"),
|
||||||
|
component: "device_automation",
|
||||||
|
additionalProps: {
|
||||||
|
type: "button_short_press",
|
||||||
|
subtype: "button_1",
|
||||||
|
automation_type: "trigger",
|
||||||
|
payload: "button_short_press",
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
LONG_PRESS: {
|
||||||
|
...ha.genFlicPrefixObject(uniqId, "button_long_press"),
|
||||||
|
component: "device_automation",
|
||||||
|
additionalProps: {
|
||||||
|
type: "button_long_press",
|
||||||
|
subtype: "button_1",
|
||||||
|
automation_type: "trigger",
|
||||||
|
payload: "button_long_press",
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
DOUBLE_PRESS: {
|
||||||
|
...ha.genFlicPrefixObject(uniqId, "button_double_press"),
|
||||||
|
component: "device_automation",
|
||||||
|
additionalProps: {
|
||||||
|
type: "button_double_press",
|
||||||
|
subtype: "button_1",
|
||||||
|
automation_type: "trigger",
|
||||||
|
payload: "button_double_press",
|
||||||
|
},
|
||||||
|
} as ButtonMqttEntity,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDeviceFromButton = (button: Button): HADevice => {
|
||||||
|
return {
|
||||||
|
name: button.name,
|
||||||
|
identifiers: [button.serialNumber, button.uuid],
|
||||||
|
manufacturer: "Flic",
|
||||||
|
model: `v${button.flicVersion}_${button.color.trim().length > 0 ? button.color : "white"}`,
|
||||||
|
sw_version: String(button.firmwareVersion),
|
||||||
|
hw_version: String(button.flicVersion),
|
||||||
|
serial_number: String(button.serialNumber),
|
||||||
|
configuration_url: "https://hubsdk.flic.io/",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
export const registerEntities = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
button: Button,
|
||||||
|
logger: Logger,
|
||||||
|
): ButtonConstants => {
|
||||||
|
const constants = getConstants(ha, button.bdaddr);
|
||||||
|
const haDevice = getDeviceFromButton(button);
|
||||||
|
logger.info(
|
||||||
|
"Registering",
|
||||||
|
JSON.stringify(
|
||||||
|
{ bdaddr: button.bdaddr, uniqId: constants.uniqId },
|
||||||
|
null,
|
||||||
|
4,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
ha.startLifeLine(
|
||||||
|
"Button Controller Connected",
|
||||||
|
constants.uniqId,
|
||||||
|
haDevice,
|
||||||
|
constants.LIFELINE_SIGNAL.objectId,
|
||||||
|
);
|
||||||
|
registerHAObjects(constants.actions, ha, constants.uniqId, haDevice, logger);
|
||||||
|
registerHAObjects(constants.signals, ha, constants.uniqId, haDevice, logger);
|
||||||
|
registerHAObjects(constants.states, ha, constants.uniqId, haDevice, logger);
|
||||||
|
return constants;
|
||||||
|
};
|
||||||
|
|
||||||
|
const registerHAObjects = (
|
||||||
|
objs: Record<string, ButtonMqttEntity>,
|
||||||
|
ha: HAmqtt,
|
||||||
|
uniqId: string,
|
||||||
|
haDevice: HADevice,
|
||||||
|
logger: Logger,
|
||||||
|
) => {
|
||||||
|
Object.keys(objs).forEach((k) => {
|
||||||
|
const o = objs[k];
|
||||||
|
logger.info(
|
||||||
|
"Registering",
|
||||||
|
JSON.stringify({ entity: k, objcetId: o.objectId, uniqId }, null, 4),
|
||||||
|
);
|
||||||
|
ha.registerEntity(
|
||||||
|
`Button ${o.objectId}`,
|
||||||
|
o.component,
|
||||||
|
uniqId,
|
||||||
|
o.objectId,
|
||||||
|
haDevice,
|
||||||
|
o.additionalProps,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deregisterButton = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
bdaddr: string,
|
||||||
|
logger: Logger,
|
||||||
|
) => {
|
||||||
|
const constants = getConstants(ha, bdaddr);
|
||||||
|
const uniqId = constants.uniqId;
|
||||||
|
logger.info("Deregistering", JSON.stringify({ bdaddr, uniqId }, null, 4));
|
||||||
|
deregisterHAObjects(constants.actions, ha, uniqId, logger);
|
||||||
|
deregisterHAObjects(constants.signals, ha, uniqId, logger);
|
||||||
|
deregisterHAObjects(constants.states, ha, uniqId, logger);
|
||||||
|
};
|
||||||
|
|
||||||
|
const deregisterHAObjects = (
|
||||||
|
objs: Record<string, ButtonMqttEntity>,
|
||||||
|
ha: HAmqtt,
|
||||||
|
uniqId: string,
|
||||||
|
logger: Logger,
|
||||||
|
) => {
|
||||||
|
Object.keys(objs).forEach((k) => {
|
||||||
|
const o = objs[k];
|
||||||
|
logger.info(
|
||||||
|
"Deregistering",
|
||||||
|
JSON.stringify({ entity: k, objcetId: o.objectId, uniqId }, null, 4),
|
||||||
|
);
|
||||||
|
ha.deregisterEntity(o.component, uniqId, o.objectId);
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
export type Button = {
|
|
||||||
bdaddr: string // Device address of button
|
|
||||||
serialNumber: string // Serial number
|
|
||||||
color: string // Colour of the button (lowercase)
|
|
||||||
name: string // The user assigned button name
|
|
||||||
activeDisconnect: boolean // The user has explicitly disconnected the button
|
|
||||||
connected: boolean // The connection to the button is currently established
|
|
||||||
ready: boolean // The connection is verified (see buttonReady)
|
|
||||||
batteryStatus: number | null // Battery level in percent (0-100), or null if unknown
|
|
||||||
batteryTimestamp: number | null // Last time the battery was updated
|
|
||||||
firmwareVersion: number | null // Firmware version of button, or null if unknown
|
|
||||||
flicVersion: number | null // Flic version (1 or 2)
|
|
||||||
uuid: string // A 32 characters long hex string, unique for every button
|
|
||||||
key: number | null // A 40 characters long hex string (only for Flic 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ButtonModule {
|
|
||||||
getButtons(): Button[],
|
|
||||||
getButton(bdaddr: string): Button,
|
|
||||||
on(ev: "buttonAdded", cb: (btn: Button) => void): void,
|
|
||||||
on(ev: "buttonUpdated", cb: (btn: Button) => void): void,
|
|
||||||
on(ev: "buttonDeleted", cb: (btn: Button) => void): void,
|
|
||||||
on(ev: "buttonConnected", cb: (btn: Button) => void): void,
|
|
||||||
on(ev: "buttonReady", cb: (obj: { bdaddr: string }) => void): void,
|
|
||||||
on(ev: "buttonDisconnected", cb: (obj: { bdaddr: string }) => void): void,
|
|
||||||
on(ev: "buttonDown", cb: (obj: { bdaddr: string }) => void): void,
|
|
||||||
on(ev: "buttonUp", cb: (obj: { bdaddr: string }) => void): void,
|
|
||||||
on(ev: "buttonClickOrHold", cb: (obj: { bdaddr: string, isClick: boolean, isHold: boolean }) => void): void,
|
|
||||||
on(ev: "buttonSingleOrDoubleClick", cb: (obj: { bdaddr: string, isSingleClick: boolean, isDoubleClick: boolean }) => void): void,
|
|
||||||
on(ev: "buttonSingleOrDoubleClickOrHold", cb: (obj: { bdaddr: string, isSingleClick: boolean, isDoubleClick: boolean, isHold: boolean }) => void): void,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IRModule {
|
|
||||||
record(): void;
|
|
||||||
cancelRecord(): void;
|
|
||||||
play(arr: Uint32Array, cb: (err: any | undefined) => void): void;
|
|
||||||
on(ev: 'recordComplete', cb: (d: Uint32Array) => void): void;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
import { makeLogger } from "../Logger";
|
||||||
|
import { FlicMQTT } from "../mqtt_client/index";
|
||||||
|
import { makeOptions } from "./utils";
|
||||||
|
|
||||||
|
export type HAmqtt = ReturnType<typeof makeHAmqtt>;
|
||||||
|
export function makeHAmqtt(
|
||||||
|
mqttServer: FlicMQTT,
|
||||||
|
_options: Partial<HAmqttOptions> = {},
|
||||||
|
) {
|
||||||
|
const options = makeOptions(_options);
|
||||||
|
const logger = makeLogger("mqtt:ha", options.debug);
|
||||||
|
logger.info("starting...", JSON.stringify(options, null, 4));
|
||||||
|
const genFlicPrefix = (nodeId: string, objectId: string): string => {
|
||||||
|
return `${options.topics.flic}/${nodeId}/${objectId}`;
|
||||||
|
};
|
||||||
|
const genFlicPrefixObject = (
|
||||||
|
nodeId: string,
|
||||||
|
objectId: string,
|
||||||
|
): FlicMqttPrefix => ({
|
||||||
|
nodeId,
|
||||||
|
objectId,
|
||||||
|
mqttPrefix: genFlicPrefix(nodeId, objectId),
|
||||||
|
});
|
||||||
|
|
||||||
|
const genHAPrefix = (
|
||||||
|
component: HAComponent,
|
||||||
|
nodeId: string,
|
||||||
|
objectId: string,
|
||||||
|
) => {
|
||||||
|
return `${options.topics.homeassistant}/${component}/${nodeId}/${objectId}`;
|
||||||
|
};
|
||||||
|
const publishStateFromObject = (
|
||||||
|
obj: FlicMqttPrefix,
|
||||||
|
state: any,
|
||||||
|
opt: MQTTPublishOpt = {},
|
||||||
|
) => {
|
||||||
|
mqttServer.publish(obj.mqttPrefix, state + "", opt);
|
||||||
|
logger.debug(JSON.stringify({ obj, state, opt }));
|
||||||
|
};
|
||||||
|
const publishState = (
|
||||||
|
nodeId: string,
|
||||||
|
objectId: string,
|
||||||
|
state: any,
|
||||||
|
opt: MQTTPublishOpt = {},
|
||||||
|
) => {
|
||||||
|
const topic = genFlicPrefix(nodeId, objectId);
|
||||||
|
mqttServer.publish(topic, state + "", opt);
|
||||||
|
logger.debug(topic, state, JSON.stringify(opt));
|
||||||
|
};
|
||||||
|
const registerEntity = (
|
||||||
|
name: string,
|
||||||
|
component: HAComponent,
|
||||||
|
nodeId: string,
|
||||||
|
objectId: string,
|
||||||
|
device: HADevice,
|
||||||
|
additionalProps: {
|
||||||
|
topic?: string;
|
||||||
|
state_topic?: string;
|
||||||
|
} & {
|
||||||
|
[key: string]: any;
|
||||||
|
} = {},
|
||||||
|
) => {
|
||||||
|
const configtopic = genHAPrefix(component, nodeId, objectId) + "/config";
|
||||||
|
if (component === "device_automation") {
|
||||||
|
additionalProps.topic = genFlicPrefix(nodeId, objectId);
|
||||||
|
} else {
|
||||||
|
additionalProps.state_topic = genFlicPrefix(nodeId, objectId);
|
||||||
|
}
|
||||||
|
const configObj = {
|
||||||
|
name,
|
||||||
|
...additionalProps,
|
||||||
|
unique_id: `Flic_${nodeId}_${objectId}`,
|
||||||
|
device,
|
||||||
|
};
|
||||||
|
mqttServer.publish(configtopic, JSON.stringify(configObj), {
|
||||||
|
retain: true,
|
||||||
|
});
|
||||||
|
logger.debug(configtopic, JSON.stringify(configObj, null, 4));
|
||||||
|
};
|
||||||
|
|
||||||
|
const deregisterEntity = (
|
||||||
|
component: HAComponent,
|
||||||
|
nodeId: string,
|
||||||
|
objectId: string,
|
||||||
|
) => {
|
||||||
|
const configtopic = genHAPrefix(component, nodeId, objectId) + "/config";
|
||||||
|
// mqttServer.publish(configtopic, null, { retain: false });
|
||||||
|
logger.debug(configtopic, null);
|
||||||
|
};
|
||||||
|
const startLifeLine = (
|
||||||
|
name: string,
|
||||||
|
nodeId: string,
|
||||||
|
haDevice: HADevice,
|
||||||
|
topic: string = "lifeline",
|
||||||
|
) => {
|
||||||
|
registerEntity(name, "binary_sensor", nodeId, topic, haDevice, {
|
||||||
|
device_class: "connectivity",
|
||||||
|
expire_after: 5,
|
||||||
|
off_delay: 3,
|
||||||
|
entity_category: "diagnostic",
|
||||||
|
payload_available: "ON",
|
||||||
|
payload_not_available: "OFF",
|
||||||
|
});
|
||||||
|
setInterval(() => {
|
||||||
|
publishState(nodeId, topic, "ON");
|
||||||
|
}, 2500);
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
deregisterEntity,
|
||||||
|
registerEntity,
|
||||||
|
publishState,
|
||||||
|
publishStateFromObject,
|
||||||
|
genFlicPrefix,
|
||||||
|
genFlicPrefixObject,
|
||||||
|
startLifeLine,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
export const makeOptions = (opt: Partial<HAmqttOptions>): HAmqttOptions => ({
|
||||||
|
debug: false,
|
||||||
|
...opt,
|
||||||
|
topics: {
|
||||||
|
homeassistant: "homeassistant",
|
||||||
|
flic: "flic",
|
||||||
|
...opt.topics,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
import { makeLogger } from "../Logger";
|
||||||
|
import { FlicMQTT } from "../mqtt_client/index";
|
||||||
|
import flichub from "flicapp";
|
||||||
|
import {
|
||||||
|
makeOptions,
|
||||||
|
getHADevice,
|
||||||
|
getConstants,
|
||||||
|
FlicHubConstants,
|
||||||
|
} from "./utils";
|
||||||
|
import { virtualDeviceUpdateHandler } from "./virtual_device_update";
|
||||||
|
|
||||||
|
export const startFlicHubController = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
mqtt: FlicMQTT,
|
||||||
|
_options: Partial<FlicHubOptions> = {},
|
||||||
|
) => {
|
||||||
|
const options = makeOptions(_options);
|
||||||
|
const logger = makeLogger("flichub", options.debug);
|
||||||
|
const haDevice = getHADevice(options);
|
||||||
|
const constants: FlicHubConstants = getConstants(ha, options);
|
||||||
|
const availability = [
|
||||||
|
{
|
||||||
|
payload_available: "ON",
|
||||||
|
payload_not_available: "unavailable",
|
||||||
|
topic: constants.LIFELINE_SIGNAL.mqttPrefix,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
logger.info("starting...");
|
||||||
|
logger.debug("setting up entities...");
|
||||||
|
ha.startLifeLine(
|
||||||
|
"FlicHub Connected",
|
||||||
|
constants.NODE_ID,
|
||||||
|
haDevice,
|
||||||
|
constants.LIFELINE_SIGNAL.objectId,
|
||||||
|
);
|
||||||
|
ha.registerEntity(
|
||||||
|
"Action Message",
|
||||||
|
"sensor",
|
||||||
|
constants.NODE_ID,
|
||||||
|
constants.MESSAGE.objectId,
|
||||||
|
haDevice,
|
||||||
|
{
|
||||||
|
icon: "mdi:message",
|
||||||
|
availability,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
ha.publishState(constants.NODE_ID, constants.MESSAGE.objectId, "");
|
||||||
|
|
||||||
|
flichub.on("actionMessage", (obj) => {
|
||||||
|
ha.publishState(constants.NODE_ID, constants.MESSAGE.objectId, obj);
|
||||||
|
});
|
||||||
|
flichub.on("virtualDeviceUpdate", (update) =>
|
||||||
|
virtualDeviceUpdateHandler(
|
||||||
|
ha,
|
||||||
|
logger,
|
||||||
|
haDevice,
|
||||||
|
constants.NODE_ID,
|
||||||
|
update,
|
||||||
|
constants.COMMAND_TOPIC(update.metaData.virtualDeviceId),
|
||||||
|
availability,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import hubinfo from "hubinfo";
|
||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
|
||||||
|
const NODE_ID = "FlicHub";
|
||||||
|
|
||||||
|
export const makeOptions = (opt: Partial<FlicHubOptions>): FlicHubOptions => ({
|
||||||
|
debug: false,
|
||||||
|
uniqueId: "0",
|
||||||
|
...opt,
|
||||||
|
});
|
||||||
|
export const getHADevice = (options: FlicHubOptions): HADevice => ({
|
||||||
|
name: `FlicHub (${options.uniqueId})`,
|
||||||
|
manufacturer: "Flic",
|
||||||
|
model: `${NODE_ID}${options.uniqueId}`,
|
||||||
|
identifiers: ["FlicHub"],
|
||||||
|
configuration_url: "https://hubsdk.flic.io/",
|
||||||
|
sw_version: hubinfo.firmwareVersion,
|
||||||
|
serial_number: hubinfo.serialNumber,
|
||||||
|
});
|
||||||
|
export type FlicHubConstants = ReturnType<typeof getConstants>;
|
||||||
|
export type FlicHubConstantsNames = keyof FlicHubConstants;
|
||||||
|
export const getConstants = (ha: HAmqtt, options: FlicHubOptions) => {
|
||||||
|
const nodeId = `${NODE_ID}${options.uniqueId}`;
|
||||||
|
return {
|
||||||
|
NODE_ID: nodeId,
|
||||||
|
LIFELINE_SIGNAL: ha.genFlicPrefixObject(nodeId, "lifeline"),
|
||||||
|
MESSAGE: ha.genFlicPrefixObject(nodeId, "action-message"),
|
||||||
|
COMMAND_TOPIC: (virtualId: string) =>
|
||||||
|
ha.genFlicPrefixObject(nodeId, `virt-command-${virtualId}`),
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import {
|
||||||
|
VirtualDeviceMetaData,
|
||||||
|
VirtualDeviceType,
|
||||||
|
VirtualDeviceUpdate,
|
||||||
|
} from "flicapp";
|
||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
import { Logger } from "../Logger";
|
||||||
|
|
||||||
|
const genVirtualDeviceObjectId = ({
|
||||||
|
virtualDeviceId,
|
||||||
|
dimmableType,
|
||||||
|
}: VirtualDeviceMetaData) =>
|
||||||
|
`virt-${dimmableType}-${virtualDeviceId}`.toLowerCase();
|
||||||
|
|
||||||
|
const VirtualDeviceType2HAComponent: Record<VirtualDeviceType, HAComponent> = {
|
||||||
|
Blind: "cover",
|
||||||
|
Light: "light",
|
||||||
|
Speaker: "media_player",
|
||||||
|
};
|
||||||
|
|
||||||
|
const convertStateUpdate2HA = (update: VirtualDeviceUpdate) => {
|
||||||
|
if (update.metaData.dimmableType === "Light") {
|
||||||
|
if (update.values.brightness) {
|
||||||
|
return {
|
||||||
|
brightness: Math.floor(update.values.brightness * 255),
|
||||||
|
state: update.values.brightness > 0 ? "ON" : "OFF",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (update.values.colorTemperature) {
|
||||||
|
return {
|
||||||
|
color_temp: Math.floor(update.values.colorTemperature * 255),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error(`${update} is not supported at the moment!`);
|
||||||
|
};
|
||||||
|
export const virtualDeviceUpdateHandler = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
logger: Logger,
|
||||||
|
haDevice: HADevice,
|
||||||
|
nodeId: string,
|
||||||
|
update: VirtualDeviceUpdate,
|
||||||
|
commandTopic: FlicMqttPrefix,
|
||||||
|
availability: any,
|
||||||
|
) => {
|
||||||
|
const objectId = genVirtualDeviceObjectId(update.metaData);
|
||||||
|
const mqttPrefix = ha.genFlicPrefixObject(nodeId, objectId);
|
||||||
|
logger.info(`Handling update for ${update} on ${haDevice}`);
|
||||||
|
ha.registerEntity(
|
||||||
|
update.metaData.virtualDeviceId,
|
||||||
|
VirtualDeviceType2HAComponent[update.metaData.dimmableType],
|
||||||
|
mqttPrefix.nodeId,
|
||||||
|
mqttPrefix.objectId,
|
||||||
|
haDevice,
|
||||||
|
{ availability, command_topic: commandTopic },
|
||||||
|
);
|
||||||
|
ha.publishState(mqttPrefix.nodeId, mqttPrefix.objectId, {
|
||||||
|
brightness: update.values.brightness * 255,
|
||||||
|
});
|
||||||
|
};
|
||||||
+28
-49
@@ -1,76 +1,55 @@
|
|||||||
import {ButtonControllerOpt, makeButtonController} from "./ButtonController";
|
import { makeHAmqtt } from "./ha_mqtt/index";
|
||||||
import {HAmqttOptions, makeHAmqtt} from './HAmqtt';
|
import { startIRController } from "./ir_controller/index";
|
||||||
import {IRControllerOpt, makeIRController} from "./IRController";
|
|
||||||
import {makeLogger} from "./Logger";
|
|
||||||
import {ButtonModule, IRModule} from './flicTypes';
|
|
||||||
import * as mqtt from './mqtt';
|
|
||||||
|
|
||||||
export type MQTTOpt = {
|
import { makeLogger } from "./Logger";
|
||||||
host: string;
|
import { FlicMQTT } from "./mqtt_client/index";
|
||||||
port: number;
|
import { startFlicHubController } from "./hub_controller/index";
|
||||||
client_id: string;
|
import { startButtinStateHandler } from "./button_controller/index";
|
||||||
keep_alive: boolean;
|
|
||||||
clean_session: boolean;
|
export const start = (options: Options) => {
|
||||||
username: string;
|
const mqttServer = new FlicMQTT(options.mqtt.host, {
|
||||||
password: string;
|
...options.mqtt,
|
||||||
}
|
keep_alive: true,
|
||||||
export type Options = {
|
});
|
||||||
mqtt: Partial<MQTTOpt> & { host: string };
|
const logger = makeLogger("root", options.debug ?? false);
|
||||||
debug?: boolean;
|
|
||||||
ha?: Partial<HAmqttOptions>;
|
|
||||||
flicBtns?: Partial<ButtonControllerOpt> & { disabled?: boolean };
|
|
||||||
flicIR?: Partial<IRControllerOpt> & { disabled?: boolean };
|
|
||||||
}
|
|
||||||
export const start = (
|
|
||||||
buttonModule: ButtonModule,
|
|
||||||
irModule: IRModule,
|
|
||||||
options: Options,
|
|
||||||
) => {
|
|
||||||
const mqttServer = mqtt.create(
|
|
||||||
options.mqtt.host,
|
|
||||||
{...options.mqtt, keep_alive: true},
|
|
||||||
);
|
|
||||||
const logger = makeLogger('root', options.debug ?? false);
|
|
||||||
options.ha = options.ha ?? {};
|
options.ha = options.ha ?? {};
|
||||||
options.flicBtns = options.flicBtns ?? {};
|
options.flicBtns = options.flicBtns ?? {};
|
||||||
options.flicIR = options.flicIR ?? {};
|
options.flicIR = options.flicIR ?? {};
|
||||||
|
options.flicHub = options.flicHub ?? {};
|
||||||
options.ha.debug = options.ha.debug ?? options.debug ?? false;
|
options.ha.debug = options.ha.debug ?? options.debug ?? false;
|
||||||
options.flicBtns.debug = options.flicBtns.debug ?? options.debug ?? false;
|
options.flicBtns.debug = options.flicBtns.debug ?? options.debug ?? false;
|
||||||
options.flicIR.debug = options.flicIR.debug ?? options.debug ?? false;
|
options.flicIR.debug = options.flicIR.debug ?? options.debug ?? false;
|
||||||
|
options.flicHub.debug = options.flicHub.debug ?? options.debug ?? false;
|
||||||
const ha = makeHAmqtt(mqttServer, options.ha);
|
const ha = makeHAmqtt(mqttServer, options.ha);
|
||||||
mqttServer.on('connected', () => {
|
mqttServer.on("connected", () => {
|
||||||
logger.info("connected to mqtt");
|
logger.info("connected to mqtt");
|
||||||
if (!options.flicBtns?.disabled) {
|
if (!options.flicBtns?.disabled) {
|
||||||
makeButtonController(
|
startButtinStateHandler(ha, options.flicBtns);
|
||||||
ha, buttonModule, options.flicBtns,
|
|
||||||
).start();
|
|
||||||
}
|
}
|
||||||
if (!options.flicIR?.disabled) {
|
if (!options.flicIR?.disabled) {
|
||||||
makeIRController(
|
startIRController(ha, mqttServer, options.flicIR);
|
||||||
irModule,
|
}
|
||||||
ha,
|
if (!options.flicHub?.disabled) {
|
||||||
mqttServer,
|
startFlicHubController(ha, mqttServer, options.flicHub);
|
||||||
options.flicIR,
|
|
||||||
).start();
|
|
||||||
}
|
}
|
||||||
logger.info("all services up!");
|
logger.info("all services up!");
|
||||||
});
|
});
|
||||||
mqttServer.on('error', function (err) {
|
mqttServer.on("error", function (err) {
|
||||||
logger.info("'Error' event", JSON.stringify(err));
|
logger.info("'Error' event", JSON.stringify(err));
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
throw new Error("Crashed");
|
throw new Error("Crashed");
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
mqttServer.on("disconnected", function (err) {
|
mqttServer.on("disconnected", function () {
|
||||||
logger.info("'Error' disconnected", JSON.stringify(err));
|
logger.info("Lost access - disconnected");
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
throw new Error("Crashed");
|
throw new Error("disconnected");
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
mqttServer.on("close", function (err) {
|
mqttServer.on("close", function () {
|
||||||
logger.info("'Error' close", JSON.stringify(err));
|
logger.info("Lost access - close");
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
throw new Error("Crashed");
|
throw new Error("closed");
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
mqttServer.connect();
|
mqttServer.connect();
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
import { IRState } from "./state";
|
||||||
|
import { IRConstants } from "./utils";
|
||||||
|
|
||||||
|
export const registerEntities = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
haDevice: HADevice,
|
||||||
|
constants: IRConstants,
|
||||||
|
) => {
|
||||||
|
const {
|
||||||
|
NODE_ID,
|
||||||
|
LIFELINE_SIGNAL,
|
||||||
|
RECORD_SIGNAL,
|
||||||
|
RECORD_SIGNAL_SET,
|
||||||
|
PLAY_SIGNAL,
|
||||||
|
PLAY_SIGNAL_SET,
|
||||||
|
DELETE_SIGNAL,
|
||||||
|
DELETE_SIGNAL_CMD,
|
||||||
|
availability,
|
||||||
|
} = constants;
|
||||||
|
ha.startLifeLine(
|
||||||
|
"IR Connnected",
|
||||||
|
NODE_ID,
|
||||||
|
haDevice,
|
||||||
|
LIFELINE_SIGNAL.objectId,
|
||||||
|
);
|
||||||
|
ha.registerEntity(
|
||||||
|
"Record Signal",
|
||||||
|
"switch",
|
||||||
|
NODE_ID,
|
||||||
|
RECORD_SIGNAL.objectId,
|
||||||
|
haDevice,
|
||||||
|
{
|
||||||
|
icon: "mdi:record-rec",
|
||||||
|
command_topic: RECORD_SIGNAL_SET.mqttPrefix,
|
||||||
|
device_class: "switch",
|
||||||
|
availability,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
ha.registerEntity(
|
||||||
|
"Play Signal",
|
||||||
|
"button",
|
||||||
|
NODE_ID,
|
||||||
|
PLAY_SIGNAL.objectId,
|
||||||
|
haDevice,
|
||||||
|
{
|
||||||
|
icon: "mdi:play",
|
||||||
|
command_topic: PLAY_SIGNAL_SET.mqttPrefix,
|
||||||
|
availability,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
ha.registerEntity(
|
||||||
|
"Delete Signal",
|
||||||
|
"button",
|
||||||
|
NODE_ID,
|
||||||
|
DELETE_SIGNAL.objectId,
|
||||||
|
haDevice,
|
||||||
|
{
|
||||||
|
icon: "mdi:delete",
|
||||||
|
command_topic: DELETE_SIGNAL_CMD.mqttPrefix,
|
||||||
|
availability,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const registerSelect = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
haDevice: HADevice,
|
||||||
|
state: IRState,
|
||||||
|
{ NODE_ID, RECORD_SIGNAL, RECORDED_SIGNALS_CMD, availability }: IRConstants,
|
||||||
|
onDone: () => void = () => {},
|
||||||
|
) => {
|
||||||
|
state.signalStore.withDataIndexed((data) => {
|
||||||
|
ha.registerEntity(
|
||||||
|
"Recorded Signals",
|
||||||
|
"select",
|
||||||
|
NODE_ID,
|
||||||
|
RECORD_SIGNAL.objectId,
|
||||||
|
haDevice,
|
||||||
|
{
|
||||||
|
command_topic: RECORDED_SIGNALS_CMD.mqttPrefix,
|
||||||
|
icon: "mdi:broadcast",
|
||||||
|
max: 500,
|
||||||
|
availability,
|
||||||
|
options: data.map(({ name }) => String(name)),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
onDone();
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
import { makeLogger } from "../Logger";
|
||||||
|
import { FlicMQTT } from "../mqtt_client/index";
|
||||||
|
import { IRConstants, NODE_ID, getConstants, makeOptions } from "./utils";
|
||||||
|
import { registerEntities, registerSelect } from "./entity_controller";
|
||||||
|
import { irMQTTHandler as handleMqttIREvents } from "./mqtt_handler";
|
||||||
|
import { handleIREvents } from "./ir_handler";
|
||||||
|
import { makeIRSharedState } from "./state";
|
||||||
|
|
||||||
|
export const startIRController = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
mqtt: FlicMQTT,
|
||||||
|
_options: Partial<IRControllerOpt> = {},
|
||||||
|
) => {
|
||||||
|
const options = makeOptions(_options);
|
||||||
|
const logger = makeLogger("ir", options.debug);
|
||||||
|
const haDevice: HADevice = {
|
||||||
|
name: "IR",
|
||||||
|
manufacturer: "Flic",
|
||||||
|
model: `${NODE_ID}${options.uniqueId}`,
|
||||||
|
identifiers: ["FlicHubIR"],
|
||||||
|
configuration_url: "https://hubsdk.flic.io/",
|
||||||
|
};
|
||||||
|
const constants: IRConstants = getConstants(ha, options);
|
||||||
|
const nodeId = constants.NODE_ID;
|
||||||
|
|
||||||
|
const state = makeIRSharedState(logger);
|
||||||
|
|
||||||
|
logger.info("starting...");
|
||||||
|
logger.debug("setting up entities...");
|
||||||
|
registerEntities(ha, haDevice, constants);
|
||||||
|
registerSelect(ha, haDevice, state, constants);
|
||||||
|
logger.debug("setting default states....");
|
||||||
|
ha.publishState(nodeId, constants.RECORD_SIGNAL.objectId, "OFF");
|
||||||
|
ha.publishState(nodeId, constants.PLAY_SIGNAL.objectId, "OFF");
|
||||||
|
logger.debug("registering events");
|
||||||
|
handleMqttIREvents(
|
||||||
|
mqtt,
|
||||||
|
ha,
|
||||||
|
nodeId,
|
||||||
|
logger,
|
||||||
|
state,
|
||||||
|
constants,
|
||||||
|
(onDone: () => void) =>
|
||||||
|
registerSelect(ha, haDevice, state, constants, onDone),
|
||||||
|
);
|
||||||
|
handleIREvents(ha, logger, nodeId, state, constants, (onDone: () => void) =>
|
||||||
|
registerSelect(ha, haDevice, state, constants, onDone),
|
||||||
|
);
|
||||||
|
logger.debug("subscribing to", constants.set_topics);
|
||||||
|
mqtt.subscribe(constants.set_topics);
|
||||||
|
logger.info("is up");
|
||||||
|
};
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import ir from "ir";
|
||||||
|
import { Logger } from "../Logger";
|
||||||
|
import { IRConstants, convertUint32Array2Str } from "./utils";
|
||||||
|
|
||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
import { IRState } from "./state";
|
||||||
|
|
||||||
|
export const handleIREvents = (
|
||||||
|
ha: HAmqtt,
|
||||||
|
logger: Logger,
|
||||||
|
nodeId: string,
|
||||||
|
state: IRState,
|
||||||
|
{ RECORD_SIGNAL, RECORDED_SIGNALS }: IRConstants,
|
||||||
|
reloadSelectableSignals: (onDone: () => void) => void,
|
||||||
|
) => {
|
||||||
|
ir.on("recordComplete", (data) => {
|
||||||
|
logger.info("recordComplete", data);
|
||||||
|
if (data.length === 0) {
|
||||||
|
logger.error("Failed to record any data");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const stringMessage = convertUint32Array2Str(data);
|
||||||
|
logger.info(
|
||||||
|
"recording completed with",
|
||||||
|
JSON.stringify({
|
||||||
|
stringMessage,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
state.signalStore.add(stringMessage, (idx) => {
|
||||||
|
reloadSelectableSignals(() => {
|
||||||
|
ha.publishState(nodeId, RECORDED_SIGNALS.objectId, String(idx), {
|
||||||
|
retain: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
state.setRecordingState(false);
|
||||||
|
ha.publishState(nodeId, RECORD_SIGNAL.objectId, "OFF");
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
import ir from "ir";
|
||||||
|
import { Logger } from "../Logger";
|
||||||
|
import { FlicMQTT } from "../mqtt_client/index";
|
||||||
|
import { IRConstants, convertStr2Uint32Array } from "./utils";
|
||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
import { IRState } from "./state";
|
||||||
|
|
||||||
|
export const irMQTTHandler = (
|
||||||
|
mqtt: FlicMQTT,
|
||||||
|
ha: HAmqtt,
|
||||||
|
nodeId: string,
|
||||||
|
logger: Logger,
|
||||||
|
state: IRState,
|
||||||
|
{
|
||||||
|
RECORD_SIGNAL_SET,
|
||||||
|
RECORDED_SIGNALS_CMD,
|
||||||
|
PLAY_SIGNAL_SET,
|
||||||
|
DELETE_SIGNAL_CMD,
|
||||||
|
|
||||||
|
RECORD_SIGNAL,
|
||||||
|
}: IRConstants,
|
||||||
|
reloadSelectableSignals: (onDone: () => void) => void,
|
||||||
|
) => {
|
||||||
|
logger.info(`Registering ir mqtt handler ${nodeId} `);
|
||||||
|
mqtt.on("message", (topic, message) => {
|
||||||
|
logger.info(
|
||||||
|
"message:",
|
||||||
|
JSON.stringify({
|
||||||
|
topic,
|
||||||
|
message,
|
||||||
|
state,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if (topic === RECORD_SIGNAL_SET.mqttPrefix) {
|
||||||
|
logger.info(`IR module is being set to ${message}`);
|
||||||
|
if (!state.isRecording()) {
|
||||||
|
ir.record();
|
||||||
|
state.setRecordingState(true);
|
||||||
|
logger.info(`Started recording...`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (message === "OFF" && state.isRecording()) {
|
||||||
|
logger.info(`Attempting to stop recording...`);
|
||||||
|
try {
|
||||||
|
ir.cancelRecord();
|
||||||
|
state.setRecordingState(false);
|
||||||
|
logger.info(`Recording stopped!`);
|
||||||
|
return;
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(
|
||||||
|
`Failed to stop record, check you have the latest version of the sdk!`,
|
||||||
|
);
|
||||||
|
state.setRecordingState(true);
|
||||||
|
ha.publishState(nodeId, RECORD_SIGNAL.objectId, "OFF", {
|
||||||
|
dup: false,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.info(`Doing nothing state.isRecording()=${state.isRecording()}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (topic === RECORDED_SIGNALS_CMD.mqttPrefix) {
|
||||||
|
logger.info(`Updating internal signal state to ${message}`);
|
||||||
|
state.signalStore.setSelection(message, () => {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (topic === PLAY_SIGNAL_SET.mqttPrefix) {
|
||||||
|
return state.signalStore.withData((signals, currentSelection) => {
|
||||||
|
if (currentSelection === null) {
|
||||||
|
logger.error(
|
||||||
|
`currentSelection=${currentSelection} cannot be played!`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (currentSelection >= signals.length) {
|
||||||
|
logger.error(
|
||||||
|
`currentSelection=${currentSelection} >= signals.length=${signals.length} cannot be played!`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const currentSignal = signals[currentSelection];
|
||||||
|
let arr: Uint32Array | null = null;
|
||||||
|
try {
|
||||||
|
arr = convertStr2Uint32Array(currentSignal);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error("invalid string signal set", JSON.stringify(err), err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return ir.play(arr, (err) => {
|
||||||
|
if (err) {
|
||||||
|
logger.error("failed to play signal", JSON.stringify(err), err);
|
||||||
|
} else {
|
||||||
|
logger.debug("signal played!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (topic === DELETE_SIGNAL_CMD.mqttPrefix) {
|
||||||
|
return state.signalStore.removeCurrent(() =>
|
||||||
|
reloadSelectableSignals(() =>
|
||||||
|
logger.info(`Successfully removed Current Selection!`),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
logger.error(
|
||||||
|
`Invalid topic recieved from mqtt ${JSON.stringify({ topic, message })}`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
import datastore from "datastore";
|
||||||
|
import { Logger } from "../Logger";
|
||||||
|
import { generateRandomKeyNotInList } from "./utils";
|
||||||
|
export type IRRecordedSignal = string;
|
||||||
|
export type SavedIRRecordedSignal = {
|
||||||
|
name: string;
|
||||||
|
signal: IRRecordedSignal;
|
||||||
|
};
|
||||||
|
export type IRStoredCache = {
|
||||||
|
currentSelection: string | null;
|
||||||
|
signals: Record<string, IRRecordedSignal>;
|
||||||
|
};
|
||||||
|
export type IRSignalStoreCallback = {
|
||||||
|
(err: Error, data: null): void;
|
||||||
|
(err: null, data: IRStoredCache): void;
|
||||||
|
};
|
||||||
|
export class IRSignalStore {
|
||||||
|
private internalCacheStore: IRStoredCache | null = null;
|
||||||
|
constructor(
|
||||||
|
private logger: Logger,
|
||||||
|
private storeCacheKey = "flic2hass:ir:signals",
|
||||||
|
) {
|
||||||
|
this.reloadLocalCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadLocalCache(cb: IRSignalStoreCallback = () => {}) {
|
||||||
|
this.getValues((err, data) => {
|
||||||
|
if (err) {
|
||||||
|
return cb(err, null);
|
||||||
|
}
|
||||||
|
if (data) {
|
||||||
|
this.internalCacheStore = data;
|
||||||
|
return cb(null, data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getValues(cb: IRSignalStoreCallback) {
|
||||||
|
return datastore.get(this.storeCacheKey, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
return cb(err, null);
|
||||||
|
}
|
||||||
|
if (!data) {
|
||||||
|
return cb(null, {
|
||||||
|
currentSelection: null,
|
||||||
|
signals: {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return cb(null, JSON.parse(data));
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error(
|
||||||
|
`Failed to parse json defaulting to empty -> data=${data} err=${err}`,
|
||||||
|
);
|
||||||
|
return cb(null, {
|
||||||
|
currentSelection: null,
|
||||||
|
signals: {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
withData(
|
||||||
|
cb: (
|
||||||
|
signals: IRStoredCache["signals"],
|
||||||
|
currentSelection: IRStoredCache["currentSelection"],
|
||||||
|
) => void,
|
||||||
|
) {
|
||||||
|
if (this.internalCacheStore) {
|
||||||
|
cb(
|
||||||
|
this.internalCacheStore["signals"],
|
||||||
|
this.internalCacheStore["currentSelection"],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.reloadLocalCache((err, data) => {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (!data) {
|
||||||
|
throw new Error("failed to get data");
|
||||||
|
}
|
||||||
|
return cb(data["signals"], data["currentSelection"]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
withDataIndexed(
|
||||||
|
cb: (
|
||||||
|
data: SavedIRRecordedSignal[],
|
||||||
|
currentSelection: IRStoredCache["currentSelection"],
|
||||||
|
) => void,
|
||||||
|
) {
|
||||||
|
this.withData((signals, currentSelection) => {
|
||||||
|
cb(
|
||||||
|
Object.keys(signals).map((k) => ({
|
||||||
|
name: k,
|
||||||
|
signal: signals[k],
|
||||||
|
})),
|
||||||
|
currentSelection,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelection(
|
||||||
|
selection: string,
|
||||||
|
cb: (s: IRStoredCache["currentSelection"]) => void,
|
||||||
|
) {
|
||||||
|
this.withData((signals) => {
|
||||||
|
if (signals[selection]) {
|
||||||
|
this.persist({
|
||||||
|
signals,
|
||||||
|
currentSelection: selection,
|
||||||
|
});
|
||||||
|
return cb(selection);
|
||||||
|
}
|
||||||
|
this.logger.error(
|
||||||
|
`Not setting currentSelection to ${selection} as data.keys=${Object.keys(signals)}, consider reloading or deleting the entity in home-assistant.`,
|
||||||
|
);
|
||||||
|
this.persist({
|
||||||
|
signals,
|
||||||
|
currentSelection: null,
|
||||||
|
});
|
||||||
|
return cb(null);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
add(signal: string, cb: (name: string) => void) {
|
||||||
|
this.withData((signals, currentSelection) => {
|
||||||
|
const randomName = generateRandomKeyNotInList(Object.keys(signals));
|
||||||
|
signals[randomName] = signal;
|
||||||
|
this.persist({ signals, currentSelection });
|
||||||
|
cb(randomName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(name: string, cb: () => void) {
|
||||||
|
this.withData((signals, currentSelection) => {
|
||||||
|
delete signals[name];
|
||||||
|
this.persist({ signals, currentSelection });
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
removeCurrent(cb: () => void) {
|
||||||
|
this.withData((signals, currentSelection) => {
|
||||||
|
if (currentSelection === null) {
|
||||||
|
this.logger.error(
|
||||||
|
`Not removing ${currentSelection} as it is null, consider reloading or deleting the entity in home-assistant.`,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delete signals[currentSelection];
|
||||||
|
this.persist({ signals, currentSelection: null });
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private persist(data: IRStoredCache) {
|
||||||
|
this.internalCacheStore = data;
|
||||||
|
datastore.put(this.storeCacheKey, JSON.stringify(this.internalCacheStore));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type IRState = ReturnType<typeof makeIRSharedState>;
|
||||||
|
export const makeIRSharedState = (logger: Logger) => {
|
||||||
|
let isRecording: boolean = false;
|
||||||
|
const signalStore = new IRSignalStore(logger);
|
||||||
|
return {
|
||||||
|
signalStore,
|
||||||
|
isRecording() {
|
||||||
|
return isRecording;
|
||||||
|
},
|
||||||
|
setRecordingState(newValue: boolean) {
|
||||||
|
isRecording = newValue;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
import { HAmqtt } from "../ha_mqtt/index";
|
||||||
|
|
||||||
|
export const NODE_ID = "FlicHubIR";
|
||||||
|
export const convertUint32Array2Str = (arr: Uint32Array): string => {
|
||||||
|
let outStr = [];
|
||||||
|
for (let i = 0; i < arr.length; i++) {
|
||||||
|
outStr.push(arr[i].toString(32));
|
||||||
|
}
|
||||||
|
return outStr.join("_");
|
||||||
|
};
|
||||||
|
export const convertStr2Uint32Array = (s: string): Uint32Array => {
|
||||||
|
const a = s.split("_");
|
||||||
|
return new Uint32Array(a.slice(0, a.length - 2).map((v) => parseInt(v, 32)));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const makeOptions = (
|
||||||
|
opt: Partial<IRControllerOpt>,
|
||||||
|
): IRControllerOpt => ({
|
||||||
|
debug: false,
|
||||||
|
uniqueId: "0",
|
||||||
|
...opt,
|
||||||
|
});
|
||||||
|
|
||||||
|
export type IRConstants = ReturnType<typeof getConstants>;
|
||||||
|
export type IRConstantsNames = keyof IRConstants;
|
||||||
|
export const getConstants = (ha: HAmqtt, options: IRControllerOpt) => {
|
||||||
|
const nodeId = `${NODE_ID}${options.uniqueId}`;
|
||||||
|
const LIFELINE_SIGNAL = ha.genFlicPrefixObject(nodeId, "lifeline");
|
||||||
|
const RECORD_SIGNAL = ha.genFlicPrefixObject(nodeId, "record");
|
||||||
|
const RECORD_SIGNAL_SET = ha.genFlicPrefixObject(nodeId, "record/set");
|
||||||
|
const PLAY_SIGNAL = ha.genFlicPrefixObject(nodeId, "play");
|
||||||
|
const PLAY_SIGNAL_SET = ha.genFlicPrefixObject(nodeId, "play/set");
|
||||||
|
const RECORDED_SIGNALS = ha.genFlicPrefixObject(nodeId, "rsignals");
|
||||||
|
const RECORDED_SIGNALS_CMD = ha.genFlicPrefixObject(nodeId, "rsignals/cmd");
|
||||||
|
const DELETE_SIGNAL = ha.genFlicPrefixObject(nodeId, "delsignals");
|
||||||
|
const DELETE_SIGNAL_CMD = ha.genFlicPrefixObject(nodeId, "delsignals/cmd");
|
||||||
|
const availability = [
|
||||||
|
{
|
||||||
|
payload_available: "ON",
|
||||||
|
payload_not_available: "unavailable",
|
||||||
|
topic: LIFELINE_SIGNAL.mqttPrefix,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
return {
|
||||||
|
NODE_ID: nodeId,
|
||||||
|
LIFELINE_SIGNAL: LIFELINE_SIGNAL,
|
||||||
|
RECORD_SIGNAL,
|
||||||
|
RECORD_SIGNAL_SET,
|
||||||
|
RECORDED_SIGNALS,
|
||||||
|
RECORDED_SIGNALS_CMD,
|
||||||
|
PLAY_SIGNAL,
|
||||||
|
PLAY_SIGNAL_SET,
|
||||||
|
DELETE_SIGNAL,
|
||||||
|
DELETE_SIGNAL_CMD,
|
||||||
|
set_topics: [
|
||||||
|
RECORD_SIGNAL_SET,
|
||||||
|
RECORDED_SIGNALS_CMD,
|
||||||
|
PLAY_SIGNAL_SET,
|
||||||
|
DELETE_SIGNAL_CMD,
|
||||||
|
].map((x) => x.mqttPrefix),
|
||||||
|
availability,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const homeAutomationWords: string[] = [
|
||||||
|
"home",
|
||||||
|
"hub",
|
||||||
|
"plug",
|
||||||
|
"bulb",
|
||||||
|
"lock",
|
||||||
|
"door",
|
||||||
|
"gate",
|
||||||
|
"bell",
|
||||||
|
"cam",
|
||||||
|
"nest",
|
||||||
|
"ring",
|
||||||
|
"alex",
|
||||||
|
"echo",
|
||||||
|
"siri",
|
||||||
|
"gove",
|
||||||
|
"hue",
|
||||||
|
"wemo",
|
||||||
|
"sonos",
|
||||||
|
"arlo",
|
||||||
|
"wyze",
|
||||||
|
"zigb",
|
||||||
|
"zway",
|
||||||
|
"mqtt",
|
||||||
|
"node",
|
||||||
|
"iftt",
|
||||||
|
"zap",
|
||||||
|
"temp",
|
||||||
|
"heat",
|
||||||
|
"cool",
|
||||||
|
"fan",
|
||||||
|
"vent",
|
||||||
|
"ac",
|
||||||
|
"wifi",
|
||||||
|
"ble",
|
||||||
|
"zwav",
|
||||||
|
"lora",
|
||||||
|
"mesh",
|
||||||
|
"edge",
|
||||||
|
"cloud",
|
||||||
|
"api",
|
||||||
|
"app",
|
||||||
|
"ios",
|
||||||
|
"droid",
|
||||||
|
"voice",
|
||||||
|
"tap",
|
||||||
|
"swipe",
|
||||||
|
"scene",
|
||||||
|
"rule",
|
||||||
|
"auto",
|
||||||
|
"mode",
|
||||||
|
"away",
|
||||||
|
"sleep",
|
||||||
|
"wake",
|
||||||
|
"light",
|
||||||
|
"dim",
|
||||||
|
"on",
|
||||||
|
"off",
|
||||||
|
"toggle",
|
||||||
|
"timer",
|
||||||
|
"schedule",
|
||||||
|
"sensor",
|
||||||
|
"motion",
|
||||||
|
"open",
|
||||||
|
"close",
|
||||||
|
"leak",
|
||||||
|
"smoke",
|
||||||
|
"co2",
|
||||||
|
"air",
|
||||||
|
"humid",
|
||||||
|
"lux",
|
||||||
|
"rgb",
|
||||||
|
"cct",
|
||||||
|
"tune",
|
||||||
|
"group",
|
||||||
|
"zone",
|
||||||
|
"room",
|
||||||
|
"floor",
|
||||||
|
"alarm",
|
||||||
|
"siren",
|
||||||
|
"arm",
|
||||||
|
"disarm",
|
||||||
|
"panic",
|
||||||
|
"geo",
|
||||||
|
"fence",
|
||||||
|
"dash",
|
||||||
|
"widget",
|
||||||
|
"ui",
|
||||||
|
"theme",
|
||||||
|
"dark",
|
||||||
|
"log",
|
||||||
|
"event",
|
||||||
|
"alert",
|
||||||
|
"push",
|
||||||
|
"sms",
|
||||||
|
"email",
|
||||||
|
"web",
|
||||||
|
"hook",
|
||||||
|
"rest",
|
||||||
|
"grpc",
|
||||||
|
"mqtt",
|
||||||
|
];
|
||||||
|
export function generateSequence(
|
||||||
|
n: number,
|
||||||
|
words: string[] | null = null,
|
||||||
|
sep: string = "-",
|
||||||
|
): string {
|
||||||
|
words = words || homeAutomationWords;
|
||||||
|
if (n <= 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
const result: string[] = [];
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
const randomIndex = Math.floor(Math.random() * words.length);
|
||||||
|
result.push(words[randomIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.join(sep);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const generateRandomKeyNotInList = (l: string[]): string => {
|
||||||
|
let name = generateSequence(5);
|
||||||
|
while (l.indexOf(name) !== -1) {
|
||||||
|
name = generateSequence(5);
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
};
|
||||||
-634
@@ -1,634 +0,0 @@
|
|||||||
/* Copyright (c) 2013 Gordon Williams, Pur3 Ltd
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
All sections of code within this repository are licensed under an MIT License:
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Modified by Flic Shortcut Labs.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** 'private' constants */
|
|
||||||
var C = {
|
|
||||||
PROTOCOL_LEVEL: 4, // MQTT protocol level
|
|
||||||
DEF_PORT: 1883, // MQTT default server port
|
|
||||||
DEF_KEEP_ALIVE: 60 // Default keep_alive (s)
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Control packet types */
|
|
||||||
var TYPE = {
|
|
||||||
CONNECT: 1,
|
|
||||||
CONNACK: 2,
|
|
||||||
PUBLISH: 3,
|
|
||||||
PUBACK: 4,
|
|
||||||
PUBREC: 5,
|
|
||||||
PUBREL: 6,
|
|
||||||
PUBCOMP: 7,
|
|
||||||
SUBSCRIBE: 8,
|
|
||||||
SUBACK: 9,
|
|
||||||
UNSUBSCRIBE: 10,
|
|
||||||
UNSUBACK: 11,
|
|
||||||
PINGREQ: 12,
|
|
||||||
PINGRESP: 13,
|
|
||||||
DISCONNECT: 14
|
|
||||||
};
|
|
||||||
|
|
||||||
var pakId = Math.floor(Math.random() * 65534);
|
|
||||||
|
|
||||||
Uint8Array.prototype.charCodeAt = function (a, b) {
|
|
||||||
return this.toString().charCodeAt(a, b);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
Return Codes
|
|
||||||
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349256
|
|
||||||
**/
|
|
||||||
var RETURN_CODES = {
|
|
||||||
0: 'ACCEPTED',
|
|
||||||
1: 'UNACCEPTABLE_PROTOCOL_VERSION',
|
|
||||||
2: 'IDENTIFIER_REJECTED',
|
|
||||||
3: 'SERVER_UNAVAILABLE',
|
|
||||||
4: 'BAD_USER_NAME_OR_PASSWORD',
|
|
||||||
5: 'NOT_AUTHORIZED'
|
|
||||||
};
|
|
||||||
|
|
||||||
/** MQTT constructor */
|
|
||||||
function MQTT(server, options) {
|
|
||||||
this.server = server;
|
|
||||||
options = options || {};
|
|
||||||
this.port = options.port || C.DEF_PORT;
|
|
||||||
this.client_id = options.client_id || mqttUid();
|
|
||||||
this.keep_alive = options.keep_alive || C.DEF_KEEP_ALIVE;
|
|
||||||
this.clean_session = options.clean_session || true;
|
|
||||||
this.username = options.username;
|
|
||||||
this.password = options.password;
|
|
||||||
this.client = false;
|
|
||||||
this.connected = false;
|
|
||||||
/* if keep_alive is less than the ping interval we need to use
|
|
||||||
a shorter ping interval, otherwise we'll just time out! */
|
|
||||||
this.ping_interval =
|
|
||||||
this.keep_alive < this.C.PING_INTERVAL ? (this.keep_alive - 5) : this.C.PING_INTERVAL;
|
|
||||||
this.protocol_name = options.protocol_name || "MQTT";
|
|
||||||
this.protocol_level = (options.protocol_level || C.PROTOCOL_LEVEL);
|
|
||||||
|
|
||||||
if (typeof this.client_id == 'string') {
|
|
||||||
var payloadarray = [this.client_id.length >> 8, this.client_id.length & 255];
|
|
||||||
var i = 2;
|
|
||||||
var messagearray = this.client_id.split('');
|
|
||||||
for (var j = 0; j < this.client_id.length; j++) {
|
|
||||||
var char = messagearray[j];
|
|
||||||
var numberrepres = char.charCodeAt(0);
|
|
||||||
payloadarray[i] = numberrepres;
|
|
||||||
i = i + 1;
|
|
||||||
}
|
|
||||||
this.client_id = payloadarray;
|
|
||||||
}
|
|
||||||
if (this.password) {
|
|
||||||
var payloadarray = [this.password.length >> 8, this.password.length & 255];
|
|
||||||
var i = 2;
|
|
||||||
var messagearray = this.password.split('');
|
|
||||||
for (var j = 0; j < this.password.length; j++) {
|
|
||||||
var char = messagearray[j];
|
|
||||||
var numberrepres = char.charCodeAt(0);
|
|
||||||
payloadarray[i] = numberrepres;
|
|
||||||
i = i + 1;
|
|
||||||
}
|
|
||||||
this.password = payloadarray;
|
|
||||||
}
|
|
||||||
if (this.username) {
|
|
||||||
var payloadarray = [this.username.length >> 8, this.username.length & 255];
|
|
||||||
var i = 2;
|
|
||||||
var messagearray = this.username.split('');
|
|
||||||
for (var j = 0; j < this.username.length; j++) {
|
|
||||||
var char = messagearray[j];
|
|
||||||
var numberrepres = char.charCodeAt(0);
|
|
||||||
payloadarray[i] = numberrepres;
|
|
||||||
i = i + 1;
|
|
||||||
}
|
|
||||||
this.username = payloadarray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var __listeners = {};
|
|
||||||
|
|
||||||
Object.prototype.on = function (type, fn) {
|
|
||||||
if (!__listeners[type]) {
|
|
||||||
__listeners[type] = [];
|
|
||||||
}
|
|
||||||
__listeners[type].push(fn);
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.prototype.emit = function (type, ...data) {
|
|
||||||
if (__listeners[type]) {
|
|
||||||
__listeners[type].map(function (fn) {
|
|
||||||
fn(...data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!Buffer.from) {
|
|
||||||
Buffer.from = function (a) {
|
|
||||||
return new Buffer(a);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 'public' constants here */
|
|
||||||
MQTT.prototype.C = {
|
|
||||||
DEF_QOS: 0, // Default QOS level
|
|
||||||
CONNECT_TIMEOUT: 10000, // Time (ms) to wait for CONNACK
|
|
||||||
PING_INTERVAL: 40 // Server ping interval (s)
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Utility functions ***************************/
|
|
||||||
|
|
||||||
var fromCharCode = String.fromCharCode;
|
|
||||||
|
|
||||||
/** MQTT string (length MSB, LSB + data) */
|
|
||||||
export function mqttStr(s) {
|
|
||||||
var payloadarray = [s.length >> 8, s.length & 255];
|
|
||||||
var i = 2;
|
|
||||||
var messagearray = s.split('');
|
|
||||||
for (var j = 0; j < s.length; j++) {
|
|
||||||
var char = messagearray[j];
|
|
||||||
var numberrepres = char.charCodeAt(0);
|
|
||||||
payloadarray[i] = numberrepres;
|
|
||||||
i = i + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return payloadarray;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function mqttInt2Str(arr: number[] | Uint8Array): string {
|
|
||||||
let outStr = "";
|
|
||||||
for (var i = 0; i < arr.length; i++) {
|
|
||||||
outStr += createEscapedHex(arr[i]);
|
|
||||||
}
|
|
||||||
return outStr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** MQTT packet length formatter - algorithm from reference docs */
|
|
||||||
function mqttPacketLength(length) {
|
|
||||||
var encLength = [];
|
|
||||||
var i = 0;
|
|
||||||
do {
|
|
||||||
var encByte = length & 127;
|
|
||||||
length = length >> 7;
|
|
||||||
// if there are more data to encode, set the top bit of this byte
|
|
||||||
if (length > 0) {
|
|
||||||
encByte += 128;
|
|
||||||
}
|
|
||||||
encLength[i] = encByte;
|
|
||||||
i++;
|
|
||||||
} while (length > 0);
|
|
||||||
return encLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** MQTT packet length decoder - algorithm from reference docs */
|
|
||||||
function mqttPacketLengthDec(length) {
|
|
||||||
var bytes = 0;
|
|
||||||
var decL = 0;
|
|
||||||
var lb = 0;
|
|
||||||
do {
|
|
||||||
lb = length[bytes];
|
|
||||||
decL |= (lb & 127) << (bytes++ * 7);
|
|
||||||
} while ((lb & 128) && (bytes < 4));
|
|
||||||
return {"decLen": decL, "lenBy": bytes};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** MQTT standard packet formatter */
|
|
||||||
function mqttPacket(cmd, variable, payload) {
|
|
||||||
var cmdAndLengthArray = [cmd].concat(mqttPacketLength(variable.length + payload.length));
|
|
||||||
var headerAndPayloadArray = cmdAndLengthArray.concat(variable).concat(payload);
|
|
||||||
var messageBuffer = Buffer.from(headerAndPayloadArray);
|
|
||||||
return messageBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Generate random UID */
|
|
||||||
var mqttUid = (function () {
|
|
||||||
function s4() {
|
|
||||||
var numberstring = Math.floor((1 + Math.random() * 10));
|
|
||||||
if (numberstring == 10) numberstring = 9;
|
|
||||||
numberstring = 97 + numberstring;
|
|
||||||
return numberstring;
|
|
||||||
}
|
|
||||||
|
|
||||||
return function () {
|
|
||||||
var output = [0, 12, s4(), s4(), s4(), s4(), s4(), s4(), s4(), s4(), s4(), s4(), s4(), s4()];
|
|
||||||
return output;
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
/** Generate PID */
|
|
||||||
function mqttPid() {
|
|
||||||
pakId = pakId > 65534 ? 1 : ++pakId;
|
|
||||||
return [pakId >> 8, pakId & 0xFF];
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get PID from message */
|
|
||||||
function getPid(data) {
|
|
||||||
return data.slice(0, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** PUBLISH control packet */
|
|
||||||
function mqttPublish(topic, message, qos, flags) {
|
|
||||||
var cmd = TYPE.PUBLISH << 4 | (qos << 1) | flags;
|
|
||||||
var variable = mqttStr(topic);
|
|
||||||
// Packet id must be included for QOS > 0
|
|
||||||
if (qos > 0) {
|
|
||||||
var newvariable = variable.concat(mqttPid());
|
|
||||||
return mqttPacket(cmd, newvariable, message);
|
|
||||||
} else {
|
|
||||||
return mqttPacket(cmd, variable, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** SUBSCRIBE control packet */
|
|
||||||
function mqttSubscribe(topic, qos) {
|
|
||||||
var cmd = TYPE.SUBSCRIBE << 4 | 2;
|
|
||||||
var payloadarray = [];
|
|
||||||
var i = 0;
|
|
||||||
var messagearray = topic.split('');
|
|
||||||
for (var j = 0; j < topic.length; j++) {
|
|
||||||
var char = messagearray[j];
|
|
||||||
var numberrepres = char.charCodeAt(0);
|
|
||||||
payloadarray[i] = numberrepres;
|
|
||||||
i = i + 1;
|
|
||||||
}
|
|
||||||
return mqttPacket(cmd,
|
|
||||||
mqttPid(),
|
|
||||||
mqttStr(topic).concat([qos]));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** UNSUBSCRIBE control packet */
|
|
||||||
function mqttUnsubscribe(topic) {
|
|
||||||
var cmd = TYPE.UNSUBSCRIBE << 4 | 2;
|
|
||||||
return mqttPacket(cmd,
|
|
||||||
mqttPid(),
|
|
||||||
mqttStr(topic));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create escaped hex value from number */
|
|
||||||
function createEscapedHex(n: number): string {
|
|
||||||
return fromCharCode(parseInt(n.toString(16), 16));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle a single packet of data
|
|
||||||
MQTT.prototype.packetHandler = function (data) {
|
|
||||||
|
|
||||||
// if we had some data left over from last
|
|
||||||
// time, add it on
|
|
||||||
if (this.partData && this.partData.length > 0) {
|
|
||||||
data = Buffer.from(Array.prototype.slice.call(this.partData).concat(Array.prototype.slice.call(data)));
|
|
||||||
this.partData = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Figure out packet length...
|
|
||||||
var dLen = mqttPacketLengthDec(data.slice(1, data.length));
|
|
||||||
var pLen = dLen.decLen + dLen.lenBy + 1;
|
|
||||||
// less than one packet?
|
|
||||||
if (data.length < pLen) {
|
|
||||||
this.partData = data;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow zero-size pData, but detect if its indexes
|
|
||||||
// will go out of bounds.
|
|
||||||
if (1 + dLen.lenBy >= data.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the data for this packet
|
|
||||||
var pData = data.slice(1 + dLen.lenBy, pLen);
|
|
||||||
|
|
||||||
// more than one packet? re-emit it so we handle it later
|
|
||||||
if (data.length > pLen) {
|
|
||||||
this.client.emit('data', data.slice(pLen, data.length));
|
|
||||||
}
|
|
||||||
// Now handle this MQTT packet
|
|
||||||
var cmd = data[0];
|
|
||||||
var type = cmd >> 4;
|
|
||||||
var flag = cmd & 15;
|
|
||||||
if (type === TYPE.PUBLISH) {
|
|
||||||
var qos = (cmd & 0x6) >> 1;
|
|
||||||
var topic_len = pData[0] << 8 | pData[1];
|
|
||||||
var msg_start = 2 + topic_len + (qos ? 2 : 0);
|
|
||||||
var parsedData = {
|
|
||||||
topic: pData.slice(2, 2 + topic_len),
|
|
||||||
message: pData.slice(msg_start, pData.length),
|
|
||||||
dup: (cmd & 0x8) >> 3,
|
|
||||||
qos: qos,
|
|
||||||
pid: qos ? pData.slice(2 + topic_len, 4 + topic_len) : 0,
|
|
||||||
retain: cmd & 0x1
|
|
||||||
};
|
|
||||||
if (parsedData.qos) {
|
|
||||||
this.client.write([((parsedData.qos == 1) ? TYPE.PUBACK : TYPE.PUBREC) << 4, 2, parsedData.pid]);
|
|
||||||
}
|
|
||||||
this.emit('publish', parsedData);
|
|
||||||
this.emit('message', mqttInt2Str(parsedData.topic), mqttInt2Str(parsedData.message));
|
|
||||||
} else if (type === TYPE.PUBACK) {
|
|
||||||
this.emit('puback', data.charCodeAt(2) << 8 | data.charCodeAt(3));
|
|
||||||
} else if (type === TYPE.PUBREC) {
|
|
||||||
var pubrelArray = [(TYPE.PUBREL << 4 | 2), 2];
|
|
||||||
var pidArray = Array.prototype.slice.call(getPid(pData));
|
|
||||||
var pubrecResponse = pubrelArray.concat(pidArray);
|
|
||||||
this.client.write(Buffer.from(pubrecResponse));
|
|
||||||
} else if (type === TYPE.PUBREL) {
|
|
||||||
var pubcompArray = [(TYPE.PUBCOMP << 4), 2];
|
|
||||||
var pidArray = Array.prototype.slice.call(getPid(pData));
|
|
||||||
var pubrelResponse = pubcompArray.concat(pidArray);
|
|
||||||
this.client.write(pubrelResponse);
|
|
||||||
} else if (type === TYPE.PUBCOMP) {
|
|
||||||
this.emit('pubcomp', data.charCodeAt(2) << 8 | data.charCodeAt(3));
|
|
||||||
} else if (type === TYPE.SUBACK) {
|
|
||||||
if (pData.length > 0) {
|
|
||||||
if (pData[pData.length - 1] == 0x80) {
|
|
||||||
this.emit('subscribed_fail');
|
|
||||||
} else {
|
|
||||||
this.emit('subscribed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (type === TYPE.UNSUBACK) {
|
|
||||||
this.emit('unsubscribed');
|
|
||||||
} else if (type === TYPE.PINGREQ) {
|
|
||||||
this.client.write([(TYPE.PINGRESP << 4), 0]);
|
|
||||||
} else if (type === TYPE.PINGRESP) {
|
|
||||||
this.emit('ping_reply');
|
|
||||||
} else if (type === TYPE.CONNACK) {
|
|
||||||
if (this.ctimo) clearTimeout(this.ctimo);
|
|
||||||
this.ctimo = undefined;
|
|
||||||
this.partData = [];
|
|
||||||
var returnCode = pData[1];
|
|
||||||
if (RETURN_CODES[returnCode] === 'ACCEPTED') {
|
|
||||||
this.connected = true;
|
|
||||||
// start pinging
|
|
||||||
if (this.pintr) clearInterval(this.pintr);
|
|
||||||
this.pintr = setInterval(this.ping.bind(this), this.ping_interval * 1000);
|
|
||||||
// emit connected events
|
|
||||||
this.emit('connected');
|
|
||||||
this.emit('connect');
|
|
||||||
} else {
|
|
||||||
var mqttError = "Connection refused, ";
|
|
||||||
this.connected = false;
|
|
||||||
if (returnCode > 0 && returnCode < 6) {
|
|
||||||
mqttError += RETURN_CODES[returnCode];
|
|
||||||
} else {
|
|
||||||
mqttError += "unknown return code: " + returnCode + ".";
|
|
||||||
}
|
|
||||||
this.emit('error', mqttError);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.emit('error', "MQTT unsupported packet type: " + type);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Public interface ****************************/
|
|
||||||
|
|
||||||
/** Establish connection and set up keep_alive ping */
|
|
||||||
MQTT.prototype.connect = function (client) {
|
|
||||||
if (this.connected) return;
|
|
||||||
var mqo = this;
|
|
||||||
var onConnect = function () {
|
|
||||||
mqo.client = client;
|
|
||||||
// write connection message
|
|
||||||
var teststring = mqo.mqttConnect(mqo.client_id);
|
|
||||||
client.write(teststring);
|
|
||||||
// handle connection timeout if too slow
|
|
||||||
mqo.ctimo = setTimeout(function () {
|
|
||||||
mqo.ctimo = undefined;
|
|
||||||
mqo.emit('disconnected');
|
|
||||||
mqo.disconnect();
|
|
||||||
}, mqo.C.CONNECT_TIMEOUT);
|
|
||||||
// Incoming data
|
|
||||||
client.on('data', mqo.packetHandler.bind(mqo));
|
|
||||||
// Socket closed
|
|
||||||
client.on('end', function () {
|
|
||||||
mqo._scktClosed();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
if (client) {
|
|
||||||
onConnect();
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
var self = this;
|
|
||||||
client = require("net").Socket().connect({host: mqo.server, port: mqo.port}, onConnect);
|
|
||||||
client.on('error', function (err) {
|
|
||||||
self.emit('error', err.message);
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
this.client = false;
|
|
||||||
this.emit('error', e.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Called internally when the connection closes */
|
|
||||||
MQTT.prototype._scktClosed = function () {
|
|
||||||
if (this.connected) {
|
|
||||||
this.connected = false;
|
|
||||||
this.client = false;
|
|
||||||
if (this.pintr) clearInterval(this.pintr);
|
|
||||||
if (this.ctimo) clearTimeout(this.ctimo);
|
|
||||||
this.pintr = this.ctimo = undefined;
|
|
||||||
this.emit('disconnected');
|
|
||||||
this.emit('close');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Disconnect from server */
|
|
||||||
MQTT.prototype.disconnect = function () {
|
|
||||||
if (!this.client) return;
|
|
||||||
try {
|
|
||||||
this.client.write(Buffer.from([(TYPE.DISCONNECT << 4), 0]));
|
|
||||||
} catch (e) {
|
|
||||||
return this._scktClosed();
|
|
||||||
}
|
|
||||||
this.client.end();
|
|
||||||
this.client = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Publish message using specified topic.
|
|
||||||
opts = {
|
|
||||||
retain: bool // the server should retain this message and send it out again to new subscribers
|
|
||||||
dup : bool // indicate the message is a duplicate because original wasn't ACKed (QoS > 0 only)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
MQTT.prototype.publish = function (topic, message, opts) {
|
|
||||||
if (!this.client) return;
|
|
||||||
opts = opts || {};
|
|
||||||
try {
|
|
||||||
var payloadarray = [];
|
|
||||||
var i = 0;
|
|
||||||
var messagearray = message.split('');
|
|
||||||
for (var j = 0; j < message.length; j++) {
|
|
||||||
var char = messagearray[j];
|
|
||||||
var numberrepres = char.charCodeAt(0);
|
|
||||||
payloadarray[i] = numberrepres;
|
|
||||||
i = i + 1;
|
|
||||||
}
|
|
||||||
var publishMessage = mqttPublish(topic, payloadarray, opts.qos || this.C.DEF_QOS, (opts.retain ? 1 : 0) | (opts.dup ? 8 : 0));
|
|
||||||
this.client.write(publishMessage);
|
|
||||||
} catch (e) {
|
|
||||||
this._scktClosed();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Subscribe to topic (filter) */
|
|
||||||
MQTT.prototype.subscribe = function (topics, opts) {
|
|
||||||
if (!this.client) return;
|
|
||||||
opts = opts || {};
|
|
||||||
|
|
||||||
var subs = [];
|
|
||||||
if ('string' === typeof topics) {
|
|
||||||
topics = [topics];
|
|
||||||
}
|
|
||||||
if (Array.isArray(topics)) {
|
|
||||||
topics.forEach(function (topic) {
|
|
||||||
subs.push({
|
|
||||||
topic: topic,
|
|
||||||
qos: opts.qos || this.C.DEF_QOS
|
|
||||||
});
|
|
||||||
}.bind(this));
|
|
||||||
} else {
|
|
||||||
Object
|
|
||||||
.keys(topics)
|
|
||||||
.forEach(function (k) {
|
|
||||||
subs.push({
|
|
||||||
topic: k,
|
|
||||||
qos: topics[k]
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
subs.forEach(function (sub) {
|
|
||||||
var subpacket = mqttSubscribe(sub.topic, sub.qos);
|
|
||||||
this.client.write(subpacket);
|
|
||||||
}.bind(this));
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Unsubscribe to topic (filter) */
|
|
||||||
MQTT.prototype.unsubscribe = function (topic) {
|
|
||||||
if (!this.client) return;
|
|
||||||
this.client.write(mqttUnsubscribe(topic));
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Send ping request to server */
|
|
||||||
MQTT.prototype.ping = function () {
|
|
||||||
if (!this.client) return;
|
|
||||||
try {
|
|
||||||
this.client.write(Buffer.from([TYPE.PINGREQ << 4, 0]));
|
|
||||||
} catch (e) {
|
|
||||||
this._scktClosed();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Packet specific functions *******************/
|
|
||||||
|
|
||||||
/** Create connection flags */
|
|
||||||
MQTT.prototype.createFlagsForConnection = function (options) {
|
|
||||||
var flags = 0;
|
|
||||||
flags |= (this.username) ? 0x80 : 0;
|
|
||||||
flags |= (this.username && this.password) ? 0x40 : 0;
|
|
||||||
flags |= (options.clean_session) ? 0x02 : 0;
|
|
||||||
return flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** CONNECT control packet
|
|
||||||
Clean Session and Userid/Password are currently only supported
|
|
||||||
connect flag. Wills are not
|
|
||||||
currently supported.
|
|
||||||
*/
|
|
||||||
MQTT.prototype.mqttConnect = function (clean) {
|
|
||||||
var cmd = TYPE.CONNECT << 4;
|
|
||||||
var flags = this.createFlagsForConnection({
|
|
||||||
clean_session: clean
|
|
||||||
});
|
|
||||||
|
|
||||||
var keep_alive = [this.keep_alive >> 8, this.keep_alive & 255];
|
|
||||||
|
|
||||||
/* payload */
|
|
||||||
var payload = this.client_id;
|
|
||||||
if (this.username) {
|
|
||||||
payload = payload.concat(this.username);
|
|
||||||
if (this.password) {
|
|
||||||
payload = payload.concat(this.password);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return mqttPacket(cmd,
|
|
||||||
mqttStr(this.protocol_name)/*protocol name*/.concat(
|
|
||||||
[this.protocol_level]) /*protocol level*/.concat(
|
|
||||||
[flags]).concat(keep_alive),
|
|
||||||
payload);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Exports *************************************/
|
|
||||||
|
|
||||||
/** This is 'exported' so it can be used with `require('MQTT.js').create(server, options)` */
|
|
||||||
export function create(server, options): MQTT {
|
|
||||||
return new MQTT(server, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function connect(options): MQTT {
|
|
||||||
var mqtt = new MQTT(options.host, options);
|
|
||||||
mqtt.connect();
|
|
||||||
return mqtt;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export interface MQTT {
|
|
||||||
connect(): void;
|
|
||||||
|
|
||||||
publish(topic: string, message: string, opts: {
|
|
||||||
retain?: boolean, // the server should retain this message and send it out again to new subscribers
|
|
||||||
dup?: boolean, // indicate the message is a duplicate because original wasn't ACKed (QoS > 0 only)
|
|
||||||
} | undefined): void;
|
|
||||||
|
|
||||||
subscribe(topics: string[]): void;
|
|
||||||
|
|
||||||
unsubscribe(topic: string): void;
|
|
||||||
|
|
||||||
on(ev: 'publish', cb: (data: { topic: Buffer, message: Buffer }) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'message', cb: (topic: string, message: string) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'puback', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'pubcomp', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'subscribed_fail', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'subscribed', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'unsubscribed', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'ping_reply', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'connected', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'connect', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'error', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'disconnected', cb: (data) => void): void;
|
|
||||||
|
|
||||||
on(ev: 'close', cb: (data) => void): void;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/** 'private' constants */
|
||||||
|
export const C = {
|
||||||
|
PROTOCOL_LEVEL: 4, // MQTT protocol level
|
||||||
|
DEF_PORT: 1883, // MQTT default server port
|
||||||
|
DEF_KEEP_ALIVE: 60, // Default keep_alive (s)
|
||||||
|
DEF_QOS: 0, // Default QOS level
|
||||||
|
CONNECT_TIMEOUT: 10000, // Time (ms) to wait for CONNACK
|
||||||
|
PING_INTERVAL: 40, // Server ping interval (s)
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Control packet types */
|
||||||
|
export const TYPE = {
|
||||||
|
CONNECT: 1,
|
||||||
|
CONNACK: 2,
|
||||||
|
PUBLISH: 3,
|
||||||
|
PUBACK: 4,
|
||||||
|
PUBREC: 5,
|
||||||
|
PUBREL: 6,
|
||||||
|
PUBCOMP: 7,
|
||||||
|
SUBSCRIBE: 8,
|
||||||
|
SUBACK: 9,
|
||||||
|
UNSUBSCRIBE: 10,
|
||||||
|
UNSUBACK: 11,
|
||||||
|
PINGREQ: 12,
|
||||||
|
PINGRESP: 13,
|
||||||
|
DISCONNECT: 14,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return Codes
|
||||||
|
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349256
|
||||||
|
**/
|
||||||
|
export const RETURN_CODES: Record<number, string> = {
|
||||||
|
0: "ACCEPTED",
|
||||||
|
1: "UNACCEPTABLE_PROTOCOL_VERSION",
|
||||||
|
2: "IDENTIFIER_REJECTED",
|
||||||
|
3: "SERVER_UNAVAILABLE",
|
||||||
|
4: "BAD_USER_NAME_OR_PASSWORD",
|
||||||
|
5: "NOT_AUTHORIZED",
|
||||||
|
};
|
||||||
@@ -0,0 +1,425 @@
|
|||||||
|
import net, { Socket } from "net";
|
||||||
|
import { C, RETURN_CODES, TYPE } from "./constants";
|
||||||
|
import {
|
||||||
|
mqttStr,
|
||||||
|
getClientId,
|
||||||
|
setOptionDefaults,
|
||||||
|
mqttPacketLengthDec,
|
||||||
|
mqttPacket,
|
||||||
|
createBufferFromArray,
|
||||||
|
getPid,
|
||||||
|
createMqttPublishPacket,
|
||||||
|
createMqttSubscribePacket,
|
||||||
|
} from "./utils";
|
||||||
|
export type ParsedMQTTData = {
|
||||||
|
topic: string;
|
||||||
|
message: string;
|
||||||
|
dup: number;
|
||||||
|
qos: number;
|
||||||
|
pid: number | Buffer;
|
||||||
|
retain: number;
|
||||||
|
};
|
||||||
|
type MQTTEventMapping = {
|
||||||
|
error: (err: string) => void;
|
||||||
|
disconnected: () => void;
|
||||||
|
connected: () => void;
|
||||||
|
connect: () => void;
|
||||||
|
close: () => void;
|
||||||
|
end: () => void;
|
||||||
|
data: (d: number[]) => void;
|
||||||
|
publish: (d: ParsedMQTTData) => void;
|
||||||
|
message: (
|
||||||
|
topic: ParsedMQTTData["topic"],
|
||||||
|
message: ParsedMQTTData["message"],
|
||||||
|
) => void;
|
||||||
|
puback: (n: number) => void;
|
||||||
|
pubcomp: (n: number) => void;
|
||||||
|
subscribed_fail: () => void;
|
||||||
|
subscribed: () => void;
|
||||||
|
unsubscribed: () => void;
|
||||||
|
ping_reply: () => void;
|
||||||
|
};
|
||||||
|
type MQTTEventName = keyof MQTTEventMapping;
|
||||||
|
type _Listener<T extends MQTTEventName> = MQTTEventMapping[T];
|
||||||
|
export class FlicMQTT {
|
||||||
|
private options: MQTTOptions;
|
||||||
|
private clientId: number[];
|
||||||
|
private connected: boolean = false;
|
||||||
|
private pingInterval: number;
|
||||||
|
private username: number[] | null = null;
|
||||||
|
private password: number[] | null = null;
|
||||||
|
private client: Socket | null = null;
|
||||||
|
private __listeners: Record<MQTTEventName, _Listener<any>[]> = {
|
||||||
|
close: [],
|
||||||
|
connected: [],
|
||||||
|
connect: [],
|
||||||
|
disconnected: [],
|
||||||
|
end: [],
|
||||||
|
error: [],
|
||||||
|
data: [],
|
||||||
|
publish: [],
|
||||||
|
message: [],
|
||||||
|
puback: [],
|
||||||
|
pubcomp: [],
|
||||||
|
subscribed: [],
|
||||||
|
unsubscribed: [],
|
||||||
|
subscribed_fail: [],
|
||||||
|
ping_reply: [],
|
||||||
|
};
|
||||||
|
private pakId = Math.floor(Math.random() * 65534);
|
||||||
|
|
||||||
|
public partData: number[] | Buffer = [];
|
||||||
|
public ctimo: any | null = null;
|
||||||
|
public pintr: any | null = null;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private server: string,
|
||||||
|
_options: Partial<MQTTOptions>,
|
||||||
|
) {
|
||||||
|
this.options = setOptionDefaults(_options);
|
||||||
|
this.clientId = getClientId(this.options);
|
||||||
|
if (this.options.username) {
|
||||||
|
this.username = mqttStr(this.options.username);
|
||||||
|
}
|
||||||
|
if (this.options.password) {
|
||||||
|
this.password = mqttStr(this.options.password);
|
||||||
|
}
|
||||||
|
this.pingInterval =
|
||||||
|
this.options.keep_alive < C.PING_INTERVAL
|
||||||
|
? this.options.keep_alive - 5
|
||||||
|
: C.PING_INTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
isConnected() {
|
||||||
|
return this.client !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
on<T extends MQTTEventName>(type: T, fn: _Listener<T>) {
|
||||||
|
if (!this.__listeners[type]) {
|
||||||
|
this.__listeners[type] = [];
|
||||||
|
}
|
||||||
|
this.__listeners[type].push(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit<T extends MQTTEventName>(type: T, ...data: Parameters<_Listener<T>>) {
|
||||||
|
if (this.__listeners[type]) {
|
||||||
|
this.__listeners[type].map(function (fn) {
|
||||||
|
fn(...data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mqttPid() {
|
||||||
|
this.pakId = this.pakId > 65534 ? 1 : ++this.pakId;
|
||||||
|
return [this.pakId >> 8, this.pakId & 0xff];
|
||||||
|
}
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
console.log(
|
||||||
|
"Connecting..." +
|
||||||
|
JSON.stringify({
|
||||||
|
connected: this.connected,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if (this.connected) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const mqo = this;
|
||||||
|
try {
|
||||||
|
const client = (this.client = net.createConnection(
|
||||||
|
{ host: this.server, port: this.options.port },
|
||||||
|
() => {
|
||||||
|
// write connection message
|
||||||
|
const teststring = mqo.mqttConnect(!!mqo.clientId);
|
||||||
|
client.write(teststring);
|
||||||
|
// handle connection timeout if too slow
|
||||||
|
mqo.ctimo = setTimeout(function () {
|
||||||
|
mqo.ctimo = null;
|
||||||
|
mqo.emit("disconnected");
|
||||||
|
mqo.disconnect();
|
||||||
|
}, C.CONNECT_TIMEOUT);
|
||||||
|
// Incoming data
|
||||||
|
const handler = mqo.packetHandler.bind(mqo);
|
||||||
|
client.on("data", handler as any);
|
||||||
|
// Socket closed
|
||||||
|
client.on("end", function () {
|
||||||
|
mqo._scktClosed();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
this.client = null;
|
||||||
|
this.emit("error", (e as Error).message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Called internally when the connection closes */
|
||||||
|
_scktClosed() {
|
||||||
|
if (this.connected) {
|
||||||
|
this.client = null;
|
||||||
|
this.connected = false;
|
||||||
|
if (this.pintr) clearInterval(this.pintr);
|
||||||
|
if (this.ctimo) clearTimeout(this.ctimo);
|
||||||
|
this.pintr = this.ctimo = undefined;
|
||||||
|
this.emit("disconnected");
|
||||||
|
this.emit("close");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Disconnect from server */
|
||||||
|
disconnect() {
|
||||||
|
if (!this.client) return;
|
||||||
|
try {
|
||||||
|
this.client.write(createBufferFromArray([TYPE.DISCONNECT << 4, 0]));
|
||||||
|
} catch (e) {
|
||||||
|
return this._scktClosed();
|
||||||
|
}
|
||||||
|
this.client.end();
|
||||||
|
this.client = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create connection flags */
|
||||||
|
createFlagsForConnection(clean: boolean) {
|
||||||
|
var flags = 0;
|
||||||
|
flags |= this.username ? 0x80 : 0;
|
||||||
|
flags |= this.username && this.password ? 0x40 : 0;
|
||||||
|
flags |= clean ? 0x02 : 0;
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
/** CONNECT control packet
|
||||||
|
Clean Session and Userid/Password are currently only supported
|
||||||
|
connect flag. Wills are not
|
||||||
|
currently supported.
|
||||||
|
*/
|
||||||
|
mqttConnect(clean: boolean) {
|
||||||
|
var cmd = TYPE.CONNECT << 4;
|
||||||
|
var flags = this.createFlagsForConnection(clean);
|
||||||
|
|
||||||
|
var keep_alive = [
|
||||||
|
this.options.keep_alive >> 8,
|
||||||
|
this.options.keep_alive & 255,
|
||||||
|
];
|
||||||
|
|
||||||
|
/* payload */
|
||||||
|
var payload = this.clientId;
|
||||||
|
if (this.username) {
|
||||||
|
payload = payload.concat(this.username);
|
||||||
|
if (this.password) {
|
||||||
|
payload = payload.concat(this.password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mqttPacket(
|
||||||
|
cmd,
|
||||||
|
mqttStr(this.options.protocol_name) /*protocol name*/
|
||||||
|
.concat([this.options.protocol_level]) /*protocol level*/
|
||||||
|
.concat([flags])
|
||||||
|
.concat(keep_alive),
|
||||||
|
payload,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
packetHandler(data: Buffer) {
|
||||||
|
if (!this.client) {
|
||||||
|
this.emit("error", "disconnected mid packet handling");
|
||||||
|
throw new Error("disconnected mid packet handling");
|
||||||
|
}
|
||||||
|
// if we had some data left over from last
|
||||||
|
// time, add it on
|
||||||
|
if (this.partData && this.partData.length > 0) {
|
||||||
|
data = createBufferFromArray(
|
||||||
|
Array.prototype.slice
|
||||||
|
.call(this.partData)
|
||||||
|
.concat(Array.prototype.slice.call(data)),
|
||||||
|
);
|
||||||
|
this.partData = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Figure out packet length...
|
||||||
|
var dLen = mqttPacketLengthDec(data.slice(1, data.length));
|
||||||
|
var pLen = dLen.decLen + dLen.lenBy + 1;
|
||||||
|
// less than one packet?
|
||||||
|
if (data.length < pLen) {
|
||||||
|
this.partData = data;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Get the data for this packet
|
||||||
|
var pData = data.slice(1 + dLen.lenBy, pLen);
|
||||||
|
|
||||||
|
// Handle this MQTT packet
|
||||||
|
var cmd = data[0];
|
||||||
|
var type = cmd >> 4;
|
||||||
|
if (type === TYPE.PUBLISH) {
|
||||||
|
var qos = (cmd & 0x6) >> 1;
|
||||||
|
var topic_len = (pData[0] << 8) | pData[1];
|
||||||
|
var msg_start = 2 + topic_len + (qos ? 2 : 0);
|
||||||
|
var parsedData: ParsedMQTTData = {
|
||||||
|
topic: pData.slice(2, 2 + topic_len).toString("utf8"),
|
||||||
|
message: pData.slice(msg_start, pData.length).toString("utf8"),
|
||||||
|
dup: (cmd & 0x8) >> 3,
|
||||||
|
qos: qos,
|
||||||
|
pid: qos ? pData.slice(2 + topic_len, 4 + topic_len) : 0,
|
||||||
|
retain: cmd & 0x1,
|
||||||
|
};
|
||||||
|
if (parsedData.qos) {
|
||||||
|
const _d = (parsedData.qos == 1 ? TYPE.PUBACK : TYPE.PUBREC) << 4;
|
||||||
|
this.client.write([_d, 2, parsedData.pid] as any);
|
||||||
|
}
|
||||||
|
this.emit("publish", parsedData);
|
||||||
|
this.emit("message", parsedData.topic, parsedData.message);
|
||||||
|
} else if (type === TYPE.PUBACK) {
|
||||||
|
this.emit(
|
||||||
|
"puback",
|
||||||
|
(data.toString().charCodeAt(2) << 8) | data.toString().charCodeAt(3),
|
||||||
|
);
|
||||||
|
} else if (type === TYPE.PUBREC) {
|
||||||
|
var pubrelArray = [(TYPE.PUBREL << 4) | 2, 2];
|
||||||
|
var pidArray = Array.prototype.slice.call(getPid(pData));
|
||||||
|
var pubrecResponse = pubrelArray.concat(pidArray);
|
||||||
|
this.client.write(Buffer.from(pubrecResponse));
|
||||||
|
} else if (type === TYPE.PUBREL) {
|
||||||
|
var pubcompArray = [TYPE.PUBCOMP << 4, 2];
|
||||||
|
var pidArray = Array.prototype.slice.call(getPid(pData));
|
||||||
|
var pubrelResponse = pubcompArray.concat(pidArray);
|
||||||
|
this.client.write(pubrelResponse as any);
|
||||||
|
} else if (type === TYPE.PUBCOMP) {
|
||||||
|
this.emit(
|
||||||
|
"pubcomp",
|
||||||
|
(data.toString().charCodeAt(2) << 8) | data.toString().charCodeAt(3),
|
||||||
|
);
|
||||||
|
} else if (type === TYPE.SUBACK) {
|
||||||
|
if (pData.length > 0) {
|
||||||
|
if (pData[pData.length - 1] == 0x80) {
|
||||||
|
this.emit("subscribed_fail");
|
||||||
|
} else {
|
||||||
|
this.emit("subscribed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (type === TYPE.UNSUBACK) {
|
||||||
|
this.emit("unsubscribed");
|
||||||
|
} else if (type === TYPE.PINGREQ) {
|
||||||
|
this.client.write([TYPE.PINGRESP << 4, 0] as any);
|
||||||
|
} else if (type === TYPE.PINGRESP) {
|
||||||
|
this.emit("ping_reply");
|
||||||
|
} else if (type === TYPE.CONNACK) {
|
||||||
|
if (this.ctimo) clearTimeout(this.ctimo);
|
||||||
|
this.ctimo = undefined;
|
||||||
|
this.partData = [];
|
||||||
|
var returnCode = pData[1];
|
||||||
|
if (RETURN_CODES[returnCode] === "ACCEPTED") {
|
||||||
|
this.connected = true;
|
||||||
|
// start pinging
|
||||||
|
if (this.pintr) clearInterval(this.pintr);
|
||||||
|
this.pintr = setInterval(
|
||||||
|
this.ping.bind(this),
|
||||||
|
this.pingInterval * 1000,
|
||||||
|
);
|
||||||
|
// emit connected events
|
||||||
|
this.emit("connected");
|
||||||
|
this.emit("connect");
|
||||||
|
} else {
|
||||||
|
var mqttError = "Connection refused, ";
|
||||||
|
this.connected = false;
|
||||||
|
if (returnCode > 0 && returnCode < 6) {
|
||||||
|
mqttError += RETURN_CODES[returnCode];
|
||||||
|
} else {
|
||||||
|
mqttError += "unknown return code: " + returnCode + ".";
|
||||||
|
}
|
||||||
|
this.emit("error", mqttError);
|
||||||
|
}
|
||||||
|
// more than one packet? re-emit it so we handle it later
|
||||||
|
if (data.length > pLen) {
|
||||||
|
this.client.emit("data", data.slice(pLen, data.length));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.emit("error", "MQTT unsupported packet type: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Unsubscribe to topic (filter) */
|
||||||
|
unsubscribe(topic: string) {
|
||||||
|
if (!this.client) return;
|
||||||
|
var cmd = (TYPE.UNSUBSCRIBE << 4) | 2;
|
||||||
|
this.client.write(mqttPacket(cmd, this.mqttPid(), mqttStr(topic)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Send ping request to server */
|
||||||
|
ping() {
|
||||||
|
if (!this.client) return;
|
||||||
|
try {
|
||||||
|
this.client.write(Buffer.from([TYPE.PINGREQ << 4, 0]));
|
||||||
|
} catch (e) {
|
||||||
|
this._scktClosed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Publish message using specified topic.
|
||||||
|
opts = {
|
||||||
|
retain: bool // the server should retain this message and send it out again to new subscribers
|
||||||
|
dup : bool // indicate the message is a duplicate because original wasn't ACKed (QoS > 0 only)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
publish(topic: string, message: string, opts: MQTTPublishOpt) {
|
||||||
|
if (!this.client) return;
|
||||||
|
opts = opts || {};
|
||||||
|
try {
|
||||||
|
var payloadarray = [];
|
||||||
|
var i = 0;
|
||||||
|
var messagearray = message.split("");
|
||||||
|
for (var j = 0; j < message.length; j++) {
|
||||||
|
var char = messagearray[j];
|
||||||
|
var numberrepres = char.charCodeAt(0);
|
||||||
|
payloadarray[i] = numberrepres;
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
var publishMessage = createMqttPublishPacket(
|
||||||
|
topic,
|
||||||
|
payloadarray,
|
||||||
|
opts.qos || C.DEF_QOS,
|
||||||
|
(opts.retain ? 1 : 0) | (opts.dup ? 8 : 0),
|
||||||
|
this.mqttPid(),
|
||||||
|
);
|
||||||
|
this.client.write(publishMessage);
|
||||||
|
} catch (e) {
|
||||||
|
this._scktClosed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Subscribe to topic (filter) */
|
||||||
|
subscribe(
|
||||||
|
topics: string[] | string | Record<string, number>,
|
||||||
|
opts: { qos?: number } = {},
|
||||||
|
) {
|
||||||
|
if (!this.client) return;
|
||||||
|
const client = this.client;
|
||||||
|
const mqo = this;
|
||||||
|
opts = opts || {};
|
||||||
|
|
||||||
|
var subs: { topic: string; qos: number }[] = [];
|
||||||
|
if ("string" === typeof topics) {
|
||||||
|
topics = [topics];
|
||||||
|
}
|
||||||
|
if (Array.isArray(topics)) {
|
||||||
|
topics.forEach((topic) => {
|
||||||
|
subs.push({
|
||||||
|
topic: topic,
|
||||||
|
qos: opts.qos || C.DEF_QOS,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
Object.keys(topics).forEach(function (k) {
|
||||||
|
subs.push({
|
||||||
|
topic: k,
|
||||||
|
qos: (topics as any)[k],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
subs.forEach((sub) => {
|
||||||
|
var subpacket = createMqttSubscribePacket(
|
||||||
|
sub.topic,
|
||||||
|
sub.qos,
|
||||||
|
mqo.mqttPid(),
|
||||||
|
);
|
||||||
|
client.write(subpacket);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
import { C, TYPE } from "./constants";
|
||||||
|
|
||||||
|
/** Generate random UID */
|
||||||
|
export const mqttUid = (function () {
|
||||||
|
function s4() {
|
||||||
|
var numberstring = Math.floor(1 + Math.random() * 10);
|
||||||
|
if (numberstring == 10) numberstring = 9;
|
||||||
|
numberstring = 97 + numberstring;
|
||||||
|
return numberstring;
|
||||||
|
}
|
||||||
|
|
||||||
|
return function () {
|
||||||
|
var output = [
|
||||||
|
0,
|
||||||
|
12,
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
s4(),
|
||||||
|
];
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
/** MQTT string (length MSB, LSB + data) */
|
||||||
|
export const mqttStr = (s: string) => {
|
||||||
|
var payloadarray = [s.length >> 8, s.length & 255];
|
||||||
|
var i = 2;
|
||||||
|
var messagearray = s.split("");
|
||||||
|
for (var j = 0; j < s.length; j++) {
|
||||||
|
var char = messagearray[j];
|
||||||
|
var numberrepres = char.charCodeAt(0);
|
||||||
|
payloadarray[i] = numberrepres;
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
return payloadarray;
|
||||||
|
};
|
||||||
|
export const getClientId = (options: MQTTOptions): number[] => {
|
||||||
|
if (typeof options.client_id == "string") {
|
||||||
|
return mqttStr(options.client_id);
|
||||||
|
}
|
||||||
|
return options.client_id;
|
||||||
|
};
|
||||||
|
export const setOptionDefaults = (
|
||||||
|
options: Partial<MQTTOptions>,
|
||||||
|
): MQTTOptions => ({
|
||||||
|
port: options.port || C.DEF_PORT,
|
||||||
|
client_id: options.client_id || mqttUid(),
|
||||||
|
keep_alive: options.keep_alive || C.DEF_KEEP_ALIVE,
|
||||||
|
clean_session: options.clean_session || true,
|
||||||
|
username: options.username,
|
||||||
|
password: options.password,
|
||||||
|
protocol_name: options.protocol_name || "MQTT",
|
||||||
|
protocol_level: options.protocol_level || C.PROTOCOL_LEVEL,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** MQTT packet length formatter - algorithm from reference docs */
|
||||||
|
export const mqttPacketLength = (length: number) => {
|
||||||
|
var encLength: number[] = [];
|
||||||
|
var i = 0;
|
||||||
|
do {
|
||||||
|
var encByte = length & 127;
|
||||||
|
length = length >> 7;
|
||||||
|
// if there are more data to encode, set the top bit of this byte
|
||||||
|
if (length > 0) {
|
||||||
|
encByte += 128;
|
||||||
|
}
|
||||||
|
encLength[i] = encByte;
|
||||||
|
i++;
|
||||||
|
} while (length > 0);
|
||||||
|
return encLength;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** MQTT packet length decoder - algorithm from reference docs */
|
||||||
|
export type MqttPacketLengthDec = { decLen: number; lenBy: number };
|
||||||
|
export const mqttPacketLengthDec = (
|
||||||
|
length: number[] | Buffer,
|
||||||
|
): MqttPacketLengthDec => {
|
||||||
|
var bytes = 0;
|
||||||
|
var decL = 0;
|
||||||
|
var lb = 0;
|
||||||
|
do {
|
||||||
|
lb = length[bytes];
|
||||||
|
decL |= (lb & 127) << (bytes++ * 7);
|
||||||
|
} while (lb & 128 && bytes < 4);
|
||||||
|
return { decLen: decL, lenBy: bytes };
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createBufferFromArray = (a: number[]) => {
|
||||||
|
if (Buffer.from) {
|
||||||
|
return Buffer.from(a);
|
||||||
|
} else {
|
||||||
|
return new Buffer(a);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** MQTT standard packet formatter */
|
||||||
|
export const mqttPacket = (
|
||||||
|
cmd: number,
|
||||||
|
variable: number[],
|
||||||
|
payload: number[],
|
||||||
|
) => {
|
||||||
|
var cmdAndLengthArray = [cmd].concat(
|
||||||
|
mqttPacketLength(variable.length + payload.length),
|
||||||
|
);
|
||||||
|
var headerAndPayloadArray = cmdAndLengthArray
|
||||||
|
.concat(variable)
|
||||||
|
.concat(payload);
|
||||||
|
var messageBuffer = createBufferFromArray(headerAndPayloadArray);
|
||||||
|
return messageBuffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Get PID from message */
|
||||||
|
export const getPid = (data: Buffer) => {
|
||||||
|
return data.slice(0, 2);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** PUBLISH control packet */
|
||||||
|
export const createMqttPublishPacket = (
|
||||||
|
topic: string,
|
||||||
|
message: number[],
|
||||||
|
qos: number,
|
||||||
|
flags: number,
|
||||||
|
pid: number[],
|
||||||
|
) => {
|
||||||
|
var cmd = (TYPE.PUBLISH << 4) | (qos << 1) | flags;
|
||||||
|
var variable = mqttStr(topic);
|
||||||
|
// Packet id must be included for QOS > 0
|
||||||
|
if (qos > 0) {
|
||||||
|
var newvariable = variable.concat(pid);
|
||||||
|
return mqttPacket(cmd, newvariable, message);
|
||||||
|
} else {
|
||||||
|
return mqttPacket(cmd, variable, message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** SUBSCRIBE control packet */
|
||||||
|
export const createMqttSubscribePacket = (
|
||||||
|
topic: string,
|
||||||
|
qos: number,
|
||||||
|
pid: number[],
|
||||||
|
) => {
|
||||||
|
var cmd = (TYPE.SUBSCRIBE << 4) | 2;
|
||||||
|
var payloadarray = [];
|
||||||
|
var i = 0;
|
||||||
|
var messagearray = topic.split("");
|
||||||
|
for (var j = 0; j < topic.length; j++) {
|
||||||
|
var char = messagearray[j];
|
||||||
|
var numberrepres = char.charCodeAt(0);
|
||||||
|
payloadarray[i] = numberrepres;
|
||||||
|
i = i + 1;
|
||||||
|
}
|
||||||
|
return mqttPacket(cmd, pid, mqttStr(topic).concat([qos]));
|
||||||
|
};
|
||||||
+5
-5
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2015",
|
"target": "ES2015",
|
||||||
"module": "ESNext"
|
"module": "ESNext",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"typeRoots": ["./node_modules/@types", "types/*"]
|
||||||
},
|
},
|
||||||
"include": [
|
"include": ["src/**/*", "rollup.config.ts", "types/*"]
|
||||||
"src/**/*",
|
|
||||||
"rollup.config.ts"
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
Vendored
+118
@@ -0,0 +1,118 @@
|
|||||||
|
/**
|
||||||
|
* Flic Hub Studio - Buttons Module
|
||||||
|
* TypeScript Declaration File
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare module "buttons" {
|
||||||
|
import { EventEmitter } from "events";
|
||||||
|
|
||||||
|
/** Button Object Type */
|
||||||
|
export interface Button {
|
||||||
|
bdaddr: string;
|
||||||
|
serialNumber: string;
|
||||||
|
color: string;
|
||||||
|
name: string;
|
||||||
|
activeDisconnect: boolean;
|
||||||
|
connected: boolean;
|
||||||
|
ready: boolean;
|
||||||
|
batteryStatus: number | null;
|
||||||
|
firmwareVersion: number | null;
|
||||||
|
flicVersion: 1 | 2;
|
||||||
|
uuid: string;
|
||||||
|
key?: string; // Only for Flic 2
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ScanWizard Event Types */
|
||||||
|
type ScanWizardEventMap = {
|
||||||
|
foundPrivateButton: [];
|
||||||
|
foundPublicButton: [{ bdaddr: string }];
|
||||||
|
buttonConnect: [{ bdaddr: string }];
|
||||||
|
complete: [{ bdaddr: string }];
|
||||||
|
fail: [{ error: ScanWizardFailReason }];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ScanWizardFailReason =
|
||||||
|
| "CancelledByUser"
|
||||||
|
| "FailedTimeout"
|
||||||
|
| "ButtonIsPrivate"
|
||||||
|
| "BluetoothUnavailable"
|
||||||
|
| "InternetBackendError"
|
||||||
|
| "InvalidData";
|
||||||
|
|
||||||
|
/** ScanWizard Class */
|
||||||
|
export interface ScanWizard extends EventEmitter {
|
||||||
|
on<K extends keyof ScanWizardEventMap>(
|
||||||
|
event: K,
|
||||||
|
listener: (...args: ScanWizardEventMap[K]) => void,
|
||||||
|
): this;
|
||||||
|
once<K extends keyof ScanWizardEventMap>(
|
||||||
|
event: K,
|
||||||
|
listener: (...args: ScanWizardEventMap[K]) => void,
|
||||||
|
): this;
|
||||||
|
emit<K extends keyof ScanWizardEventMap>(
|
||||||
|
event: K,
|
||||||
|
...args: ScanWizardEventMap[K]
|
||||||
|
): boolean;
|
||||||
|
|
||||||
|
cancel(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Buttons Event Types */
|
||||||
|
export type ButtonsEventMap = {
|
||||||
|
buttonAdded: [{ button: Button }];
|
||||||
|
buttonUpdated: [{ button: Button }];
|
||||||
|
buttonDeleted: [{ bdaddr: string }];
|
||||||
|
buttonConnected: [{ bdaddr: string }];
|
||||||
|
buttonReady: [{ bdaddr: string }];
|
||||||
|
buttonDisconnected: [{ bdaddr: string }];
|
||||||
|
buttonDown: [{ bdaddr: string }];
|
||||||
|
buttonUp: [{ bdaddr: string }];
|
||||||
|
buttonClickOrHold: [{ bdaddr: string; isClick: boolean; isHold: boolean }];
|
||||||
|
buttonSingleOrDoubleClick: [
|
||||||
|
{ bdaddr: string; isSingleClick: boolean; isDoubleClick: boolean },
|
||||||
|
];
|
||||||
|
buttonSingleOrDoubleClickOrHold: [
|
||||||
|
{
|
||||||
|
bdaddr: string;
|
||||||
|
isSingleClick: boolean;
|
||||||
|
isDoubleClick: boolean;
|
||||||
|
isHold: boolean;
|
||||||
|
},
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Buttons Class */
|
||||||
|
export interface Buttons extends EventEmitter {
|
||||||
|
on<K extends keyof ButtonsEventMap>(
|
||||||
|
event: K,
|
||||||
|
listener: (...args: ButtonsEventMap[K]) => void,
|
||||||
|
): this;
|
||||||
|
once<K extends keyof ButtonsEventMap>(
|
||||||
|
event: K,
|
||||||
|
listener: (...args: ButtonsEventMap[K]) => void,
|
||||||
|
): this;
|
||||||
|
emit<K extends keyof ButtonsEventMap>(
|
||||||
|
event: K,
|
||||||
|
...args: ButtonsEventMap[K]
|
||||||
|
): boolean;
|
||||||
|
|
||||||
|
getButtons(): Button[];
|
||||||
|
getButton(bdaddr: string): Button | null;
|
||||||
|
startScanWizard(): ScanWizard;
|
||||||
|
|
||||||
|
importFlic2Pairings(
|
||||||
|
pairings: Array<{
|
||||||
|
bdaddr: string;
|
||||||
|
serialNumber: string;
|
||||||
|
color: string;
|
||||||
|
firmwareVersion: number;
|
||||||
|
uuid: string;
|
||||||
|
key: string;
|
||||||
|
}>,
|
||||||
|
callback: () => void,
|
||||||
|
): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const buttons: Buttons;
|
||||||
|
export default buttons;
|
||||||
|
}
|
||||||
Vendored
+46
@@ -0,0 +1,46 @@
|
|||||||
|
// datastore.d.ts
|
||||||
|
/**
|
||||||
|
* Flic Hub Studio - Datastore Module Type Declarations
|
||||||
|
* Based on: https://studio.flic.io/static/documentation/#133_datastore_module
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare module "datastore" {
|
||||||
|
/**
|
||||||
|
* The Datastore class provides persistent key-value storage per package.
|
||||||
|
* Keys and values are strings. Storage is isolated per package.
|
||||||
|
*/
|
||||||
|
class Datastore {
|
||||||
|
/**
|
||||||
|
* Stores a string value under the given key.
|
||||||
|
*
|
||||||
|
* @param key - The key under which to store the value.
|
||||||
|
* @param value - The string value to store.
|
||||||
|
* @param callback - Optional callback invoked when the operation completes.
|
||||||
|
* Receives an error if the operation failed, otherwise null.
|
||||||
|
*/
|
||||||
|
put(
|
||||||
|
key: string,
|
||||||
|
value: string,
|
||||||
|
callback?: (error: Error | null) => void,
|
||||||
|
): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a stored string value by key.
|
||||||
|
*
|
||||||
|
* @param key - The key to look up.
|
||||||
|
* @param callback - Required callback invoked when the operation completes.
|
||||||
|
* - error: null if successful, or Error if a datastore error occurred (other than not found).
|
||||||
|
* - result: The stored string, or null if the key was not found.
|
||||||
|
*/
|
||||||
|
get(
|
||||||
|
key: string,
|
||||||
|
callback: (error: Error | null, result: string | null) => void,
|
||||||
|
): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default export is an instance of the Datastore class.
|
||||||
|
*/
|
||||||
|
const datastore: Datastore;
|
||||||
|
export default datastore;
|
||||||
|
}
|
||||||
Vendored
+84
@@ -0,0 +1,84 @@
|
|||||||
|
declare module "flicapp" {
|
||||||
|
import { EventEmitter } from "events";
|
||||||
|
/**
|
||||||
|
* The FlicApp class allows integration with virtual devices and message actions
|
||||||
|
* configured in the Flic mobile app for use with Flic Twist and other controls.
|
||||||
|
*/
|
||||||
|
export class FlicApp extends EventEmitter {
|
||||||
|
/**
|
||||||
|
* Emitted when a message action configured in the Flic app is triggered.
|
||||||
|
* Useful for advanced Flic Twist configurations like action points in dimming or Scene Blender.
|
||||||
|
*
|
||||||
|
* @event actionMessage
|
||||||
|
* @param message - The configured message string from the Flic app
|
||||||
|
*/
|
||||||
|
on(event: "actionMessage", listener: (message: string) => void): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when a Flic Twist rotation updates a virtual device.
|
||||||
|
* Only includes the fields that changed in this update.
|
||||||
|
*
|
||||||
|
* @event virtualDeviceUpdate
|
||||||
|
* @param update - Object containing metadata and updated values
|
||||||
|
*/
|
||||||
|
on(
|
||||||
|
event: "virtualDeviceUpdate",
|
||||||
|
listener: (update: VirtualDeviceUpdate) => void,
|
||||||
|
): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the state of a virtual device in the Flic app to reflect external changes.
|
||||||
|
* This keeps the Flic Twist in sync (e.g., LED indicators, small movements).
|
||||||
|
*
|
||||||
|
* Note: For Advanced Dimming and Scene Blender, this is not required as communication is one-way.
|
||||||
|
*
|
||||||
|
* @param type - Type of the virtual device
|
||||||
|
* @param id - Identifier of the virtual device (must match Flic app configuration)
|
||||||
|
* @param values - Partial state update with values between 0 and 1
|
||||||
|
*/
|
||||||
|
virtualDeviceUpdateState(
|
||||||
|
type: VirtualDeviceType,
|
||||||
|
id: string,
|
||||||
|
values: VirtualDeviceValues,
|
||||||
|
): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Supported virtual device types */
|
||||||
|
export type VirtualDeviceType = "Light" | "Blind" | "Speaker";
|
||||||
|
|
||||||
|
/** Metadata included in virtualDeviceUpdate events */
|
||||||
|
export interface VirtualDeviceMetaData {
|
||||||
|
/** ID of the Flic Button or Twist that triggered the change */
|
||||||
|
buttonId: string;
|
||||||
|
/** Type of dimmable device */
|
||||||
|
dimmableType: VirtualDeviceType;
|
||||||
|
/** ID of the virtual device being controlled */
|
||||||
|
virtualDeviceId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Possible value fields in virtual device updates */
|
||||||
|
export interface VirtualDeviceValues {
|
||||||
|
/** Brightness level (0 to 1) - for Light, Blind, Speaker */
|
||||||
|
brightness?: number;
|
||||||
|
/** Hue (0 to 1) - for Light */
|
||||||
|
hue?: number;
|
||||||
|
/** Saturation (0 to 1) - for Light */
|
||||||
|
saturation?: number;
|
||||||
|
/** Color temperature (0 to 1) - for Light */
|
||||||
|
colorTemperature?: number;
|
||||||
|
/** Volume level (0 to 1) - for Speaker */
|
||||||
|
volume?: number;
|
||||||
|
/** Position (0 to 1) - for Blind */
|
||||||
|
position?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Full structure of a virtualDeviceUpdate event */
|
||||||
|
export interface VirtualDeviceUpdate {
|
||||||
|
metaData: VirtualDeviceMetaData;
|
||||||
|
values: VirtualDeviceValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The exported module instance */
|
||||||
|
const flicapp: FlicApp;
|
||||||
|
export default flicapp;
|
||||||
|
}
|
||||||
Vendored
+130
@@ -0,0 +1,130 @@
|
|||||||
|
// globals.d.ts
|
||||||
|
// TypeScript declarations for Flic Hub Studio Global Functions & Classes
|
||||||
|
// https://studio.flic.io/static/documentation/#165_global_functions_and_classes
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global Buffer class (Node.js-like, partial support)
|
||||||
|
* Unsupported: poolSize, indexOf, lastIndexOf, swap16/32/64, BigInt methods
|
||||||
|
* Supported encodings: 'utf8', 'hex', 'base64'
|
||||||
|
*/
|
||||||
|
declare class Buffer extends Uint8Array {
|
||||||
|
/** Create Buffer from string, array, etc. */
|
||||||
|
constructor(
|
||||||
|
source: string | ArrayBuffer | ArrayBufferView | number | Array<number>,
|
||||||
|
encoding?: "utf8" | "hex" | "base64",
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Length of the buffer */
|
||||||
|
readonly length: number;
|
||||||
|
|
||||||
|
/** Convert to string */
|
||||||
|
toString(
|
||||||
|
encoding?: "utf8" | "hex" | "base64",
|
||||||
|
start?: number,
|
||||||
|
end?: number,
|
||||||
|
): string;
|
||||||
|
|
||||||
|
/** Write string to buffer */
|
||||||
|
write(
|
||||||
|
string: string,
|
||||||
|
offset?: number,
|
||||||
|
length?: number,
|
||||||
|
encoding?: "utf8" | "hex" | "base64",
|
||||||
|
): number;
|
||||||
|
|
||||||
|
/** Copy between buffers */
|
||||||
|
copy(
|
||||||
|
target: Buffer,
|
||||||
|
targetStart?: number,
|
||||||
|
sourceStart?: number,
|
||||||
|
sourceEnd?: number,
|
||||||
|
): number;
|
||||||
|
|
||||||
|
/** Fill buffer with value */
|
||||||
|
fill(
|
||||||
|
value: string | number | Buffer,
|
||||||
|
offset?: number,
|
||||||
|
end?: number,
|
||||||
|
encoding?: "utf8" | "hex" | "base64",
|
||||||
|
): this;
|
||||||
|
|
||||||
|
/** Compare two buffers */
|
||||||
|
equals(otherBuffer: Buffer): boolean;
|
||||||
|
|
||||||
|
/** Slice buffer */
|
||||||
|
slice(start?: number, end?: number): Buffer;
|
||||||
|
|
||||||
|
/** Static: Allocate new buffer */
|
||||||
|
static alloc(
|
||||||
|
size: number,
|
||||||
|
fill?: string | number | Buffer,
|
||||||
|
encoding?: "utf8" | "hex" | "base64",
|
||||||
|
): Buffer;
|
||||||
|
|
||||||
|
/** Static: Concatenate buffers */
|
||||||
|
static concat(list: Buffer[], totalLength?: number): Buffer;
|
||||||
|
|
||||||
|
/** Static: From string or array */
|
||||||
|
static from(
|
||||||
|
source: string | ArrayBuffer | ArrayBufferView | Array<number>,
|
||||||
|
encoding?: "utf8" | "hex" | "base64",
|
||||||
|
): Buffer;
|
||||||
|
|
||||||
|
/** Static: Check if value is Buffer */
|
||||||
|
static isBuffer(obj: any): obj is Buffer;
|
||||||
|
|
||||||
|
/** Static: Byte length of string */
|
||||||
|
static byteLength(
|
||||||
|
string: string,
|
||||||
|
encoding?: "utf8" | "hex" | "base64",
|
||||||
|
): number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TextEncoder (Web API)
|
||||||
|
* Only UTF-8 supported
|
||||||
|
* encodeInto() is NOT supported
|
||||||
|
*/
|
||||||
|
declare class TextEncoder {
|
||||||
|
readonly encoding: "utf-8";
|
||||||
|
|
||||||
|
encode(input?: string): Uint8Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TextDecoder (Web API)
|
||||||
|
* Only UTF-8 supported
|
||||||
|
*/
|
||||||
|
declare class TextDecoder {
|
||||||
|
constructor(
|
||||||
|
label?: "utf-8",
|
||||||
|
options?: { fatal?: boolean; ignoreBOM?: boolean },
|
||||||
|
);
|
||||||
|
|
||||||
|
readonly encoding: "utf-8";
|
||||||
|
readonly fatal: boolean;
|
||||||
|
readonly ignoreBOM: boolean;
|
||||||
|
|
||||||
|
decode(input?: BufferSource, options?: { stream?: boolean }): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timer API (Node.js-like)
|
||||||
|
*/
|
||||||
|
declare function setTimeout(
|
||||||
|
callback: (...args: any[]) => void,
|
||||||
|
ms?: number,
|
||||||
|
...args: any[]
|
||||||
|
): number;
|
||||||
|
declare function setInterval(
|
||||||
|
callback: (...args: any[]) => void,
|
||||||
|
ms?: number,
|
||||||
|
...args: any[]
|
||||||
|
): number;
|
||||||
|
declare function clearTimeout(timeoutId: number): void;
|
||||||
|
declare function clearInterval(intervalId: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug printing (console.log alias)
|
||||||
|
*/
|
||||||
|
declare function print(...args: any[]): void;
|
||||||
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
declare module "hubinfo" {
|
||||||
|
export interface HubInfo {
|
||||||
|
serialNumber: string;
|
||||||
|
firmwareVersion: string;
|
||||||
|
}
|
||||||
|
const hubinfo: HubInfo;
|
||||||
|
export default hubinfo;
|
||||||
|
}
|
||||||
Vendored
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Flic Hub Studio - IR Module
|
||||||
|
* TypeScript Declaration File
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare module "ir" {
|
||||||
|
import { EventEmitter } from "events";
|
||||||
|
|
||||||
|
/** IR Class */
|
||||||
|
export interface IR extends EventEmitter {
|
||||||
|
on(event: "recordComplete", listener: (arr: Uint32Array) => void): this;
|
||||||
|
once(event: "recordComplete", listener: (arr: Uint32Array) => void): this;
|
||||||
|
emit(event: "recordComplete", arr: Uint32Array): boolean;
|
||||||
|
|
||||||
|
record(): void;
|
||||||
|
cancelRecord(): void;
|
||||||
|
play(arr: Uint32Array, callback: (error: any) => void): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ir: IR;
|
||||||
|
export default ir;
|
||||||
|
}
|
||||||
Vendored
+231
@@ -0,0 +1,231 @@
|
|||||||
|
// net.d.ts
|
||||||
|
// TypeScript declarations for Flic Hub Studio 'net' (TCP) module
|
||||||
|
// Based on: https://studio.flic.io/static/documentation/#63_tcp_module
|
||||||
|
|
||||||
|
declare module "net" {
|
||||||
|
import { EventEmitter } from "events";
|
||||||
|
/**
|
||||||
|
* Creates a TCP server.
|
||||||
|
*/
|
||||||
|
function createServer(
|
||||||
|
options?: ServerOptions,
|
||||||
|
connectionListener?: (socket: Socket) => void,
|
||||||
|
): Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a TCP socket and connects it to the specified port and host.
|
||||||
|
*/
|
||||||
|
function createConnection(
|
||||||
|
options: ConnectOptions,
|
||||||
|
connectionListener?: () => void,
|
||||||
|
): Socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternative signature for createConnection.
|
||||||
|
*/
|
||||||
|
function createConnection(
|
||||||
|
port: number,
|
||||||
|
host?: string,
|
||||||
|
connectionListener?: () => void,
|
||||||
|
): Socket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TCP Server class.
|
||||||
|
*/
|
||||||
|
class Server extends EventEmitter {
|
||||||
|
constructor(
|
||||||
|
options?: ServerOptions,
|
||||||
|
connectionListener?: (socket: Socket) => void,
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start listening for connections.
|
||||||
|
*/
|
||||||
|
listen(options: ListenOptions, callback?: () => void): this;
|
||||||
|
listen(
|
||||||
|
port?: number,
|
||||||
|
host?: string,
|
||||||
|
backlog?: number,
|
||||||
|
callback?: () => void,
|
||||||
|
): this;
|
||||||
|
listen(port?: number, host?: string, callback?: () => void): this;
|
||||||
|
listen(port?: number, callback?: () => void): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the server from accepting new connections.
|
||||||
|
*/
|
||||||
|
close(callback?: (err?: Error) => void): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the bound address, family, and port of the server.
|
||||||
|
*/
|
||||||
|
address(): AddressInfo | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously get the number of concurrent connections.
|
||||||
|
*/
|
||||||
|
getConnections(callback: (err: Error | null, count: number) => void): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the server is currently listening.
|
||||||
|
*/
|
||||||
|
readonly listening: boolean;
|
||||||
|
|
||||||
|
// Events
|
||||||
|
on(event: "close", listener: () => void): this;
|
||||||
|
on(event: "connection", listener: (socket: Socket) => void): this;
|
||||||
|
on(event: "error", listener: (err: Error) => void): this;
|
||||||
|
on(event: "listening", listener: () => void): this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TCP Socket class.
|
||||||
|
*/
|
||||||
|
export class Socket extends EventEmitter {
|
||||||
|
constructor(options?: SocketOptions);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiate a connection.
|
||||||
|
*/
|
||||||
|
connect(options: ConnectOptions, connectionListener?: () => void): this;
|
||||||
|
connect(port: number, host?: string, connectionListener?: () => void): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send data on the socket.
|
||||||
|
*/
|
||||||
|
write(
|
||||||
|
data: string | Buffer | Uint8Array,
|
||||||
|
encoding?: string,
|
||||||
|
callback?: (err?: Error) => void,
|
||||||
|
): boolean;
|
||||||
|
write(
|
||||||
|
data: string | Buffer | Uint8Array,
|
||||||
|
callback?: (err?: Error) => void,
|
||||||
|
): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Half-close the socket (send FIN).
|
||||||
|
*/
|
||||||
|
end(
|
||||||
|
data?: string | Buffer | Uint8Array,
|
||||||
|
encoding?: string,
|
||||||
|
callback?: () => void,
|
||||||
|
): this;
|
||||||
|
end(data?: string | Buffer | Uint8Array, callback?: () => void): this;
|
||||||
|
end(callback?: () => void): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abruptly close the socket.
|
||||||
|
*/
|
||||||
|
destroy(exception?: Error): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pause reading data.
|
||||||
|
*/
|
||||||
|
pause(): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resume reading after pause().
|
||||||
|
*/
|
||||||
|
resume(): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set encoding for incoming data.
|
||||||
|
*/
|
||||||
|
setEncoding(encoding?: "utf8" | "hex" | "base64" | null): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable Nagle's algorithm (enable no delay).
|
||||||
|
*/
|
||||||
|
setNoDelay(noDelay?: boolean): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/disable TCP keep-alive.
|
||||||
|
*/
|
||||||
|
setKeepAlive(enable?: boolean, initialDelay?: number): this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get local address info.
|
||||||
|
*/
|
||||||
|
address(): AddressInfo | null;
|
||||||
|
|
||||||
|
// Read-only properties
|
||||||
|
readonly connecting: boolean;
|
||||||
|
readonly destroyed: boolean;
|
||||||
|
readonly localAddress?: string;
|
||||||
|
readonly localPort?: number;
|
||||||
|
readonly remoteAddress?: string;
|
||||||
|
readonly remotePort?: number;
|
||||||
|
readonly remoteFamily?: string;
|
||||||
|
readonly bytesRead: number;
|
||||||
|
readonly bytesWritten: number;
|
||||||
|
|
||||||
|
// Events
|
||||||
|
on(event: "close", listener: (hadError: boolean) => void): this;
|
||||||
|
on(event: "connect", listener: () => void): this;
|
||||||
|
on(event: "data", listener: (data: Buffer | string) => void): this;
|
||||||
|
on(event: "drain", listener: () => void): this;
|
||||||
|
on(event: "end", listener: () => void): this;
|
||||||
|
on(event: "error", listener: (err: Error) => void): this;
|
||||||
|
on(
|
||||||
|
event: "lookup",
|
||||||
|
listener: (
|
||||||
|
err: Error | null,
|
||||||
|
address: string | null,
|
||||||
|
family: string,
|
||||||
|
host: string,
|
||||||
|
) => void,
|
||||||
|
): this;
|
||||||
|
on(event: "ready", listener: () => void): this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option Interfaces
|
||||||
|
|
||||||
|
interface ServerOptions {
|
||||||
|
/**
|
||||||
|
* Allow half-open TCP connections.
|
||||||
|
* Default: false
|
||||||
|
*/
|
||||||
|
allowHalfOpen?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pause incoming connections until resume() is called.
|
||||||
|
* Default: false
|
||||||
|
*/
|
||||||
|
pauseOnConnect?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SocketOptions {
|
||||||
|
/**
|
||||||
|
* Allow half-open TCP connections.
|
||||||
|
* Default: false
|
||||||
|
*/
|
||||||
|
allowHalfOpen?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConnectOptions {
|
||||||
|
port: number;
|
||||||
|
host?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ListenOptions {
|
||||||
|
port?: number;
|
||||||
|
host?: string;
|
||||||
|
backlog?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AddressInfo {
|
||||||
|
address: string;
|
||||||
|
family: "IPv4";
|
||||||
|
port: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Module export
|
||||||
|
const net: {
|
||||||
|
createServer: typeof createServer;
|
||||||
|
createConnection: typeof createConnection;
|
||||||
|
Server: typeof Server;
|
||||||
|
Socket: typeof Socket;
|
||||||
|
};
|
||||||
|
export default net;
|
||||||
|
}
|
||||||
Vendored
+26
@@ -0,0 +1,26 @@
|
|||||||
|
type HADevice = {
|
||||||
|
name: string;
|
||||||
|
identifiers: string[];
|
||||||
|
manufacturer: string;
|
||||||
|
model: string;
|
||||||
|
sw_version?: string;
|
||||||
|
hw_version?: string;
|
||||||
|
serial_number?: string;
|
||||||
|
configuration_url?: string;
|
||||||
|
};
|
||||||
|
type HAComponent =
|
||||||
|
| "cover"
|
||||||
|
| "select"
|
||||||
|
| "media_player"
|
||||||
|
| "light"
|
||||||
|
| "sensor"
|
||||||
|
| "binary_sensor"
|
||||||
|
| "button"
|
||||||
|
| "switch"
|
||||||
|
| "text"
|
||||||
|
| "device_automation";
|
||||||
|
type FlicMqttPrefix = {
|
||||||
|
nodeId: string;
|
||||||
|
objectId: string;
|
||||||
|
mqttPrefix: string;
|
||||||
|
};
|
||||||
Vendored
+44
@@ -0,0 +1,44 @@
|
|||||||
|
type HAmqttOptions = {
|
||||||
|
debug: boolean;
|
||||||
|
topics: {
|
||||||
|
homeassistant: string;
|
||||||
|
flic: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
type MQTTPublishOpt = {
|
||||||
|
retain?: boolean; // the server should retain this message and send it out again to new subscribers
|
||||||
|
dup?: boolean; // indicate the message is a duplicate because original wasn't ACKed (QoS > 0 only)
|
||||||
|
qos?: number;
|
||||||
|
};
|
||||||
|
type ButtonControllerOpt = {
|
||||||
|
debug: boolean;
|
||||||
|
};
|
||||||
|
type IRControllerOpt = {
|
||||||
|
uniqueId: string;
|
||||||
|
debug: boolean;
|
||||||
|
};
|
||||||
|
type FlicHubOptions = {
|
||||||
|
uniqueId: string;
|
||||||
|
debug: boolean;
|
||||||
|
};
|
||||||
|
type MQTTOptions = {
|
||||||
|
port: number;
|
||||||
|
client_id: string | number[];
|
||||||
|
keep_alive: number | boolean;
|
||||||
|
clean_session: boolean;
|
||||||
|
username?: string;
|
||||||
|
password?: string;
|
||||||
|
protocol_name: string;
|
||||||
|
protocol_level: number;
|
||||||
|
};
|
||||||
|
type Flic2HassMQTTOptions = MQTTOptions & {
|
||||||
|
host: string;
|
||||||
|
};
|
||||||
|
type Options = {
|
||||||
|
mqtt: Partial<Flic2HassMQTTOptions> & { host: string };
|
||||||
|
debug?: boolean;
|
||||||
|
ha?: Partial<HAmqttOptions>;
|
||||||
|
flicBtns?: Partial<ButtonControllerOpt> & { disabled?: boolean };
|
||||||
|
flicIR?: Partial<IRControllerOpt> & { disabled?: boolean };
|
||||||
|
flicHub?: Partial<FlicHubOptions> & { disabled?: boolean };
|
||||||
|
};
|
||||||
Reference in new issue
Block a user