ref: remove unsupported mqtt config

This commit is contained in:
leukipp
2025-09-10 16:00:26 +02:00
parent 758f64ced4
commit a4c300407b
+49 -26
View File
@@ -140,6 +140,22 @@ const update = async () => {
updateBatteryLevel(); updateBatteryLevel();
}; };
/**
* Removes the auto-discovery config via the mqtt connection.
*
* @param {string} type - The entity type name.
* @param {Object} config - The configuration object.
* @returns {Object} Instance of the mqtt client.
*/
const removeConfig = (type, config) => {
if (type === null || config === null) {
return INTEGRATION.client;
}
const path = config.unique_id.replace(`${INTEGRATION.node}_`, "");
const root = `${INTEGRATION.discovery}/${type}/${INTEGRATION.node}/${path}/config`;
return INTEGRATION.client.publish(root, null, { qos: 1, retain: true });
};
/** /**
* Publishes the auto-discovery config via the mqtt connection. * Publishes the auto-discovery config via the mqtt connection.
* *
@@ -190,9 +206,6 @@ const publishState = (path, state) => {
* Initializes the app update entity and handles the execute logic. * Initializes the app update entity and handles the execute logic.
*/ */
const initApp = () => { const initApp = () => {
if (!HARDWARE.support.appUpdate) {
return;
}
const root = `${INTEGRATION.root}/app`; const root = `${INTEGRATION.root}/app`;
const config = { const config = {
name: "App", name: "App",
@@ -202,6 +215,10 @@ const initApp = () => {
payload_install: "update", payload_install: "update",
device: INTEGRATION.device, device: INTEGRATION.device,
}; };
if (!HARDWARE.support.appUpdate) {
removeConfig("update", config);
return;
}
publishConfig("update", config) publishConfig("update", config)
.on("message", (topic, message) => { .on("message", (topic, message) => {
if (topic === config.command_topic) { if (topic === config.command_topic) {
@@ -226,7 +243,7 @@ const initApp = () => {
*/ */
const updateApp = async (progress = 0) => { const updateApp = async (progress = 0) => {
const latest = APP.releases.latest; const latest = APP.releases.latest;
if (!latest || !latest.summary) { if (!HARDWARE.support.appUpdate || !latest || !latest.summary) {
return; return;
} }
const summary = latest.summary.length > 250 ? latest.summary.slice(0, 250) + "..." : latest.summary; const summary = latest.summary.length > 250 ? latest.summary.slice(0, 250) + "..." : latest.summary;
@@ -246,9 +263,6 @@ const updateApp = async (progress = 0) => {
* Initializes the shutdown button and handles the execute logic. * Initializes the shutdown button and handles the execute logic.
*/ */
const initShutdown = () => { const initShutdown = () => {
if (!HARDWARE.support.sudoRights) {
return;
}
const root = `${INTEGRATION.root}/shutdown`; const root = `${INTEGRATION.root}/shutdown`;
const config = { const config = {
name: "Shutdown", name: "Shutdown",
@@ -257,6 +271,10 @@ const initShutdown = () => {
icon: "mdi:power", icon: "mdi:power",
device: INTEGRATION.device, device: INTEGRATION.device,
}; };
if (!HARDWARE.support.sudoRights) {
removeConfig("button", config);
return;
}
publishConfig("button", config) publishConfig("button", config)
.on("message", (topic, message) => { .on("message", (topic, message) => {
if (topic === config.command_topic) { if (topic === config.command_topic) {
@@ -273,9 +291,6 @@ const initShutdown = () => {
* Initializes the reboot button and handles the execute logic. * Initializes the reboot button and handles the execute logic.
*/ */
const initReboot = () => { const initReboot = () => {
if (!HARDWARE.support.sudoRights) {
return;
}
const root = `${INTEGRATION.root}/reboot`; const root = `${INTEGRATION.root}/reboot`;
const config = { const config = {
name: "Reboot", name: "Reboot",
@@ -284,6 +299,10 @@ const initReboot = () => {
icon: "mdi:restart", icon: "mdi:restart",
device: INTEGRATION.device, device: INTEGRATION.device,
}; };
if (!HARDWARE.support.sudoRights) {
removeConfig("button", config);
return;
}
publishConfig("button", config) publishConfig("button", config)
.on("message", (topic, message) => { .on("message", (topic, message) => {
if (topic === config.command_topic) { if (topic === config.command_topic) {
@@ -384,9 +403,6 @@ const updateKiosk = async () => {
* Initializes the display status, brightness and handles the execute logic. * Initializes the display status, brightness and handles the execute logic.
*/ */
const initDisplay = () => { const initDisplay = () => {
if (!HARDWARE.support.displayStatus) {
return;
}
const root = `${INTEGRATION.root}/display`; const root = `${INTEGRATION.root}/display`;
const config = { const config = {
name: "Display", name: "Display",
@@ -402,6 +418,10 @@ const initDisplay = () => {
brightness_scale: 100, brightness_scale: 100,
}), }),
}; };
if (!HARDWARE.support.displayStatus) {
removeConfig("light", config);
return;
}
publishConfig("light", config) publishConfig("light", config)
.on("message", (topic, message) => { .on("message", (topic, message) => {
if (topic === config.command_topic) { if (topic === config.command_topic) {
@@ -445,9 +465,6 @@ const updateDisplay = async () => {
* Initializes the keyboard visibility and handles the execute logic. * Initializes the keyboard visibility and handles the execute logic.
*/ */
const initKeyboard = () => { const initKeyboard = () => {
if (!HARDWARE.support.keyboardVisibility) {
return;
}
const root = `${INTEGRATION.root}/keyboard`; const root = `${INTEGRATION.root}/keyboard`;
const config = { const config = {
name: "Keyboard", name: "Keyboard",
@@ -457,6 +474,10 @@ const initKeyboard = () => {
icon: "mdi:keyboard-close-outline", icon: "mdi:keyboard-close-outline",
device: INTEGRATION.device, device: INTEGRATION.device,
}; };
if (!HARDWARE.support.keyboardVisibility) {
removeConfig("switch", config);
return;
}
publishConfig("switch", config) publishConfig("switch", config)
.on("message", (topic, message) => { .on("message", (topic, message) => {
if (topic === config.command_topic) { if (topic === config.command_topic) {
@@ -495,9 +516,6 @@ const updateKeyboard = async () => {
* Initializes the page number and handles the execute logic. * Initializes the page number and handles the execute logic.
*/ */
const initPageNumber = () => { const initPageNumber = () => {
if (WEBVIEW.viewUrls.length <= 2) {
return;
}
const root = `${INTEGRATION.root}/page_number`; const root = `${INTEGRATION.root}/page_number`;
const config = { const config = {
name: "Page Number", name: "Page Number",
@@ -512,6 +530,10 @@ const initPageNumber = () => {
icon: "mdi:page-next", icon: "mdi:page-next",
device: INTEGRATION.device, device: INTEGRATION.device,
}; };
if (WEBVIEW.viewUrls.length <= 2) {
removeConfig("number", config);
return;
}
publishConfig("number", config) publishConfig("number", config)
.on("message", (topic, message) => { .on("message", (topic, message) => {
if (topic === config.command_topic) { if (topic === config.command_topic) {
@@ -529,7 +551,7 @@ const initPageNumber = () => {
* Updates the page number via the mqtt connection. * Updates the page number via the mqtt connection.
*/ */
const updatePageNumber = async () => { const updatePageNumber = async () => {
const pageNumber = WEBVIEW.viewActive || 1; const pageNumber = WEBVIEW.viewUrls.length <= 2 ? null : WEBVIEW.viewActive || 1;
publishState("page_number", pageNumber); publishState("page_number", pageNumber);
}; };
@@ -850,9 +872,6 @@ const updateProcessorTemperature = async () => {
* Initializes the battery level sensor. * Initializes the battery level sensor.
*/ */
const initBatteryLevel = () => { const initBatteryLevel = () => {
if (!HARDWARE.support.batteryLevel) {
return;
}
const root = `${INTEGRATION.root}/battery_level`; const root = `${INTEGRATION.root}/battery_level`;
const config = { const config = {
name: "Battery Level", name: "Battery Level",
@@ -863,6 +882,10 @@ const initBatteryLevel = () => {
icon: "mdi:battery-medium", icon: "mdi:battery-medium",
device: INTEGRATION.device, device: INTEGRATION.device,
}; };
if (!HARDWARE.support.batteryLevel) {
removeConfig("sensor", config);
return;
}
publishConfig("sensor", config); publishConfig("sensor", config);
updateBatteryLevel(); updateBatteryLevel();
}; };
@@ -898,12 +921,12 @@ const initPackageUpgrades = () => {
*/ */
const updatePackageUpgrades = async () => { const updatePackageUpgrades = async () => {
const packages = hardware.checkPackageUpgrades(); const packages = hardware.checkPackageUpgrades();
const attributes = { const upgrades = {
total: packages.length, total: packages.length,
packages: packages.map((pkg) => pkg.replace(/\s*\[.*?\]\s*/g, "").trim()), packages: packages.map((pkg) => pkg.replace(/\s*\[.*?\]\s*/g, "").trim()),
}; };
publishState("package_upgrades", attributes.total); publishState("package_upgrades", upgrades.total);
publishAttributes("package_upgrades", attributes); publishAttributes("package_upgrades", upgrades);
}; };
/** /**