feat: Implement Tapo P110/P115 power and energy monitoring, add Tapo device testing utilities, and include a database upsert test.

This commit is contained in:
sebseb7
2026-01-22 01:17:46 -05:00
parent 22050d1350
commit d093e18877
5 changed files with 279 additions and 12 deletions

View File

@@ -221,8 +221,17 @@ if (process.env.TAPO_USERNAME && process.env.TAPO_PASSWORD) {
? Buffer.from(deviceInfo.nickname, 'base64').toString('utf8').replace(/\0/g, '')
: null;
const stmt = db.prepare("INSERT OR REPLACE INTO devices (mac, model, connected, last_seen) VALUES (?, ?, ?, ?)");
stmt.run(mac, model, value === true && component === 'system' && field === 'online' ? 1 : null, new Date().toISOString());
const stmt = db.prepare(`
INSERT INTO devices (mac, model, connected, last_seen)
VALUES (?, ?, ?, ?)
ON CONFLICT(mac) DO UPDATE SET
model = excluded.model,
connected = COALESCE(excluded.connected, devices.connected),
last_seen = excluded.last_seen
`);
const connectedState = value === true && component === 'system' && field === 'online' ? 1 :
(value === false && component === 'system' && field === 'online' ? 0 : null);
stmt.run(mac, model, connectedState, new Date().toISOString());
stmt.finalize();
if (nickname) {
@@ -316,6 +325,12 @@ wss.on('connection', (ws, req) => {
}
}
}
// Log extracted RSSI from NotifyFullStatus
const possibleMac = data.params.sys ? data.params.sys.mac : null;
if (possibleMac && data.params.wifi && typeof data.params.wifi.rssi !== 'undefined') {
checkAndLogEvent(possibleMac, 'wifi', 'rssi', 'range', data.params.wifi.rssi, connectionId);
}
}
// Request device info to populate database
@@ -405,6 +420,11 @@ wss.on('connection', (ws, req) => {
}
}
}
// Check for wifi updates in NotifyStatus
if (data.params.wifi && typeof data.params.wifi.rssi !== 'undefined') {
checkAndLogEvent(mac, 'wifi', 'rssi', 'range', data.params.wifi.rssi, connectionId);
}
}
}
}