Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3201786d41 | ||
|
|
0656f8f897 | ||
|
|
dbcfb74923 | ||
|
|
640156ba87 | ||
|
|
8d2f3da93e | ||
|
|
286e8c1758 | ||
|
|
c8f254d90a | ||
|
|
5e3d204019 | ||
|
|
926bcdfab8 |
+33
@@ -0,0 +1,33 @@
|
|||||||
|
# TouchKio - Supported Hardware
|
||||||
|
This document contains an incomplete list of device and display hardware combinations that are either intended to be tested or have already been tested.
|
||||||
|
|
||||||
|
The [release](https://github.com/leukipp/touchkio/releases) page has builds exclusively for **arm64**, but custom builds for other architectures can be made (see [Development](https://github.com/leukipp/touchkio?tab=readme-ov-file#development)), allowing the application to operate on any hardware.
|
||||||
|
At least the **minimal** features, such as displaying a **kiosk window** (which doesn't necessarily need to be Home Assistant) will work.
|
||||||
|
|
||||||
|
## Hardware
|
||||||
|
Any SBC clones of the Raspberry Pi that operate on **Raspberry Pi OS (64-bit)** and **Wayland** are likely to function as well.
|
||||||
|
|
||||||
|
### DSI
|
||||||
|
| Device | Display | Tested | Status | Notes |
|
||||||
|
| -------------- | ----------------------------------------------------------------------------------------------- | ------ | ----------------- | ------------------------------------------------------ |
|
||||||
|
| Raspberry Pi 3 | [Official 7" Touch Display 1](https://www.raspberrypi.com/products/raspberry-pi-touch-display/) | ❌ | Unknown | 99% chance that it is slow and the resolution sucks. |
|
||||||
|
| Raspberry Pi 3 | [Official 7" Touch Display 2](https://www.raspberrypi.com/products/touch-display-2/) | ❌ | Unknown | 99% chance that it is slow. |
|
||||||
|
| Raspberry Pi 4 | [Official 7" Touch Display 1](https://www.raspberrypi.com/products/raspberry-pi-touch-display/) | ❌ | Unknown | 99% chance that the resolution sucks. |
|
||||||
|
| Raspberry Pi 4 | [Official 7" Touch Display 2](https://www.raspberrypi.com/products/touch-display-2/) | ❌ | Optimistic | 99% chance that it fully works. |
|
||||||
|
| Raspberry Pi 5 | [Official 7" Touch Display 1](https://www.raspberrypi.com/products/raspberry-pi-touch-display/) | ❌ | Unknown | 99% chance that the resolution sucks. |
|
||||||
|
| Raspberry Pi 5 | [Official 7" Touch Display 2](https://www.raspberrypi.com/products/touch-display-2/) | ✅ | Fully operational | Working display power and brightness control via MQTT. |
|
||||||
|
|
||||||
|
### HDMI
|
||||||
|
| Device | Display | Tested | Status | Notes |
|
||||||
|
| -------------- | ----------------- | ------ | --------------------- | ----------------------------------------------------- |
|
||||||
|
| Raspberry Pi 4 | - | ✅ | Partially operational | - |
|
||||||
|
| Raspberry Pi 5 | Generic Non-Touch | ✅ | Partially operational | Display brightness control is not available via MQTT. |
|
||||||
|
|
||||||
|
## Contributions
|
||||||
|
In case your hardware is not listed above don't worry, give it a try.
|
||||||
|
Running `touchkio --web-url=https://demo.home-assistant.io` will most likely just work.
|
||||||
|
The only problems that may arise are when controlling the display via the Home Assistant integration.
|
||||||
|
|
||||||
|
- If you encounter any problems, please create a new [issue](https://github.com/leukipp/touchkio/issues).
|
||||||
|
- If you encounter any problems and are able to fix it yourself, feel free to create a [pull request](https://github.com/leukipp/touchkio/pulls).
|
||||||
|
- If everything works as expected and your hardware is not yet listed, you are welcome to add it and create a [pull request](https://github.com/leukipp/touchkio/pulls).
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
# TouchKio
|
# TouchKio
|
||||||
**TouchKio** is a Node.js application that utilizes **Electron** to create a kiosk mode specifically designed for a Home Assistant dashboard.
|
**TouchKio** is a Node.js application that utilizes **Electron** to create a kiosk mode specifically designed for a Home Assistant dashboard (or any other [webpage](https://github.com/leukipp/touchkio/blob/main/HARDWARE.md)).
|
||||||
This tool is packaged as a **.deb** file, making it easy to launch the kiosk mode on a **Raspberry Pi** equipped with the official 7" touch display.
|
This tool is packaged as a **.deb** file, making it easy to launch the kiosk mode on a **Raspberry Pi** (or similar [hardware](https://github.com/leukipp/touchkio/blob/main/HARDWARE.md)) equipped with a touch display.
|
||||||
|
|
||||||
[](https://github.com/leukipp/touchkio/blob/main/img/display.png)
|
[](https://github.com/leukipp/touchkio/blob/main/img/display.png)
|
||||||
|
|
||||||
This implementation addresses common issues encountered when using the built-in browser running in fullscreen mode on the Raspberry Pi touch display.
|
This implementation addresses common issues encountered when using the built-in browser running in fullscreen mode on the Raspberry Pi with touch display.
|
||||||
Moreover, the device running the **kiosk application** also offers several **Home Assistant MQTT** sensors, enhancing it's functionality for automation purposes.
|
Moreover, the device running the **kiosk application** also offers several **Home Assistant MQTT** sensors, enhancing it's functionality for automation purposes.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@@ -22,8 +22,8 @@ The kiosk application can be executed with command line arguments to load a **Ho
|
|||||||
Additionally, a **MQTT endpoint** can be defined, allowing the application to provide controls and sensors for the Raspberry Pi and the connected touch display.
|
Additionally, a **MQTT endpoint** can be defined, allowing the application to provide controls and sensors for the Raspberry Pi and the connected touch display.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
Before you begin, ensure that you have a Raspberry Pi configured and running with a compatible touch display.
|
Before you begin, make sure that you have a Raspberry Pi configured and operational with a [compatible touch display](https://github.com/leukipp/touchkio/blob/main/HARDWARE.md).
|
||||||
This guide assumes you are using **Raspberry Pi OS Lite (64-bit)**, which is recommended for kiosk applications due to its **lightweight** nature and minimal overhead.
|
This guide assumes that you are using the latest version of **Raspberry Pi OS (64-bit)** together with a **Wayland** based desktop environment.
|
||||||
|
|
||||||
### Optional
|
### Optional
|
||||||
To utilize the sensor features of your display through Home Assistant, it's essential to have a **MQTT broker running** and the **MQTT integration installed** on your Home Assistant instance.
|
To utilize the sensor features of your display through Home Assistant, it's essential to have a **MQTT broker running** and the **MQTT integration installed** on your Home Assistant instance.
|
||||||
@@ -96,15 +96,23 @@ touchkio --web-url=http://192.168.1.42:8123 --mqtt-url=mqtt://192.168.1.42:1883
|
|||||||
If you want to create your own local build install [nodejs](https://pimylifeup.com/raspberry-pi-nodejs) and [yarn](https://classic.yarnpkg.com/lang/en/docs/install) on your Raspberry Pi.
|
If you want to create your own local build install [nodejs](https://pimylifeup.com/raspberry-pi-nodejs) and [yarn](https://classic.yarnpkg.com/lang/en/docs/install) on your Raspberry Pi.
|
||||||
|
|
||||||
Clone this repository and run `yarn install` to install the dependencies.
|
Clone this repository and run `yarn install` to install the dependencies.
|
||||||
Then use `yarn start` to execute the `start` script located in the `package.json` file.
|
Then use `yarn start` to execute the `start` script located in the [package.json](https://github.com/leukipp/touchkio/blob/main/package.json) file.
|
||||||
There you can adjust the `--web-url` and other arguments for development runs.
|
There you can adjust the `--web-url` and other arguments for development runs.
|
||||||
|
|
||||||
|
If you connect to your Raspberry Pi via SSH, you must export the display variables so that the kiosk application can be loaded in the desktop environment:
|
||||||
|
```bash
|
||||||
|
export DISPLAY=":0"
|
||||||
|
export WAYLAND_DISPLAY="wayland-0"
|
||||||
|
```
|
||||||
|
|
||||||
### The nitty gritty
|
### The nitty gritty
|
||||||
|
|
||||||
<details><summary>Don't waste your time reading this.</summary><div></br>
|
<details><summary>Don't waste your time reading this.</summary><div></br>
|
||||||
|
|
||||||
To enable **write access** to the `/sys/class/backlight/10-0045/bl_power` and `/sys/class/backlight/10-0045/brightness` files, you need to set up a **udev rule**.
|
To enable **write access** to the `/sys/class/backlight/10-0045/bl_power` and `/sys/class/backlight/10-0045/brightness` files, you need to set up a **udev rule**. In case you don't use the official touch display you may have to change the rules, that are located under `/etc/udev/rules.d/backlight-permissions.rules`.
|
||||||
This is done within the `install.sh` script, which also creates a `.service` file.
|
|
||||||
|
This rule is created via the [install.sh](https://github.com/leukipp/touchkio/blob/main/install.sh) script, which also creates a service file.
|
||||||
|
The service file is located at `~/.config/systemd/user/touchkio.service` and starts the `/usr/bin/touchkio` process when the graphical user interface is loaded.
|
||||||
While creating a service file is optional, it's highly recommended if you want your Raspberry Pi to automatically boot into kiosk mode.
|
While creating a service file is optional, it's highly recommended if you want your Raspberry Pi to automatically boot into kiosk mode.
|
||||||
|
|
||||||
The Raspberry Pi's **build-in screen blanking** function uses the command `swayidle -w timeout 600 'wlopm --off \*' resume 'wlopm --on \*' &` inside `~/.config/labwc/autostart` to blank the screen after **10 minutes**.
|
The Raspberry Pi's **build-in screen blanking** function uses the command `swayidle -w timeout 600 'wlopm --off \*' resume 'wlopm --on \*' &` inside `~/.config/labwc/autostart` to blank the screen after **10 minutes**.
|
||||||
@@ -116,9 +124,14 @@ I managed to achieve this for the `brightness` file by implementing a simple `fs
|
|||||||
However, I found that it **never triggered** for the `bl_power` file.
|
However, I found that it **never triggered** for the `bl_power` file.
|
||||||
Although the file content changes, none of the filesystem listeners where fired.
|
Although the file content changes, none of the filesystem listeners where fired.
|
||||||
This could be due to `swayidle`/`wlopm` performing write actions at a deeper level that are not detectable by file listeners.
|
This could be due to `swayidle`/`wlopm` performing write actions at a deeper level that are not detectable by file listeners.
|
||||||
As a result, I went for a **polling solution**, checking the state of both files every **500 milliseconds** for any changes.
|
As a result, I went for a **polling solution**, checking the state of the file every **500 milliseconds** for any changes.
|
||||||
While I understand this is not ideal, it's necessary to ensure proper functionality.
|
While I understand this is not ideal, it's necessary to ensure proper functionality.
|
||||||
|
|
||||||
|
The display power status and brightness can be adjusted via the MQTT integration.
|
||||||
|
**Support** for changing the power status for **DSI and HDMI** displays is achieved by checking for connected screens in `/sys/class/drm/*/status`.
|
||||||
|
Support for changing the brightness of connected display is implemented by using `/sys/class/backlight/*/brightness`.
|
||||||
|
In cases where no supported backlight device is found, the Home Assistant light entity will only show an on/off switch without brightness control.
|
||||||
|
|
||||||
Keep in mind that default arguments are stored as plain text in `~/.config/touchkio/Arguments.json`.
|
Keep in mind that default arguments are stored as plain text in `~/.config/touchkio/Arguments.json`.
|
||||||
This file also includes the **MQTT user password**, which is somewhat obfuscated/encrypted, but in a way that it could be easily reverse engineered.
|
This file also includes the **MQTT user password**, which is somewhat obfuscated/encrypted, but in a way that it could be easily reverse engineered.
|
||||||
Implementing stronger **security measures** would complicate the setup process and could discourage some users from configuring the application properly.
|
Implementing stronger **security measures** would complicate the setup process and could discourage some users from configuring the application properly.
|
||||||
@@ -126,10 +139,10 @@ When using the kiosk application without initializing the default arguments, you
|
|||||||
This means that the password may be stored as plain text in various files, such as `touchkio.service`, `~/.bash_history`, etc.
|
This means that the password may be stored as plain text in various files, such as `touchkio.service`, `~/.bash_history`, etc.
|
||||||
|
|
||||||
To resolve the issue where the first **touch** on a **turned-off screen** triggers a **click event** (potentially activating Home Assistant actions), I implemented a workaround.
|
To resolve the issue where the first **touch** on a **turned-off screen** triggers a **click event** (potentially activating Home Assistant actions), I implemented a workaround.
|
||||||
When the screen **turns off**, I remove **focus** from the kiosk window.
|
When the screen **turns off** the **focus** is removed from the kiosk window.
|
||||||
This way, the first click only turns the screen on and focuses the window, allowing subsequent clicks to work as expected.
|
This way, the first click only turns the screen on and focuses the window, allowing subsequent clicks to work as expected.
|
||||||
|
|
||||||
Additionally, to address the problem that scrolling on the Raspberry Pi only works with the **web browser scrollbar** on the right, I configured the Electron app to **simulate a touch device** using `Emulation.setEmitTouchEventsForMouse`.
|
Additionally, to address the problem that scrolling on the Raspberry Pi only works with the **web browser scrollbar** on the right, the Electron app is configured to **simulate a touch device** using `Emulation.setEmitTouchEventsForMouse`.
|
||||||
This adjustment provides a user experience similar to that of a proper mobile device.
|
This adjustment provides a user experience similar to that of a proper mobile device.
|
||||||
|
|
||||||
Electron apps are known to be **resource intensive** due to their architecture and the inclusion of a full web browser environment. If you just run the kiosk application without other heavy loads, everything should run smoothly.
|
Electron apps are known to be **resource intensive** due to their architecture and the inclusion of a full web browser environment. If you just run the kiosk application without other heavy loads, everything should run smoothly.
|
||||||
@@ -137,10 +150,12 @@ Electron apps are known to be **resource intensive** due to their architecture a
|
|||||||
</div></details>
|
</div></details>
|
||||||
|
|
||||||
## Issues
|
## Issues
|
||||||
- Currently, only the Raspberry Pi 5 in combination with the new touch display 2 supports the MQTT integration.
|
Please have a look into the [hardware](https://github.com/leukipp/touchkio/blob/main/HARDWARE.md) documentation if you ran into any issues.
|
||||||
- Other variations, such as Raspberry Pi 4 or Raspberry Pi 5 with touch display 1, could likely be added, but this will require additional testing and contributions via pull requests.
|
|
||||||
|
- Depending on the display hardware you are using, some features of the MQTT integration may not fully work (e.g. display brightness control).
|
||||||
|
- This is especially common when using X11 instead of Wayland (default on Raspberry Pi OS).
|
||||||
- You can use Raspberry Pi's build-in screen blanking functionality, however, if the screen is turned on through Home Assistant after being automatically turned off, it will remain on indefinitely.
|
- You can use Raspberry Pi's build-in screen blanking functionality, however, if the screen is turned on through Home Assistant after being automatically turned off, it will remain on indefinitely.
|
||||||
- It's recommended to either use the built-in screen blanking feature or implement a Home Assistant automation (e.g., presence detection) to manage the screen status.
|
- It's recommended to either use the built-in screen blanking feature or implement a Home Assistant automation (e.g. presence detection) to manage the screen status.
|
||||||
- Hyperlinks that redirect the browser away from the main window are intentionally disabled.
|
- Hyperlinks that redirect the browser away from the main window are intentionally disabled.
|
||||||
- This decision was made to maintain a clean design, as navigation buttons to move back and forth between different sites were not included.
|
- This decision was made to maintain a clean design, as navigation buttons to move back and forth between different sites were not included.
|
||||||
- On the Raspberry Pi terminal you may see some *ERROR:gbm_wrapper.cc* messages.
|
- On the Raspberry Pi terminal you may see some *ERROR:gbm_wrapper.cc* messages.
|
||||||
|
|||||||
@@ -13,6 +13,11 @@ const { app } = require("electron");
|
|||||||
* initialization tasks.
|
* initialization tasks.
|
||||||
*/
|
*/
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
|
const lock = app.requestSingleInstanceLock();
|
||||||
|
if (!lock) {
|
||||||
|
console.error("TouchKio is already running");
|
||||||
|
return app.quit();
|
||||||
|
}
|
||||||
let args = parseArgs(process);
|
let args = parseArgs(process);
|
||||||
let argsProvided = !!Object.keys(args).length;
|
let argsProvided = !!Object.keys(args).length;
|
||||||
|
|
||||||
@@ -130,12 +135,7 @@ const promptArgs = async (proc) => {
|
|||||||
const answer = await read.question(prompt);
|
const answer = await read.question(prompt);
|
||||||
const value = (answer.trim() || fallback.match(/[YN]/)[0]).toLowerCase();
|
const value = (answer.trim() || fallback.match(/[YN]/)[0]).toLowerCase();
|
||||||
if (!["y", "yes"].includes(value)) {
|
if (!["y", "yes"].includes(value)) {
|
||||||
ignore = ignore.concat([
|
ignore = ignore.concat(["mqtt_url", "mqtt_user", "mqtt_password", "mqtt_discovery"]);
|
||||||
"mqtt_url",
|
|
||||||
"mqtt_user",
|
|
||||||
"mqtt_password",
|
|
||||||
"mqtt_discovery",
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
} else if (key === "check") {
|
} else if (key === "check") {
|
||||||
const json = JSON.stringify(args, null, 2);
|
const json = JSON.stringify(args, null, 2);
|
||||||
|
|||||||
+22
-3
@@ -47,13 +47,32 @@ WantedBy=default.target
|
|||||||
EOF"
|
EOF"
|
||||||
|
|
||||||
systemctl --user enable "$(basename "$SERVICE_FILE")" || { echo "Failed to enable service $SERVICE_FILE"; exit 1; }
|
systemctl --user enable "$(basename "$SERVICE_FILE")" || { echo "Failed to enable service $SERVICE_FILE"; exit 1; }
|
||||||
|
echo "Service $SERVICE_FILE enabled"
|
||||||
|
|
||||||
# Create the udev rule for backlight
|
# Create the udev rule for backlight
|
||||||
echo -e "\nCreating udev rule for backlight..."
|
echo -e "\nCreating udev rule for backlight..."
|
||||||
|
|
||||||
sudo bash -c 'cat << EOF > /etc/udev/rules.d/backlight-permissions.rules
|
UDEV_FILE="/etc/udev/rules.d/backlight-permissions.rules"
|
||||||
SUBSYSTEM=="backlight", KERNEL=="10-0045", RUN+="/bin/chmod 666 /sys/class/backlight/%k/bl_power /sys/class/backlight/%k/brightness"
|
sudo bash -c "cat << EOF > \"$UDEV_FILE\"
|
||||||
EOF'
|
SUBSYSTEM==\"backlight\", KERNEL==\"10-0045\", RUN+=\"/bin/chmod 666 /sys/class/backlight/%k/bl_power /sys/class/backlight/%k/brightness\"
|
||||||
|
EOF"
|
||||||
|
echo "Rule $UDEV_FILE created"
|
||||||
|
|
||||||
|
# Export display variables
|
||||||
|
echo -e "\nExporting display variables..."
|
||||||
|
|
||||||
|
if [ -z "$DISPLAY" ]; then
|
||||||
|
export DISPLAY=":0"
|
||||||
|
echo "DISPLAY was not set, defaulting to \"$DISPLAY\""
|
||||||
|
else
|
||||||
|
echo "DISPLAY is set to \"$DISPLAY\""
|
||||||
|
fi
|
||||||
|
if [ -z "$WAYLAND_DISPLAY" ]; then
|
||||||
|
export WAYLAND_DISPLAY="wayland-0"
|
||||||
|
echo "WAYLAND_DISPLAY was not set, defaulting to \"$WAYLAND_DISPLAY\""
|
||||||
|
else
|
||||||
|
echo "WAYLAND_DISPLAY is set to \"$WAYLAND_DISPLAY\""
|
||||||
|
fi
|
||||||
|
|
||||||
# Start the setup mode
|
# Start the setup mode
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
+6
-2
@@ -2,7 +2,7 @@
|
|||||||
"name": "touchkio",
|
"name": "touchkio",
|
||||||
"description": "Home Assistant Touch Kiosk",
|
"description": "Home Assistant Touch Kiosk",
|
||||||
"author": "leukipp",
|
"author": "leukipp",
|
||||||
"version": "0.0.3",
|
"version": "1.0.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -49,12 +49,16 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"prettier": {
|
||||||
|
"printWidth": 120
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@electron-forge/cli": "^7.6.0",
|
"@electron-forge/cli": "^7.6.0",
|
||||||
"@electron-forge/maker-deb": "^7.6.0",
|
"@electron-forge/maker-deb": "^7.6.0",
|
||||||
"@electron-forge/maker-zip": "^7.6.0",
|
"@electron-forge/maker-zip": "^7.6.0",
|
||||||
"@electron-forge/publisher-github": "^7.6.0",
|
"@electron-forge/publisher-github": "^7.6.0",
|
||||||
"electron": "^33.2.1"
|
"electron": "^33.3.1",
|
||||||
|
"prettier": "^3.4.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mqtt": "^5.10.3"
|
"mqtt": "^5.10.3"
|
||||||
|
|||||||
+145
-73
@@ -1,13 +1,22 @@
|
|||||||
const os = require("os");
|
const os = require("os");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
const process = require("child_process");
|
const process = require("child_process");
|
||||||
|
|
||||||
global.HARDWARE = global.HARDWARE || {
|
global.HARDWARE = global.HARDWARE || {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
status: "invalid",
|
status: "invalid",
|
||||||
display: {
|
display: {
|
||||||
status: null,
|
name: null,
|
||||||
brightness: null,
|
status: {
|
||||||
|
path: null,
|
||||||
|
value: null,
|
||||||
|
},
|
||||||
|
brightness: {
|
||||||
|
path: null,
|
||||||
|
value: null,
|
||||||
|
max: null,
|
||||||
|
},
|
||||||
notifiers: [],
|
notifiers: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -23,20 +32,29 @@ const init = async (args) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check supported hardware
|
// Check device support
|
||||||
if (!hardwareExists()) {
|
if (!compatibleDevice()) {
|
||||||
console.warn("Hardware not supported");
|
console.warn("Device not supported");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check supported model
|
// Check model support
|
||||||
const model = getModel();
|
const model = getModel();
|
||||||
if (!model || !model.includes("Raspberry Pi 5")) {
|
if (!model || !model.includes("Raspberry Pi")) {
|
||||||
console.warn(`Device ${model} not supported`);
|
console.warn(`${model} not supported`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("\nModel:", getModel());
|
// Init globals
|
||||||
|
HARDWARE.display.name = getDisplayName();
|
||||||
|
HARDWARE.display.status.path = getDisplayStatusPath(HARDWARE.display.name);
|
||||||
|
HARDWARE.display.brightness.path = getDisplayBrightnessPath(HARDWARE.display.name);
|
||||||
|
HARDWARE.display.brightness.max = getDisplayBrightnessMax();
|
||||||
|
HARDWARE.initialized = true;
|
||||||
|
HARDWARE.status = "valid";
|
||||||
|
|
||||||
|
// Show device infos
|
||||||
|
console.log("\nModel:", model);
|
||||||
console.log("Serial Number:", getSerialNumber());
|
console.log("Serial Number:", getSerialNumber());
|
||||||
console.log("Host Name:", getHostName());
|
console.log("Host Name:", getHostName());
|
||||||
console.log("Up Time:", getUpTime());
|
console.log("Up Time:", getUpTime());
|
||||||
@@ -44,12 +62,11 @@ const init = async (args) => {
|
|||||||
console.log("Memory Usage:", getMemoryUsage());
|
console.log("Memory Usage:", getMemoryUsage());
|
||||||
console.log("Processor Usage:", getProcessorUsage());
|
console.log("Processor Usage:", getProcessorUsage());
|
||||||
console.log("Processor Temperature:", getProcessorTemperature());
|
console.log("Processor Temperature:", getProcessorTemperature());
|
||||||
console.log("Display Status:", getDisplayStatus());
|
|
||||||
console.log("Display Brightness:", getDisplayBrightness(), "\n");
|
|
||||||
|
|
||||||
// Init globals
|
// Show display infos
|
||||||
HARDWARE.initialized = true;
|
console.log("\nDisplay Name:", HARDWARE.display.name);
|
||||||
HARDWARE.status = "valid";
|
console.log(`Display Status [${HARDWARE.display.status.path}]:`, getDisplayStatus());
|
||||||
|
console.log(`Display Brightness [${HARDWARE.display.brightness.path}]:`, getDisplayBrightness(), "\n");
|
||||||
|
|
||||||
// Check for display changes
|
// Check for display changes
|
||||||
setInterval(update, 500);
|
setInterval(update, 500);
|
||||||
@@ -64,40 +81,43 @@ const update = () => {
|
|||||||
if (!HARDWARE.initialized) {
|
if (!HARDWARE.initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const path = "/sys/class/backlight/10-0045";
|
|
||||||
|
|
||||||
// Display status has changed
|
// Display status has changed
|
||||||
const status = fs.readFileSync(`${path}/bl_power`, "utf8").trim();
|
if (HARDWARE.display.status.path !== null) {
|
||||||
if (status !== HARDWARE.display.status) {
|
const status = fs.readFileSync(`${HARDWARE.display.status.path}/enabled`, "utf8").trim();
|
||||||
|
if (status !== HARDWARE.display.status.value) {
|
||||||
console.log("Update Display Status:", getDisplayStatus());
|
console.log("Update Display Status:", getDisplayStatus());
|
||||||
HARDWARE.display.status = status;
|
HARDWARE.display.status.value = status;
|
||||||
HARDWARE.display.notifiers.forEach((notifier) => {
|
HARDWARE.display.notifiers.forEach((notifier) => {
|
||||||
notifier();
|
notifier();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Display brightness has changed
|
// Display brightness has changed
|
||||||
const brightness = fs.readFileSync(`${path}/brightness`, "utf8").trim();
|
if (HARDWARE.display.brightness.path !== null) {
|
||||||
if (brightness !== HARDWARE.display.brightness) {
|
const brightness = fs.readFileSync(`${HARDWARE.display.brightness.path}/brightness`, "utf8").trim();
|
||||||
|
if (brightness !== HARDWARE.display.brightness.value) {
|
||||||
console.log("Update Display Brightness:", getDisplayBrightness());
|
console.log("Update Display Brightness:", getDisplayBrightness());
|
||||||
HARDWARE.display.brightness = brightness;
|
HARDWARE.display.brightness.value = brightness;
|
||||||
HARDWARE.display.notifiers.forEach((notifier) => {
|
HARDWARE.display.notifiers.forEach((notifier) => {
|
||||||
notifier();
|
notifier();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies hardware compatibility by checking the presence of necessary sys files.
|
* Verifies device compatibility by checking the presence of necessary sys files.
|
||||||
*
|
*
|
||||||
* @returns {bool} Returns true if all files exists.
|
* @returns {bool} Returns true if all files exists.
|
||||||
*/
|
*/
|
||||||
const hardwareExists = () => {
|
const compatibleDevice = () => {
|
||||||
const files = [
|
const files = [
|
||||||
|
"/sys/class/drm",
|
||||||
|
"/sys/class/backlight",
|
||||||
"/sys/firmware/devicetree/base/model",
|
"/sys/firmware/devicetree/base/model",
|
||||||
"/sys/firmware/devicetree/base/serial-number",
|
"/sys/firmware/devicetree/base/serial-number",
|
||||||
"/sys/class/backlight/10-0045/brightness",
|
|
||||||
"/sys/class/backlight/10-0045/bl_power",
|
|
||||||
];
|
];
|
||||||
return files.every((file) => fs.existsSync(file));
|
return files.every((file) => fs.existsSync(file));
|
||||||
};
|
};
|
||||||
@@ -117,9 +137,7 @@ const getModel = () => {
|
|||||||
* @returns {string|null} The serial number of the Raspberry Pi or null if an error occurs.
|
* @returns {string|null} The serial number of the Raspberry Pi or null if an error occurs.
|
||||||
*/
|
*/
|
||||||
const getSerialNumber = () => {
|
const getSerialNumber = () => {
|
||||||
return execSyncCommand("cat", [
|
return execSyncCommand("cat", ["/sys/firmware/devicetree/base/serial-number"]);
|
||||||
"/sys/firmware/devicetree/base/serial-number",
|
|
||||||
]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,6 +210,41 @@ const getProcessorTemperature = () => {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the primary display name using `wlopm`.
|
||||||
|
*
|
||||||
|
* @returns {string|null} The output of the command or null if an error occurs.
|
||||||
|
*/
|
||||||
|
const getDisplayName = () => {
|
||||||
|
const status = execSyncCommand("wlopm", []);
|
||||||
|
if (status !== null) {
|
||||||
|
const out = status.split("\n")[0].split(" ");
|
||||||
|
return out.shift();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current display status path using `/sys/class/drm`.
|
||||||
|
*
|
||||||
|
* @param {string} name - Primary display name.
|
||||||
|
* @returns {string|null} The display status path or null if nothing was found.
|
||||||
|
*/
|
||||||
|
const getDisplayStatusPath = (name) => {
|
||||||
|
const drm = "/sys/class/drm";
|
||||||
|
for (const card of fs.readdirSync(drm)) {
|
||||||
|
const statusFile = path.join(drm, card, "status");
|
||||||
|
if (!fs.existsSync(statusFile)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const content = fs.readFileSync(statusFile, "utf8").trim();
|
||||||
|
if (card.includes(name) && content === "connected") {
|
||||||
|
return path.join(drm, card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current display power status using `wlopm`.
|
* Gets the current display power status using `wlopm`.
|
||||||
*
|
*
|
||||||
@@ -200,18 +253,10 @@ const getProcessorTemperature = () => {
|
|||||||
const getDisplayStatus = () => {
|
const getDisplayStatus = () => {
|
||||||
const status = execSyncCommand("wlopm", []);
|
const status = execSyncCommand("wlopm", []);
|
||||||
if (status !== null) {
|
if (status !== null) {
|
||||||
return status.slice(status.lastIndexOf(" ") + 1).toUpperCase();
|
const out = status.split("\n")[0].split(" ");
|
||||||
|
return out.pop().toUpperCase();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
/* This also works, but it's better to use `wlopm` for getter and setter methods.
|
|
||||||
const status = execSyncCommand("cat", [
|
|
||||||
"/sys/class/backlight/10-0045/bl_power",
|
|
||||||
]);
|
|
||||||
if (status !== null) {
|
|
||||||
return status === "0" ? "ON" : "OFF";
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,60 +274,85 @@ const setDisplayStatus = (status, callback = null) => {
|
|||||||
if (typeof callback === "function") callback(null, "Invalid status");
|
if (typeof callback === "function") callback(null, "Invalid status");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const args = status === "ON" ? ["--on", "*"] : ["--off", "*"];
|
const args = [`--${status.toLowerCase()}`, HARDWARE.display.name];
|
||||||
execAsyncCommand("wlopm", args, callback);
|
execAsyncCommand("wlopm", args, callback);
|
||||||
|
|
||||||
/* This also works, but interferes with the built-in screen blanking function.
|
|
||||||
const value = status === "ON" ? "0" : "4";
|
|
||||||
const proc = execAsyncCommand(
|
|
||||||
"tee",
|
|
||||||
["/sys/class/backlight/10-0045/bl_power"],
|
|
||||||
callback
|
|
||||||
);
|
|
||||||
proc.stdin.write(value.toString());
|
|
||||||
proc.stdin.end();
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current display brightness level using `/sys/class/backlight/10-0045/brightness`.
|
* Gets the current display brightness path using `/sys/class/backlight`.
|
||||||
*
|
*
|
||||||
* This function retrieves the brightness level, which is in the range of 0-31,
|
* @param {string} name - Primary display name.
|
||||||
* and maps it to a percentage in the range of 0-100 percent.
|
* @returns {string|null} The display brightness path or null if nothing was found.
|
||||||
*
|
|
||||||
* @returns {number|null} The brightness level as a percentage or null if an error occurs.
|
|
||||||
*/
|
*/
|
||||||
const getDisplayBrightness = () => {
|
const getDisplayBrightnessPath = (name) => {
|
||||||
const brightness = execSyncCommand("cat", [
|
const backlight = "/sys/class/backlight";
|
||||||
"/sys/class/backlight/10-0045/brightness",
|
for (const address of fs.readdirSync(backlight)) {
|
||||||
]);
|
const nameFile = path.join(backlight, address, "display_name");
|
||||||
if (brightness !== null) {
|
if (!fs.existsSync(nameFile)) {
|
||||||
return Math.round((parseInt(brightness, 10) / 31) * 100);
|
continue;
|
||||||
|
}
|
||||||
|
const content = fs.readFileSync(nameFile, "utf8").trim();
|
||||||
|
if (content.includes(name)) {
|
||||||
|
return path.join(backlight, address);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the display brightness level using `/sys/class/backlight/10-0045/brightness`.
|
* Gets the maximum display brightness value using `/sys/class/backlight/.../max_brightness`.
|
||||||
*
|
*
|
||||||
* This function takes a brightness value in the range of 1-100 percent,
|
* @returns {number|null} The brightness maximum value or null if an error occurs.
|
||||||
* maps it to the range of 0-31, and writes it to the system.
|
*/
|
||||||
|
const getDisplayBrightnessMax = () => {
|
||||||
|
if (!HARDWARE.display.brightness.path) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const max = execSyncCommand("cat", [`${HARDWARE.display.brightness.path}/max_brightness`]);
|
||||||
|
if (max !== null) {
|
||||||
|
return parseInt(max, 10);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current display brightness level using `/sys/class/backlight/.../brightness`.
|
||||||
|
*
|
||||||
|
* @returns {number|null} The brightness level as a percentage or null if an error occurs.
|
||||||
|
*/
|
||||||
|
const getDisplayBrightness = () => {
|
||||||
|
if (!HARDWARE.display.brightness.path) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const brightness = execSyncCommand("cat", [`${HARDWARE.display.brightness.path}/brightness`]);
|
||||||
|
if (brightness !== null) {
|
||||||
|
const max = HARDWARE.display.brightness.max;
|
||||||
|
return Math.round((parseInt(brightness, 10) / max) * 100);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the display brightness level using `/sys/class/backlight/.../brightness`.
|
||||||
|
*
|
||||||
|
* This function takes a brightness value between 1 to 100 percent,
|
||||||
|
* maps it to the proper range and writes it to the system.
|
||||||
*
|
*
|
||||||
* @param {number} brightness - The desired brightness level (1-100).
|
* @param {number} brightness - The desired brightness level (1-100).
|
||||||
* @param {function} callback - A callback function that receives the output or error.
|
* @param {function} callback - A callback function that receives the output or error.
|
||||||
*/
|
*/
|
||||||
const setDisplayBrightness = (brightness, callback = null) => {
|
const setDisplayBrightness = (brightness, callback = null) => {
|
||||||
|
if (!HARDWARE.display.brightness.path) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (typeof brightness !== "number" || brightness < 1 || brightness > 100) {
|
if (typeof brightness !== "number" || brightness < 1 || brightness > 100) {
|
||||||
console.error("Brightness must be a number between 1 and 100");
|
console.error("Brightness must be a number between 1 and 100");
|
||||||
if (typeof callback === "function") callback(null, "Invalid brightness");
|
if (typeof callback === "function") callback(null, "Invalid brightness");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const value = Math.max(1, Math.min(Math.round((brightness / 100) * 31), 31));
|
const max = HARDWARE.display.brightness.max;
|
||||||
const proc = execAsyncCommand(
|
const value = Math.max(1, Math.min(Math.round((brightness / 100) * max), max));
|
||||||
"tee",
|
const proc = execAsyncCommand("tee", [`${HARDWARE.display.brightness.path}/brightness`], callback);
|
||||||
["/sys/class/backlight/10-0045/brightness"],
|
|
||||||
callback
|
|
||||||
);
|
|
||||||
proc.stdin.write(value.toString());
|
proc.stdin.write(value.toString());
|
||||||
proc.stdin.end();
|
proc.stdin.end();
|
||||||
};
|
};
|
||||||
@@ -320,9 +390,7 @@ const rebootSystem = (callback = null) => {
|
|||||||
*/
|
*/
|
||||||
const execSyncCommand = (cmd, args = []) => {
|
const execSyncCommand = (cmd, args = []) => {
|
||||||
try {
|
try {
|
||||||
const output = process.execSync([cmd, ...args].join(" "), {
|
const output = process.execSync([cmd, ...args].join(" "), { encoding: "utf8" });
|
||||||
encoding: "utf8",
|
|
||||||
});
|
|
||||||
return output.trim().replace(/\0/g, "");
|
return output.trim().replace(/\0/g, "");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Execute Sync:", error.message);
|
console.error("Execute Sync:", error.message);
|
||||||
@@ -380,8 +448,12 @@ module.exports = {
|
|||||||
getMemoryUsage,
|
getMemoryUsage,
|
||||||
getProcessorUsage,
|
getProcessorUsage,
|
||||||
getProcessorTemperature,
|
getProcessorTemperature,
|
||||||
|
getDisplayName,
|
||||||
|
getDisplayStatusPath,
|
||||||
getDisplayStatus,
|
getDisplayStatus,
|
||||||
setDisplayStatus,
|
setDisplayStatus,
|
||||||
|
getDisplayBrightnessPath,
|
||||||
|
getDisplayBrightnessMax,
|
||||||
getDisplayBrightness,
|
getDisplayBrightness,
|
||||||
setDisplayBrightness,
|
setDisplayBrightness,
|
||||||
shutdownSystem,
|
shutdownSystem,
|
||||||
|
|||||||
+89
-149
@@ -90,12 +90,12 @@ const init = async (args) => {
|
|||||||
updateDisplay(INTEGRATION.client);
|
updateDisplay(INTEGRATION.client);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update heartbeat time periodically
|
// Update heartbeat time periodically (30s)
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
updateHeartbeat(INTEGRATION.client);
|
updateHeartbeat(INTEGRATION.client);
|
||||||
}, 30 * 1000);
|
}, 30 * 1000);
|
||||||
|
|
||||||
// Update sensor states periodically
|
// Update sensor states periodically (1min)
|
||||||
setInterval(update, 60 * 1000);
|
setInterval(update, 60 * 1000);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -124,18 +124,15 @@ const update = () => {
|
|||||||
*/
|
*/
|
||||||
const initShutdown = (client) => {
|
const initShutdown = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/button/${INTEGRATION.node}/shutdown`;
|
const root = `${INTEGRATION.discovery}/button/${INTEGRATION.node}/shutdown`;
|
||||||
client
|
const config = {
|
||||||
.publish(
|
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: "Shutdown",
|
name: "Shutdown",
|
||||||
unique_id: `${INTEGRATION.node}_shutdown`,
|
unique_id: `${INTEGRATION.node}_shutdown`,
|
||||||
command_topic: `${root}/execute`,
|
command_topic: `${root}/execute`,
|
||||||
icon: "mdi:power",
|
icon: "mdi:power",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client
|
||||||
)
|
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||||
.on("message", (topic, message) => {
|
.on("message", (topic, message) => {
|
||||||
if (topic === `${root}/execute`) {
|
if (topic === `${root}/execute`) {
|
||||||
console.log("Shutdown system...");
|
console.log("Shutdown system...");
|
||||||
@@ -153,18 +150,15 @@ const initShutdown = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initReboot = (client) => {
|
const initReboot = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/button/${INTEGRATION.node}/reboot`;
|
const root = `${INTEGRATION.discovery}/button/${INTEGRATION.node}/reboot`;
|
||||||
client
|
const config = {
|
||||||
.publish(
|
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: "Reboot",
|
name: "Reboot",
|
||||||
unique_id: `${INTEGRATION.node}_reboot`,
|
unique_id: `${INTEGRATION.node}_reboot`,
|
||||||
command_topic: `${root}/execute`,
|
command_topic: `${root}/execute`,
|
||||||
icon: "mdi:restart",
|
icon: "mdi:restart",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client
|
||||||
)
|
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||||
.on("message", (topic, message) => {
|
.on("message", (topic, message) => {
|
||||||
if (topic === `${root}/execute`) {
|
if (topic === `${root}/execute`) {
|
||||||
console.log("Rebooting system...");
|
console.log("Rebooting system...");
|
||||||
@@ -182,18 +176,15 @@ const initReboot = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initRefresh = (client) => {
|
const initRefresh = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/button/${INTEGRATION.node}/refresh`;
|
const root = `${INTEGRATION.discovery}/button/${INTEGRATION.node}/refresh`;
|
||||||
client
|
const config = {
|
||||||
.publish(
|
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: "Refresh",
|
name: "Refresh",
|
||||||
unique_id: `${INTEGRATION.node}_refresh`,
|
unique_id: `${INTEGRATION.node}_refresh`,
|
||||||
command_topic: `${root}/execute`,
|
command_topic: `${root}/execute`,
|
||||||
icon: "mdi:web-refresh",
|
icon: "mdi:web-refresh",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client
|
||||||
)
|
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||||
.on("message", (topic, message) => {
|
.on("message", (topic, message) => {
|
||||||
if (topic === `${root}/execute`) {
|
if (topic === `${root}/execute`) {
|
||||||
console.log("Refreshing webview...");
|
console.log("Refreshing webview...");
|
||||||
@@ -211,27 +202,18 @@ const initRefresh = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initKiosk = (client) => {
|
const initKiosk = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/select/${INTEGRATION.node}/kiosk`;
|
const root = `${INTEGRATION.discovery}/select/${INTEGRATION.node}/kiosk`;
|
||||||
client
|
const config = {
|
||||||
.publish(
|
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Kiosk`,
|
name: `Kiosk`,
|
||||||
unique_id: `${INTEGRATION.node}_kiosk`,
|
unique_id: `${INTEGRATION.node}_kiosk`,
|
||||||
command_topic: `${root}/set`,
|
command_topic: `${root}/set`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
value_template: "{{ value }}",
|
value_template: "{{ value }}",
|
||||||
options: [
|
options: ["Framed", "Fullscreen", "Maximized", "Minimized", "Terminated"],
|
||||||
"Framed",
|
|
||||||
"Fullscreen",
|
|
||||||
"Maximized",
|
|
||||||
"Minimized",
|
|
||||||
"Terminated",
|
|
||||||
],
|
|
||||||
icon: "mdi:overscan",
|
icon: "mdi:overscan",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client
|
||||||
)
|
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||||
.on("message", (topic, message) => {
|
.on("message", (topic, message) => {
|
||||||
if (topic === `${root}/set`) {
|
if (topic === `${root}/set`) {
|
||||||
const status = message.toString();
|
const status = message.toString();
|
||||||
@@ -275,10 +257,9 @@ const initKiosk = (client) => {
|
|||||||
const updateKiosk = (client) => {
|
const updateKiosk = (client) => {
|
||||||
const kiosk = WEBVIEW.status;
|
const kiosk = WEBVIEW.status;
|
||||||
const root = `${INTEGRATION.discovery}/select/${INTEGRATION.node}/kiosk`;
|
const root = `${INTEGRATION.discovery}/select/${INTEGRATION.node}/kiosk`;
|
||||||
client.publish(`${root}/status`, `${kiosk}`, {
|
if (kiosk !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${kiosk}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -288,23 +269,22 @@ const updateKiosk = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initDisplay = (client) => {
|
const initDisplay = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/light/${INTEGRATION.node}/display`;
|
const root = `${INTEGRATION.discovery}/light/${INTEGRATION.node}/display`;
|
||||||
client
|
const config = {
|
||||||
.publish(
|
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Display`,
|
name: `Display`,
|
||||||
unique_id: `${INTEGRATION.node}_display`,
|
unique_id: `${INTEGRATION.node}_display`,
|
||||||
command_topic: `${root}/set`,
|
command_topic: `${root}/set`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
brightness_command_topic: `${root}/brightness/set`,
|
|
||||||
brightness_state_topic: `${root}/brightness/status`,
|
|
||||||
brightness_scale: 100,
|
|
||||||
icon: "mdi:monitor-shimmer",
|
icon: "mdi:monitor-shimmer",
|
||||||
platform: "light",
|
platform: "light",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
if (HARDWARE.display.brightness.path !== null) {
|
||||||
)
|
config.brightness_scale = 100;
|
||||||
|
config.brightness_command_topic = `${root}/brightness/set`;
|
||||||
|
config.brightness_state_topic = `${root}/brightness/status`;
|
||||||
|
}
|
||||||
|
client
|
||||||
|
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||||
.on("message", (topic, message) => {
|
.on("message", (topic, message) => {
|
||||||
if (topic === `${root}/set`) {
|
if (topic === `${root}/set`) {
|
||||||
const status = message.toString();
|
const status = message.toString();
|
||||||
@@ -330,14 +310,12 @@ const updateDisplay = (client) => {
|
|||||||
const status = hardware.getDisplayStatus();
|
const status = hardware.getDisplayStatus();
|
||||||
const brightness = hardware.getDisplayBrightness();
|
const brightness = hardware.getDisplayBrightness();
|
||||||
const root = `${INTEGRATION.discovery}/light/${INTEGRATION.node}/display`;
|
const root = `${INTEGRATION.discovery}/light/${INTEGRATION.node}/display`;
|
||||||
client.publish(`${root}/status`, `${status}`, {
|
if (status !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${status}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
if (brightness !== null) {
|
||||||
client.publish(`${root}/brightness/status`, `${brightness}`, {
|
client.publish(`${root}/brightness/status`, `${brightness}`, { qos: 1, retain: true });
|
||||||
qos: 1,
|
}
|
||||||
retain: true,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -347,18 +325,15 @@ const updateDisplay = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initModel = (client) => {
|
const initModel = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/model`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/model`;
|
||||||
client.publish(
|
const config = {
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Model`,
|
name: `Model`,
|
||||||
unique_id: `${INTEGRATION.node}_model`,
|
unique_id: `${INTEGRATION.node}_model`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
value_template: "{{ value }}",
|
value_template: "{{ value }}",
|
||||||
icon: "mdi:raspberry-pi",
|
icon: "mdi:raspberry-pi",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||||
);
|
|
||||||
updateModel(client);
|
updateModel(client);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -370,10 +345,9 @@ const initModel = (client) => {
|
|||||||
const updateModel = (client) => {
|
const updateModel = (client) => {
|
||||||
const model = hardware.getModel();
|
const model = hardware.getModel();
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/model`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/model`;
|
||||||
client.publish(`${root}/status`, `${model}`, {
|
if (model !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${model}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -383,18 +357,15 @@ const updateModel = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initSerialNumber = (client) => {
|
const initSerialNumber = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/serial_number`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/serial_number`;
|
||||||
client.publish(
|
const config = {
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Serial Number`,
|
name: `Serial Number`,
|
||||||
unique_id: `${INTEGRATION.node}_serial_number`,
|
unique_id: `${INTEGRATION.node}_serial_number`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
value_template: "{{ value }}",
|
value_template: "{{ value }}",
|
||||||
icon: "mdi:hexadecimal",
|
icon: "mdi:hexadecimal",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||||
);
|
|
||||||
updateSerialNumber(client);
|
updateSerialNumber(client);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -406,10 +377,9 @@ const initSerialNumber = (client) => {
|
|||||||
const updateSerialNumber = (client) => {
|
const updateSerialNumber = (client) => {
|
||||||
const serialNumber = hardware.getSerialNumber();
|
const serialNumber = hardware.getSerialNumber();
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/serial_number`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/serial_number`;
|
||||||
client.publish(`${root}/status`, `${serialNumber}`, {
|
if (serialNumber !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${serialNumber}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -419,18 +389,15 @@ const updateSerialNumber = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initHostName = (client) => {
|
const initHostName = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/host_name`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/host_name`;
|
||||||
client.publish(
|
const config = {
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Host Name`,
|
name: `Host Name`,
|
||||||
unique_id: `${INTEGRATION.node}_host_name`,
|
unique_id: `${INTEGRATION.node}_host_name`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
value_template: "{{ value }}",
|
value_template: "{{ value }}",
|
||||||
icon: "mdi:console-network",
|
icon: "mdi:console-network",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||||
);
|
|
||||||
updateHostName(client);
|
updateHostName(client);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -442,10 +409,9 @@ const initHostName = (client) => {
|
|||||||
const updateHostName = (client) => {
|
const updateHostName = (client) => {
|
||||||
const hostName = hardware.getHostName();
|
const hostName = hardware.getHostName();
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/host_name`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/host_name`;
|
||||||
client.publish(`${root}/status`, `${hostName}`, {
|
if (hostName !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${hostName}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -455,9 +421,7 @@ const updateHostName = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initUpTime = (client) => {
|
const initUpTime = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/up_time`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/up_time`;
|
||||||
client.publish(
|
const config = {
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Up Time`,
|
name: `Up Time`,
|
||||||
unique_id: `${INTEGRATION.node}_up_time`,
|
unique_id: `${INTEGRATION.node}_up_time`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
@@ -465,9 +429,8 @@ const initUpTime = (client) => {
|
|||||||
unit_of_measurement: "min",
|
unit_of_measurement: "min",
|
||||||
icon: "mdi:timeline-clock",
|
icon: "mdi:timeline-clock",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||||
);
|
|
||||||
updateUpTime(client);
|
updateUpTime(client);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -479,10 +442,9 @@ const initUpTime = (client) => {
|
|||||||
const updateUpTime = (client) => {
|
const updateUpTime = (client) => {
|
||||||
const upTime = hardware.getUpTime();
|
const upTime = hardware.getUpTime();
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/up_time`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/up_time`;
|
||||||
client.publish(`${root}/status`, `${upTime}`, {
|
if (upTime !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${upTime}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -492,9 +454,7 @@ const updateUpTime = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initMemorySize = (client) => {
|
const initMemorySize = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_size`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_size`;
|
||||||
client.publish(
|
const config = {
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Memory Size`,
|
name: `Memory Size`,
|
||||||
unique_id: `${INTEGRATION.node}_memory_size`,
|
unique_id: `${INTEGRATION.node}_memory_size`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
@@ -502,9 +462,8 @@ const initMemorySize = (client) => {
|
|||||||
unit_of_measurement: "GiB",
|
unit_of_measurement: "GiB",
|
||||||
icon: "mdi:memory",
|
icon: "mdi:memory",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||||
);
|
|
||||||
updateMemorySize(client);
|
updateMemorySize(client);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -516,10 +475,9 @@ const initMemorySize = (client) => {
|
|||||||
const updateMemorySize = (client) => {
|
const updateMemorySize = (client) => {
|
||||||
const memorySize = hardware.getMemorySize();
|
const memorySize = hardware.getMemorySize();
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_size`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_size`;
|
||||||
client.publish(`${root}/status`, `${memorySize}`, {
|
if (memorySize !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${memorySize}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -529,9 +487,7 @@ const updateMemorySize = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initMemoryUsage = (client) => {
|
const initMemoryUsage = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_usage`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_usage`;
|
||||||
client.publish(
|
const config = {
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Memory Usage`,
|
name: `Memory Usage`,
|
||||||
unique_id: `${INTEGRATION.node}_memory_usage`,
|
unique_id: `${INTEGRATION.node}_memory_usage`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
@@ -539,9 +495,8 @@ const initMemoryUsage = (client) => {
|
|||||||
unit_of_measurement: "%",
|
unit_of_measurement: "%",
|
||||||
icon: "mdi:memory-arrow-down",
|
icon: "mdi:memory-arrow-down",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||||
);
|
|
||||||
updateMemoryUsage(client);
|
updateMemoryUsage(client);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -553,10 +508,9 @@ const initMemoryUsage = (client) => {
|
|||||||
const updateMemoryUsage = (client) => {
|
const updateMemoryUsage = (client) => {
|
||||||
const memoryUsage = hardware.getMemoryUsage();
|
const memoryUsage = hardware.getMemoryUsage();
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_usage`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_usage`;
|
||||||
client.publish(`${root}/status`, `${memoryUsage}`, {
|
if (memoryUsage !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${memoryUsage}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -566,9 +520,7 @@ const updateMemoryUsage = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initProcessorUsage = (client) => {
|
const initProcessorUsage = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_usage`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_usage`;
|
||||||
client.publish(
|
const config = {
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Processor Usage`,
|
name: `Processor Usage`,
|
||||||
unique_id: `${INTEGRATION.node}_processor_usage`,
|
unique_id: `${INTEGRATION.node}_processor_usage`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
@@ -576,9 +528,8 @@ const initProcessorUsage = (client) => {
|
|||||||
unit_of_measurement: "%",
|
unit_of_measurement: "%",
|
||||||
icon: "mdi:cpu-64-bit",
|
icon: "mdi:cpu-64-bit",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||||
);
|
|
||||||
updateProcessorUsage(client);
|
updateProcessorUsage(client);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -590,10 +541,9 @@ const initProcessorUsage = (client) => {
|
|||||||
const updateProcessorUsage = (client) => {
|
const updateProcessorUsage = (client) => {
|
||||||
const processorUsage = hardware.getProcessorUsage();
|
const processorUsage = hardware.getProcessorUsage();
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_usage`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_usage`;
|
||||||
client.publish(`${root}/status`, `${processorUsage}`, {
|
if (processorUsage !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${processorUsage}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -603,9 +553,7 @@ const updateProcessorUsage = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initProcessorTemperature = (client) => {
|
const initProcessorTemperature = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_temperature`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_temperature`;
|
||||||
client.publish(
|
const config = {
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Processor Temperature`,
|
name: `Processor Temperature`,
|
||||||
unique_id: `${INTEGRATION.node}_processor_temperature`,
|
unique_id: `${INTEGRATION.node}_processor_temperature`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
@@ -613,9 +561,8 @@ const initProcessorTemperature = (client) => {
|
|||||||
unit_of_measurement: "°C",
|
unit_of_measurement: "°C",
|
||||||
icon: "mdi:radiator",
|
icon: "mdi:radiator",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||||
);
|
|
||||||
updateProcessorTemperature(client);
|
updateProcessorTemperature(client);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -627,10 +574,9 @@ const initProcessorTemperature = (client) => {
|
|||||||
const updateProcessorTemperature = (client) => {
|
const updateProcessorTemperature = (client) => {
|
||||||
const processorTemperature = hardware.getProcessorTemperature();
|
const processorTemperature = hardware.getProcessorTemperature();
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_temperature`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_temperature`;
|
||||||
client.publish(`${root}/status`, `${processorTemperature}`, {
|
if (processorTemperature !== null) {
|
||||||
qos: 1,
|
client.publish(`${root}/status`, `${processorTemperature}`, { qos: 1, retain: true });
|
||||||
retain: true,
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -640,18 +586,15 @@ const updateProcessorTemperature = (client) => {
|
|||||||
*/
|
*/
|
||||||
const initHeartbeat = (client) => {
|
const initHeartbeat = (client) => {
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/heartbeat`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/heartbeat`;
|
||||||
client.publish(
|
const config = {
|
||||||
`${root}/config`,
|
|
||||||
JSON.stringify({
|
|
||||||
name: `Heartbeat`,
|
name: `Heartbeat`,
|
||||||
unique_id: `${INTEGRATION.node}_heartbeat`,
|
unique_id: `${INTEGRATION.node}_heartbeat`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
value_template: "{{ value }}",
|
value_template: "{{ value }}",
|
||||||
icon: "mdi:heart-flash",
|
icon: "mdi:heart-flash",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
}),
|
};
|
||||||
{ qos: 1, retain: true }
|
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||||
);
|
|
||||||
updateHeartbeat(client);
|
updateHeartbeat(client);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -665,10 +608,7 @@ const updateHeartbeat = (client) => {
|
|||||||
const local = new Date(now.getTime() - now.getTimezoneOffset() * 60 * 1000);
|
const local = new Date(now.getTime() - now.getTimezoneOffset() * 60 * 1000);
|
||||||
const heartbeat = local.toISOString().replace(/\.\d{3}Z$/, "");
|
const heartbeat = local.toISOString().replace(/\.\d{3}Z$/, "");
|
||||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/heartbeat`;
|
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/heartbeat`;
|
||||||
client.publish(`${root}/status`, `${heartbeat}`, {
|
client.publish(`${root}/status`, `${heartbeat}`, { qos: 1, retain: true });
|
||||||
qos: 1,
|
|
||||||
retain: true,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
+16
-11
@@ -24,12 +24,10 @@ const init = async (args) => {
|
|||||||
const theme = args.web_theme ? args.web_theme : "dark";
|
const theme = args.web_theme ? args.web_theme : "dark";
|
||||||
const zoom = args.web_zoom ? parseFloat(args.web_zoom) : 1.25;
|
const zoom = args.web_zoom ? parseFloat(args.web_zoom) : 1.25;
|
||||||
|
|
||||||
// Set app theme and name
|
|
||||||
nativeTheme.themeSource = theme;
|
|
||||||
app.setName("TouchKio");
|
|
||||||
|
|
||||||
// Init global root window
|
// Init global root window
|
||||||
|
nativeTheme.themeSource = theme;
|
||||||
WEBVIEW.window = new BaseWindow({
|
WEBVIEW.window = new BaseWindow({
|
||||||
|
title: `TouchKio - ${url.host}`,
|
||||||
icon: path.join(__dirname, "..", "img", "icon.png"),
|
icon: path.join(__dirname, "..", "img", "icon.png"),
|
||||||
});
|
});
|
||||||
WEBVIEW.window.setMenuBarVisibility(false);
|
WEBVIEW.window.setMenuBarVisibility(false);
|
||||||
@@ -95,7 +93,7 @@ const windowEvents = (window, zoom) => {
|
|||||||
window.blur();
|
window.blur();
|
||||||
}
|
}
|
||||||
/* This also works, but it doesn't allow to react for screen wake up.
|
/* This also works, but it doesn't allow to react for screen wake up.
|
||||||
window.setIgnoreMouseEvents(getDisplayStatus() === "OFF");
|
window.setIgnoreMouseEvents(hardware.getDisplayStatus() === "OFF");
|
||||||
*/
|
*/
|
||||||
});
|
});
|
||||||
window.on("focus", () => {
|
window.on("focus", () => {
|
||||||
@@ -106,18 +104,28 @@ const windowEvents = (window, zoom) => {
|
|||||||
WEBVIEW.locked = false;
|
WEBVIEW.locked = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update window status
|
// Handle window status updates
|
||||||
window.on("minimize", update);
|
window.on("minimize", update);
|
||||||
window.on("restore", update);
|
window.on("restore", update);
|
||||||
window.on("maximize", update);
|
window.on("maximize", update);
|
||||||
window.on("unmaximize", update);
|
window.on("unmaximize", update);
|
||||||
window.on("enter-full-screen", update);
|
window.on("enter-full-screen", update);
|
||||||
window.on("leave-full-screen", update);
|
window.on("leave-full-screen", update);
|
||||||
|
|
||||||
|
// Handle signal and exit events
|
||||||
process.on("SIGINT", app.quit);
|
process.on("SIGINT", app.quit);
|
||||||
app.on("before-quit", () => {
|
app.on("before-quit", () => {
|
||||||
WEBVIEW.status = "Terminated";
|
WEBVIEW.status = "Terminated";
|
||||||
integration.update();
|
integration.update();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle multiple instances
|
||||||
|
app.on("second-instance", () => {
|
||||||
|
if (window.isMinimized()) {
|
||||||
|
window.restore();
|
||||||
|
}
|
||||||
|
window.focus();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,13 +136,10 @@ const windowEvents = (window, zoom) => {
|
|||||||
const viewEvents = (view) => {
|
const viewEvents = (view) => {
|
||||||
// Enable webview touch emulation
|
// Enable webview touch emulation
|
||||||
view.webContents.debugger.attach("1.1");
|
view.webContents.debugger.attach("1.1");
|
||||||
view.webContents.debugger.sendCommand(
|
view.webContents.debugger.sendCommand("Emulation.setEmitTouchEventsForMouse", {
|
||||||
"Emulation.setEmitTouchEventsForMouse",
|
|
||||||
{
|
|
||||||
enabled: true,
|
enabled: true,
|
||||||
configuration: "mobile",
|
configuration: "mobile",
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
// Disable webview hyperlinks
|
// Disable webview hyperlinks
|
||||||
view.webContents.setWindowOpenHandler(() => {
|
view.webContents.setWindowOpenHandler(() => {
|
||||||
|
|||||||
@@ -1129,10 +1129,10 @@ electron-installer-debian@^3.2.0:
|
|||||||
word-wrap "^1.2.3"
|
word-wrap "^1.2.3"
|
||||||
yargs "^16.0.2"
|
yargs "^16.0.2"
|
||||||
|
|
||||||
electron@^33.2.1:
|
electron@^33.3.1:
|
||||||
version "33.2.1"
|
version "33.3.1"
|
||||||
resolved "https://registry.yarnpkg.com/electron/-/electron-33.2.1.tgz#d0d7bba7a7abf4f14881d0a6e03c498b301a2d5f"
|
resolved "https://registry.yarnpkg.com/electron/-/electron-33.3.1.tgz#26d63b3a110c4a9db639c33633bf806f91b4f649"
|
||||||
integrity sha512-SG/nmSsK9Qg1p6wAW+ZfqU+AV8cmXMTIklUL18NnOKfZLlum4ZsDoVdmmmlL39ZmeCaq27dr7CgslRPahfoVJg==
|
integrity sha512-Z7l2bVgpdKxHQMI4i0CirBX2n+iCYKOx5mbzNM3BpOyFELwlobEXKmzCmEnwP+3EcNeIhUQyIEBFQxN06QgdIw==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@electron/get" "^2.0.0"
|
"@electron/get" "^2.0.0"
|
||||||
"@types/node" "^20.9.0"
|
"@types/node" "^20.9.0"
|
||||||
@@ -2396,6 +2396,11 @@ postject@^1.0.0-alpha.6:
|
|||||||
dependencies:
|
dependencies:
|
||||||
commander "^9.4.0"
|
commander "^9.4.0"
|
||||||
|
|
||||||
|
prettier@^3.4.2:
|
||||||
|
version "3.4.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.4.2.tgz#a5ce1fb522a588bf2b78ca44c6e6fe5aa5a2b13f"
|
||||||
|
integrity sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==
|
||||||
|
|
||||||
proc-log@^2.0.1:
|
proc-log@^2.0.1:
|
||||||
version "2.0.1"
|
version "2.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/proc-log/-/proc-log-2.0.1.tgz#8f3f69a1f608de27878f91f5c688b225391cb685"
|
resolved "https://registry.yarnpkg.com/proc-log/-/proc-log-2.0.1.tgz#8f3f69a1f608de27878f91f5c688b225391cb685"
|
||||||
|
|||||||
Reference in New Issue
Block a user