feat: Home Assistant MQTT Integration - KöPi Angebote, Änderungs-Sensor, Check-Button, Nutzer-online-Sensor

This commit is contained in:
2026-07-10 17:53:35 +02:00
parent aa5c67d9f5
commit 5cbed956f6
5 changed files with 177 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
const express = require('express');
const https = require('https');
const db = require('../../db');
const mqttClient = require('../../mqtt');
const { authenticate } = require('../../middleware/auth');
const router = express.Router();
@@ -311,6 +312,7 @@ async function runDailyCheck(forceNotify = false) {
if (!changed && !forceNotify) {
console.log('🍺 KöPi-Check: keine Änderungen an den Angeboten.');
mqttClient.publishKoepiState({ offers, changed: false });
return { changed: false, sent: false, offerCount: offers.length };
}
@@ -318,6 +320,7 @@ async function runDailyCheck(forceNotify = false) {
db.prepare('INSERT OR REPLACE INTO admin_settings (key, value) VALUES (?, ?)')
.run(KOEPI_SETTINGS_KEY, currentSig);
console.log(`🍺 KöPi-Check: ${offers.length} Angebot(e)${changed ? ' geändert' : ' (Test, unverändert)'} Pushover versendet.`);
mqttClient.publishKoepiState({ offers, changed });
return { changed, sent: true, offerCount: offers.length };
} catch (e) {
console.error('KöPi Tages-Check Fehler:', e.message);