Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3201786d41 | ||
|
|
0656f8f897 | ||
|
|
dbcfb74923 | ||
|
|
640156ba87 | ||
|
|
8d2f3da93e | ||
|
|
286e8c1758 |
+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** is a Node.js application that utilizes **Electron** to create a kiosk mode specifically designed for a Home Assistant dashboard.
|
||||
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.
|
||||
**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** (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)
|
||||
|
||||
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.
|
||||
|
||||
## 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.
|
||||
|
||||
## Setup
|
||||
Before you begin, make sure that you have a Raspberry Pi configured and operational with a compatible touch display.
|
||||
This guide assumes that you are using the latest version of **Raspberry Pi OS (64-bit)** together with a desktop environment.
|
||||
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 that you are using the latest version of **Raspberry Pi OS (64-bit)** together with a **Wayland** based desktop environment.
|
||||
|
||||
### 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.
|
||||
@@ -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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
<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**.
|
||||
This is done within the `install.sh` script, which also creates a `.service` file.
|
||||
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 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.
|
||||
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
|
||||
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`.
|
||||
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.
|
||||
@@ -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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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>
|
||||
|
||||
## Issues
|
||||
- Currently, only the Raspberry Pi 5 in combination with the new touch display 2 supports the MQTT integration.
|
||||
- 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.
|
||||
Please have a look into the [hardware](https://github.com/leukipp/touchkio/blob/main/HARDWARE.md) documentation if you ran into any issues.
|
||||
|
||||
- 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.
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
@@ -135,12 +135,7 @@ const promptArgs = async (proc) => {
|
||||
const answer = await read.question(prompt);
|
||||
const value = (answer.trim() || fallback.match(/[YN]/)[0]).toLowerCase();
|
||||
if (!["y", "yes"].includes(value)) {
|
||||
ignore = ignore.concat([
|
||||
"mqtt_url",
|
||||
"mqtt_user",
|
||||
"mqtt_password",
|
||||
"mqtt_discovery",
|
||||
]);
|
||||
ignore = ignore.concat(["mqtt_url", "mqtt_user", "mqtt_password", "mqtt_discovery"]);
|
||||
}
|
||||
} else if (key === "check") {
|
||||
const json = JSON.stringify(args, null, 2);
|
||||
|
||||
+22
-3
@@ -47,13 +47,32 @@ WantedBy=default.target
|
||||
EOF"
|
||||
|
||||
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
|
||||
echo -e "\nCreating udev rule for backlight..."
|
||||
|
||||
sudo bash -c 'cat << EOF > /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"
|
||||
EOF'
|
||||
UDEV_FILE="/etc/udev/rules.d/backlight-permissions.rules"
|
||||
sudo bash -c "cat << EOF > \"$UDEV_FILE\"
|
||||
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
|
||||
echo ""
|
||||
|
||||
+7
-3
@@ -2,7 +2,7 @@
|
||||
"name": "touchkio",
|
||||
"description": "Home Assistant Touch Kiosk",
|
||||
"author": "leukipp",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -49,14 +49,18 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 120
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "^7.6.0",
|
||||
"@electron-forge/maker-deb": "^7.6.0",
|
||||
"@electron-forge/maker-zip": "^7.6.0",
|
||||
"@electron-forge/publisher-github": "^7.6.0",
|
||||
"electron": "^33.2.1"
|
||||
"electron": "^33.3.1",
|
||||
"prettier": "^3.4.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"mqtt": "^5.10.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+153
-81
@@ -1,13 +1,22 @@
|
||||
const os = require("os");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const process = require("child_process");
|
||||
|
||||
global.HARDWARE = global.HARDWARE || {
|
||||
initialized: false,
|
||||
status: "invalid",
|
||||
display: {
|
||||
status: null,
|
||||
brightness: null,
|
||||
name: null,
|
||||
status: {
|
||||
path: null,
|
||||
value: null,
|
||||
},
|
||||
brightness: {
|
||||
path: null,
|
||||
value: null,
|
||||
max: null,
|
||||
},
|
||||
notifiers: [],
|
||||
},
|
||||
};
|
||||
@@ -23,20 +32,29 @@ const init = async (args) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check supported hardware
|
||||
if (!hardwareExists()) {
|
||||
console.warn("Hardware not supported");
|
||||
// Check device support
|
||||
if (!compatibleDevice()) {
|
||||
console.warn("Device not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check supported model
|
||||
// Check model support
|
||||
const model = getModel();
|
||||
if (!model || !model.includes("Raspberry Pi 5")) {
|
||||
console.warn(`Device ${model} not supported`);
|
||||
if (!model || !model.includes("Raspberry Pi")) {
|
||||
console.warn(`${model} not supported`);
|
||||
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("Host Name:", getHostName());
|
||||
console.log("Up Time:", getUpTime());
|
||||
@@ -44,12 +62,11 @@ const init = async (args) => {
|
||||
console.log("Memory Usage:", getMemoryUsage());
|
||||
console.log("Processor Usage:", getProcessorUsage());
|
||||
console.log("Processor Temperature:", getProcessorTemperature());
|
||||
console.log("Display Status:", getDisplayStatus());
|
||||
console.log("Display Brightness:", getDisplayBrightness(), "\n");
|
||||
|
||||
// Init globals
|
||||
HARDWARE.initialized = true;
|
||||
HARDWARE.status = "valid";
|
||||
// Show display infos
|
||||
console.log("\nDisplay Name:", HARDWARE.display.name);
|
||||
console.log(`Display Status [${HARDWARE.display.status.path}]:`, getDisplayStatus());
|
||||
console.log(`Display Brightness [${HARDWARE.display.brightness.path}]:`, getDisplayBrightness(), "\n");
|
||||
|
||||
// Check for display changes
|
||||
setInterval(update, 500);
|
||||
@@ -64,40 +81,43 @@ const update = () => {
|
||||
if (!HARDWARE.initialized) {
|
||||
return;
|
||||
}
|
||||
const path = "/sys/class/backlight/10-0045";
|
||||
|
||||
// Display status has changed
|
||||
const status = fs.readFileSync(`${path}/bl_power`, "utf8").trim();
|
||||
if (status !== HARDWARE.display.status) {
|
||||
console.log("Update Display Status:", getDisplayStatus());
|
||||
HARDWARE.display.status = status;
|
||||
HARDWARE.display.notifiers.forEach((notifier) => {
|
||||
notifier();
|
||||
});
|
||||
if (HARDWARE.display.status.path !== null) {
|
||||
const status = fs.readFileSync(`${HARDWARE.display.status.path}/enabled`, "utf8").trim();
|
||||
if (status !== HARDWARE.display.status.value) {
|
||||
console.log("Update Display Status:", getDisplayStatus());
|
||||
HARDWARE.display.status.value = status;
|
||||
HARDWARE.display.notifiers.forEach((notifier) => {
|
||||
notifier();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Display brightness has changed
|
||||
const brightness = fs.readFileSync(`${path}/brightness`, "utf8").trim();
|
||||
if (brightness !== HARDWARE.display.brightness) {
|
||||
console.log("Update Display Brightness:", getDisplayBrightness());
|
||||
HARDWARE.display.brightness = brightness;
|
||||
HARDWARE.display.notifiers.forEach((notifier) => {
|
||||
notifier();
|
||||
});
|
||||
if (HARDWARE.display.brightness.path !== null) {
|
||||
const brightness = fs.readFileSync(`${HARDWARE.display.brightness.path}/brightness`, "utf8").trim();
|
||||
if (brightness !== HARDWARE.display.brightness.value) {
|
||||
console.log("Update Display Brightness:", getDisplayBrightness());
|
||||
HARDWARE.display.brightness.value = brightness;
|
||||
HARDWARE.display.notifiers.forEach((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.
|
||||
*/
|
||||
const hardwareExists = () => {
|
||||
const compatibleDevice = () => {
|
||||
const files = [
|
||||
"/sys/class/drm",
|
||||
"/sys/class/backlight",
|
||||
"/sys/firmware/devicetree/base/model",
|
||||
"/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));
|
||||
};
|
||||
@@ -117,9 +137,7 @@ const getModel = () => {
|
||||
* @returns {string|null} The serial number of the Raspberry Pi or null if an error occurs.
|
||||
*/
|
||||
const getSerialNumber = () => {
|
||||
return execSyncCommand("cat", [
|
||||
"/sys/firmware/devicetree/base/serial-number",
|
||||
]);
|
||||
return execSyncCommand("cat", ["/sys/firmware/devicetree/base/serial-number"]);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -192,6 +210,41 @@ const getProcessorTemperature = () => {
|
||||
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`.
|
||||
*
|
||||
@@ -200,18 +253,10 @@ const getProcessorTemperature = () => {
|
||||
const getDisplayStatus = () => {
|
||||
const status = execSyncCommand("wlopm", []);
|
||||
if (status !== null) {
|
||||
return status.slice(status.lastIndexOf(" ") + 1).toUpperCase();
|
||||
const out = status.split("\n")[0].split(" ");
|
||||
return out.pop().toUpperCase();
|
||||
}
|
||||
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");
|
||||
return;
|
||||
}
|
||||
const args = status === "ON" ? ["--on", "*"] : ["--off", "*"];
|
||||
const args = [`--${status.toLowerCase()}`, HARDWARE.display.name];
|
||||
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,
|
||||
* and maps it to a percentage in the range of 0-100 percent.
|
||||
*
|
||||
* @returns {number|null} The brightness level as a percentage or null if an error occurs.
|
||||
* @param {string} name - Primary display name.
|
||||
* @returns {string|null} The display brightness path or null if nothing was found.
|
||||
*/
|
||||
const getDisplayBrightness = () => {
|
||||
const brightness = execSyncCommand("cat", [
|
||||
"/sys/class/backlight/10-0045/brightness",
|
||||
]);
|
||||
if (brightness !== null) {
|
||||
return Math.round((parseInt(brightness, 10) / 31) * 100);
|
||||
const getDisplayBrightnessPath = (name) => {
|
||||
const backlight = "/sys/class/backlight";
|
||||
for (const address of fs.readdirSync(backlight)) {
|
||||
const nameFile = path.join(backlight, address, "display_name");
|
||||
if (!fs.existsSync(nameFile)) {
|
||||
continue;
|
||||
}
|
||||
const content = fs.readFileSync(nameFile, "utf8").trim();
|
||||
if (content.includes(name)) {
|
||||
return path.join(backlight, address);
|
||||
}
|
||||
}
|
||||
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,
|
||||
* maps it to the range of 0-31, and writes it to the system.
|
||||
* @returns {number|null} The brightness maximum value or null if an error occurs.
|
||||
*/
|
||||
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 {function} callback - A callback function that receives the output or error.
|
||||
*/
|
||||
const setDisplayBrightness = (brightness, callback = null) => {
|
||||
if (!HARDWARE.display.brightness.path) {
|
||||
return;
|
||||
}
|
||||
if (typeof brightness !== "number" || brightness < 1 || brightness > 100) {
|
||||
console.error("Brightness must be a number between 1 and 100");
|
||||
if (typeof callback === "function") callback(null, "Invalid brightness");
|
||||
return;
|
||||
}
|
||||
const value = Math.max(1, Math.min(Math.round((brightness / 100) * 31), 31));
|
||||
const proc = execAsyncCommand(
|
||||
"tee",
|
||||
["/sys/class/backlight/10-0045/brightness"],
|
||||
callback
|
||||
);
|
||||
const max = HARDWARE.display.brightness.max;
|
||||
const value = Math.max(1, Math.min(Math.round((brightness / 100) * max), max));
|
||||
const proc = execAsyncCommand("tee", [`${HARDWARE.display.brightness.path}/brightness`], callback);
|
||||
proc.stdin.write(value.toString());
|
||||
proc.stdin.end();
|
||||
};
|
||||
@@ -320,9 +390,7 @@ const rebootSystem = (callback = null) => {
|
||||
*/
|
||||
const execSyncCommand = (cmd, args = []) => {
|
||||
try {
|
||||
const output = process.execSync([cmd, ...args].join(" "), {
|
||||
encoding: "utf8",
|
||||
});
|
||||
const output = process.execSync([cmd, ...args].join(" "), { encoding: "utf8" });
|
||||
return output.trim().replace(/\0/g, "");
|
||||
} catch (error) {
|
||||
console.error("Execute Sync:", error.message);
|
||||
@@ -380,8 +448,12 @@ module.exports = {
|
||||
getMemoryUsage,
|
||||
getProcessorUsage,
|
||||
getProcessorTemperature,
|
||||
getDisplayName,
|
||||
getDisplayStatusPath,
|
||||
getDisplayStatus,
|
||||
setDisplayStatus,
|
||||
getDisplayBrightnessPath,
|
||||
getDisplayBrightnessMax,
|
||||
getDisplayBrightness,
|
||||
setDisplayBrightness,
|
||||
shutdownSystem,
|
||||
|
||||
+172
-232
@@ -90,12 +90,12 @@ const init = async (args) => {
|
||||
updateDisplay(INTEGRATION.client);
|
||||
});
|
||||
|
||||
// Update heartbeat time periodically
|
||||
// Update heartbeat time periodically (30s)
|
||||
setInterval(() => {
|
||||
updateHeartbeat(INTEGRATION.client);
|
||||
}, 30 * 1000);
|
||||
|
||||
// Update sensor states periodically
|
||||
// Update sensor states periodically (1min)
|
||||
setInterval(update, 60 * 1000);
|
||||
|
||||
return true;
|
||||
@@ -124,18 +124,15 @@ const update = () => {
|
||||
*/
|
||||
const initShutdown = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/button/${INTEGRATION.node}/shutdown`;
|
||||
const config = {
|
||||
name: "Shutdown",
|
||||
unique_id: `${INTEGRATION.node}_shutdown`,
|
||||
command_topic: `${root}/execute`,
|
||||
icon: "mdi:power",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client
|
||||
.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: "Shutdown",
|
||||
unique_id: `${INTEGRATION.node}_shutdown`,
|
||||
command_topic: `${root}/execute`,
|
||||
icon: "mdi:power",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
)
|
||||
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||
.on("message", (topic, message) => {
|
||||
if (topic === `${root}/execute`) {
|
||||
console.log("Shutdown system...");
|
||||
@@ -153,18 +150,15 @@ const initShutdown = (client) => {
|
||||
*/
|
||||
const initReboot = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/button/${INTEGRATION.node}/reboot`;
|
||||
const config = {
|
||||
name: "Reboot",
|
||||
unique_id: `${INTEGRATION.node}_reboot`,
|
||||
command_topic: `${root}/execute`,
|
||||
icon: "mdi:restart",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client
|
||||
.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: "Reboot",
|
||||
unique_id: `${INTEGRATION.node}_reboot`,
|
||||
command_topic: `${root}/execute`,
|
||||
icon: "mdi:restart",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
)
|
||||
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||
.on("message", (topic, message) => {
|
||||
if (topic === `${root}/execute`) {
|
||||
console.log("Rebooting system...");
|
||||
@@ -182,18 +176,15 @@ const initReboot = (client) => {
|
||||
*/
|
||||
const initRefresh = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/button/${INTEGRATION.node}/refresh`;
|
||||
const config = {
|
||||
name: "Refresh",
|
||||
unique_id: `${INTEGRATION.node}_refresh`,
|
||||
command_topic: `${root}/execute`,
|
||||
icon: "mdi:web-refresh",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client
|
||||
.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: "Refresh",
|
||||
unique_id: `${INTEGRATION.node}_refresh`,
|
||||
command_topic: `${root}/execute`,
|
||||
icon: "mdi:web-refresh",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
)
|
||||
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||
.on("message", (topic, message) => {
|
||||
if (topic === `${root}/execute`) {
|
||||
console.log("Refreshing webview...");
|
||||
@@ -211,27 +202,18 @@ const initRefresh = (client) => {
|
||||
*/
|
||||
const initKiosk = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/select/${INTEGRATION.node}/kiosk`;
|
||||
const config = {
|
||||
name: `Kiosk`,
|
||||
unique_id: `${INTEGRATION.node}_kiosk`,
|
||||
command_topic: `${root}/set`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
options: ["Framed", "Fullscreen", "Maximized", "Minimized", "Terminated"],
|
||||
icon: "mdi:overscan",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client
|
||||
.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Kiosk`,
|
||||
unique_id: `${INTEGRATION.node}_kiosk`,
|
||||
command_topic: `${root}/set`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
options: [
|
||||
"Framed",
|
||||
"Fullscreen",
|
||||
"Maximized",
|
||||
"Minimized",
|
||||
"Terminated",
|
||||
],
|
||||
icon: "mdi:overscan",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
)
|
||||
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||
.on("message", (topic, message) => {
|
||||
if (topic === `${root}/set`) {
|
||||
const status = message.toString();
|
||||
@@ -275,10 +257,9 @@ const initKiosk = (client) => {
|
||||
const updateKiosk = (client) => {
|
||||
const kiosk = WEBVIEW.status;
|
||||
const root = `${INTEGRATION.discovery}/select/${INTEGRATION.node}/kiosk`;
|
||||
client.publish(`${root}/status`, `${kiosk}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (kiosk !== null) {
|
||||
client.publish(`${root}/status`, `${kiosk}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -288,23 +269,22 @@ const updateKiosk = (client) => {
|
||||
*/
|
||||
const initDisplay = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/light/${INTEGRATION.node}/display`;
|
||||
const config = {
|
||||
name: `Display`,
|
||||
unique_id: `${INTEGRATION.node}_display`,
|
||||
command_topic: `${root}/set`,
|
||||
state_topic: `${root}/status`,
|
||||
icon: "mdi:monitor-shimmer",
|
||||
platform: "light",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
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({
|
||||
name: `Display`,
|
||||
unique_id: `${INTEGRATION.node}_display`,
|
||||
command_topic: `${root}/set`,
|
||||
state_topic: `${root}/status`,
|
||||
brightness_command_topic: `${root}/brightness/set`,
|
||||
brightness_state_topic: `${root}/brightness/status`,
|
||||
brightness_scale: 100,
|
||||
icon: "mdi:monitor-shimmer",
|
||||
platform: "light",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
)
|
||||
.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true })
|
||||
.on("message", (topic, message) => {
|
||||
if (topic === `${root}/set`) {
|
||||
const status = message.toString();
|
||||
@@ -330,14 +310,12 @@ const updateDisplay = (client) => {
|
||||
const status = hardware.getDisplayStatus();
|
||||
const brightness = hardware.getDisplayBrightness();
|
||||
const root = `${INTEGRATION.discovery}/light/${INTEGRATION.node}/display`;
|
||||
client.publish(`${root}/status`, `${status}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
client.publish(`${root}/brightness/status`, `${brightness}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (status !== null) {
|
||||
client.publish(`${root}/status`, `${status}`, { qos: 1, retain: true });
|
||||
}
|
||||
if (brightness !== null) {
|
||||
client.publish(`${root}/brightness/status`, `${brightness}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -347,18 +325,15 @@ const updateDisplay = (client) => {
|
||||
*/
|
||||
const initModel = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/model`;
|
||||
client.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Model`,
|
||||
unique_id: `${INTEGRATION.node}_model`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
icon: "mdi:raspberry-pi",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
);
|
||||
const config = {
|
||||
name: `Model`,
|
||||
unique_id: `${INTEGRATION.node}_model`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
icon: "mdi:raspberry-pi",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||
updateModel(client);
|
||||
};
|
||||
|
||||
@@ -370,10 +345,9 @@ const initModel = (client) => {
|
||||
const updateModel = (client) => {
|
||||
const model = hardware.getModel();
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/model`;
|
||||
client.publish(`${root}/status`, `${model}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (model !== null) {
|
||||
client.publish(`${root}/status`, `${model}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -383,18 +357,15 @@ const updateModel = (client) => {
|
||||
*/
|
||||
const initSerialNumber = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/serial_number`;
|
||||
client.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Serial Number`,
|
||||
unique_id: `${INTEGRATION.node}_serial_number`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
icon: "mdi:hexadecimal",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
);
|
||||
const config = {
|
||||
name: `Serial Number`,
|
||||
unique_id: `${INTEGRATION.node}_serial_number`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
icon: "mdi:hexadecimal",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||
updateSerialNumber(client);
|
||||
};
|
||||
|
||||
@@ -406,10 +377,9 @@ const initSerialNumber = (client) => {
|
||||
const updateSerialNumber = (client) => {
|
||||
const serialNumber = hardware.getSerialNumber();
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/serial_number`;
|
||||
client.publish(`${root}/status`, `${serialNumber}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (serialNumber !== null) {
|
||||
client.publish(`${root}/status`, `${serialNumber}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -419,18 +389,15 @@ const updateSerialNumber = (client) => {
|
||||
*/
|
||||
const initHostName = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/host_name`;
|
||||
client.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Host Name`,
|
||||
unique_id: `${INTEGRATION.node}_host_name`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
icon: "mdi:console-network",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
);
|
||||
const config = {
|
||||
name: `Host Name`,
|
||||
unique_id: `${INTEGRATION.node}_host_name`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
icon: "mdi:console-network",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||
updateHostName(client);
|
||||
};
|
||||
|
||||
@@ -442,10 +409,9 @@ const initHostName = (client) => {
|
||||
const updateHostName = (client) => {
|
||||
const hostName = hardware.getHostName();
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/host_name`;
|
||||
client.publish(`${root}/status`, `${hostName}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (hostName !== null) {
|
||||
client.publish(`${root}/status`, `${hostName}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -455,19 +421,16 @@ const updateHostName = (client) => {
|
||||
*/
|
||||
const initUpTime = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/up_time`;
|
||||
client.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Up Time`,
|
||||
unique_id: `${INTEGRATION.node}_up_time`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(0) }}",
|
||||
unit_of_measurement: "min",
|
||||
icon: "mdi:timeline-clock",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
);
|
||||
const config = {
|
||||
name: `Up Time`,
|
||||
unique_id: `${INTEGRATION.node}_up_time`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(0) }}",
|
||||
unit_of_measurement: "min",
|
||||
icon: "mdi:timeline-clock",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||
updateUpTime(client);
|
||||
};
|
||||
|
||||
@@ -479,10 +442,9 @@ const initUpTime = (client) => {
|
||||
const updateUpTime = (client) => {
|
||||
const upTime = hardware.getUpTime();
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/up_time`;
|
||||
client.publish(`${root}/status`, `${upTime}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (upTime !== null) {
|
||||
client.publish(`${root}/status`, `${upTime}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -492,19 +454,16 @@ const updateUpTime = (client) => {
|
||||
*/
|
||||
const initMemorySize = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_size`;
|
||||
client.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Memory Size`,
|
||||
unique_id: `${INTEGRATION.node}_memory_size`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(2) }}",
|
||||
unit_of_measurement: "GiB",
|
||||
icon: "mdi:memory",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
);
|
||||
const config = {
|
||||
name: `Memory Size`,
|
||||
unique_id: `${INTEGRATION.node}_memory_size`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(2) }}",
|
||||
unit_of_measurement: "GiB",
|
||||
icon: "mdi:memory",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||
updateMemorySize(client);
|
||||
};
|
||||
|
||||
@@ -516,10 +475,9 @@ const initMemorySize = (client) => {
|
||||
const updateMemorySize = (client) => {
|
||||
const memorySize = hardware.getMemorySize();
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_size`;
|
||||
client.publish(`${root}/status`, `${memorySize}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (memorySize !== null) {
|
||||
client.publish(`${root}/status`, `${memorySize}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -529,19 +487,16 @@ const updateMemorySize = (client) => {
|
||||
*/
|
||||
const initMemoryUsage = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_usage`;
|
||||
client.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Memory Usage`,
|
||||
unique_id: `${INTEGRATION.node}_memory_usage`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(0) }}",
|
||||
unit_of_measurement: "%",
|
||||
icon: "mdi:memory-arrow-down",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
);
|
||||
const config = {
|
||||
name: `Memory Usage`,
|
||||
unique_id: `${INTEGRATION.node}_memory_usage`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(0) }}",
|
||||
unit_of_measurement: "%",
|
||||
icon: "mdi:memory-arrow-down",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||
updateMemoryUsage(client);
|
||||
};
|
||||
|
||||
@@ -553,10 +508,9 @@ const initMemoryUsage = (client) => {
|
||||
const updateMemoryUsage = (client) => {
|
||||
const memoryUsage = hardware.getMemoryUsage();
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/memory_usage`;
|
||||
client.publish(`${root}/status`, `${memoryUsage}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (memoryUsage !== null) {
|
||||
client.publish(`${root}/status`, `${memoryUsage}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -566,19 +520,16 @@ const updateMemoryUsage = (client) => {
|
||||
*/
|
||||
const initProcessorUsage = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_usage`;
|
||||
client.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Processor Usage`,
|
||||
unique_id: `${INTEGRATION.node}_processor_usage`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(0) }}",
|
||||
unit_of_measurement: "%",
|
||||
icon: "mdi:cpu-64-bit",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
);
|
||||
const config = {
|
||||
name: `Processor Usage`,
|
||||
unique_id: `${INTEGRATION.node}_processor_usage`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(0) }}",
|
||||
unit_of_measurement: "%",
|
||||
icon: "mdi:cpu-64-bit",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||
updateProcessorUsage(client);
|
||||
};
|
||||
|
||||
@@ -590,10 +541,9 @@ const initProcessorUsage = (client) => {
|
||||
const updateProcessorUsage = (client) => {
|
||||
const processorUsage = hardware.getProcessorUsage();
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_usage`;
|
||||
client.publish(`${root}/status`, `${processorUsage}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (processorUsage !== null) {
|
||||
client.publish(`${root}/status`, `${processorUsage}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -603,19 +553,16 @@ const updateProcessorUsage = (client) => {
|
||||
*/
|
||||
const initProcessorTemperature = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_temperature`;
|
||||
client.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Processor Temperature`,
|
||||
unique_id: `${INTEGRATION.node}_processor_temperature`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(0) }}",
|
||||
unit_of_measurement: "°C",
|
||||
icon: "mdi:radiator",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
);
|
||||
const config = {
|
||||
name: `Processor Temperature`,
|
||||
unique_id: `${INTEGRATION.node}_processor_temperature`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ (value | float) | round(0) }}",
|
||||
unit_of_measurement: "°C",
|
||||
icon: "mdi:radiator",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||
updateProcessorTemperature(client);
|
||||
};
|
||||
|
||||
@@ -627,10 +574,9 @@ const initProcessorTemperature = (client) => {
|
||||
const updateProcessorTemperature = (client) => {
|
||||
const processorTemperature = hardware.getProcessorTemperature();
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/processor_temperature`;
|
||||
client.publish(`${root}/status`, `${processorTemperature}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
if (processorTemperature !== null) {
|
||||
client.publish(`${root}/status`, `${processorTemperature}`, { qos: 1, retain: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -640,18 +586,15 @@ const updateProcessorTemperature = (client) => {
|
||||
*/
|
||||
const initHeartbeat = (client) => {
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/heartbeat`;
|
||||
client.publish(
|
||||
`${root}/config`,
|
||||
JSON.stringify({
|
||||
name: `Heartbeat`,
|
||||
unique_id: `${INTEGRATION.node}_heartbeat`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
icon: "mdi:heart-flash",
|
||||
device: INTEGRATION.device,
|
||||
}),
|
||||
{ qos: 1, retain: true }
|
||||
);
|
||||
const config = {
|
||||
name: `Heartbeat`,
|
||||
unique_id: `${INTEGRATION.node}_heartbeat`,
|
||||
state_topic: `${root}/status`,
|
||||
value_template: "{{ value }}",
|
||||
icon: "mdi:heart-flash",
|
||||
device: INTEGRATION.device,
|
||||
};
|
||||
client.publish(`${root}/config`, JSON.stringify(config), { qos: 1, retain: true });
|
||||
updateHeartbeat(client);
|
||||
};
|
||||
|
||||
@@ -665,10 +608,7 @@ const updateHeartbeat = (client) => {
|
||||
const local = new Date(now.getTime() - now.getTimezoneOffset() * 60 * 1000);
|
||||
const heartbeat = local.toISOString().replace(/\.\d{3}Z$/, "");
|
||||
const root = `${INTEGRATION.discovery}/sensor/${INTEGRATION.node}/heartbeat`;
|
||||
client.publish(`${root}/status`, `${heartbeat}`, {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
client.publish(`${root}/status`, `${heartbeat}`, { qos: 1, retain: true });
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
+5
-8
@@ -93,7 +93,7 @@ const windowEvents = (window, zoom) => {
|
||||
window.blur();
|
||||
}
|
||||
/* 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", () => {
|
||||
@@ -136,13 +136,10 @@ const windowEvents = (window, zoom) => {
|
||||
const viewEvents = (view) => {
|
||||
// Enable webview touch emulation
|
||||
view.webContents.debugger.attach("1.1");
|
||||
view.webContents.debugger.sendCommand(
|
||||
"Emulation.setEmitTouchEventsForMouse",
|
||||
{
|
||||
enabled: true,
|
||||
configuration: "mobile",
|
||||
}
|
||||
);
|
||||
view.webContents.debugger.sendCommand("Emulation.setEmitTouchEventsForMouse", {
|
||||
enabled: true,
|
||||
configuration: "mobile",
|
||||
});
|
||||
|
||||
// Disable webview hyperlinks
|
||||
view.webContents.setWindowOpenHandler(() => {
|
||||
|
||||
@@ -1129,10 +1129,10 @@ electron-installer-debian@^3.2.0:
|
||||
word-wrap "^1.2.3"
|
||||
yargs "^16.0.2"
|
||||
|
||||
electron@^33.2.1:
|
||||
version "33.2.1"
|
||||
resolved "https://registry.yarnpkg.com/electron/-/electron-33.2.1.tgz#d0d7bba7a7abf4f14881d0a6e03c498b301a2d5f"
|
||||
integrity sha512-SG/nmSsK9Qg1p6wAW+ZfqU+AV8cmXMTIklUL18NnOKfZLlum4ZsDoVdmmmlL39ZmeCaq27dr7CgslRPahfoVJg==
|
||||
electron@^33.3.1:
|
||||
version "33.3.1"
|
||||
resolved "https://registry.yarnpkg.com/electron/-/electron-33.3.1.tgz#26d63b3a110c4a9db639c33633bf806f91b4f649"
|
||||
integrity sha512-Z7l2bVgpdKxHQMI4i0CirBX2n+iCYKOx5mbzNM3BpOyFELwlobEXKmzCmEnwP+3EcNeIhUQyIEBFQxN06QgdIw==
|
||||
dependencies:
|
||||
"@electron/get" "^2.0.0"
|
||||
"@types/node" "^20.9.0"
|
||||
@@ -2396,6 +2396,11 @@ postject@^1.0.0-alpha.6:
|
||||
dependencies:
|
||||
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:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/proc-log/-/proc-log-2.0.1.tgz#8f3f69a1f608de27878f91f5c688b225391cb685"
|
||||
|
||||
Reference in New Issue
Block a user