more debug logs
Build Images and Deploy / Update-PROD-Stack (push) Successful in 11s

This commit is contained in:
2026-03-30 22:29:18 -04:00
parent da2693ae68
commit 5bffb1064d
2 changed files with 198 additions and 6 deletions
+109 -6
View File
@@ -85,6 +85,80 @@ async function handleRequest(req, res) {
});
try {
// ── Debug endpoint ─────────────────────────────────────────────────────
if (url === '/api/debug/test-device' && method === 'POST') {
const { host, port } = body;
if (!host) {
return jsonErr(res, 'Host is required', 400);
}
const devicePort = port ? parseInt(port, 10) : 49153;
console.log(`[DWM] Debug test for ${host}:${devicePort}`);
const results = {};
// Test 1: HTTP connection to setup.xml
try {
const setupUrl = `http://${host}:${devicePort}/setup.xml`;
console.log(`[DWM] Testing setup.xml URL: ${setupUrl}`);
const response = await axios.get(setupUrl, {
timeout: 5000,
httpAgent: NO_KEEPALIVE
});
results.setupXml = {
status: response.status,
dataLength: response.data.length,
success: response.status === 200
};
console.log(`[DWM] setup.xml response:`, results.setupXml);
} catch (err) {
results.setupXml = {
success: false,
error: err.message,
code: err.code
};
console.log(`[DWM] setup.xml failed:`, err.message);
}
// Test 2: Try to get device info
try {
console.log(`[DWM] Testing getDeviceInfo`);
const deviceInfo = await wemo.getDeviceInfo(host, devicePort);
results.deviceInfo = {
success: true,
data: deviceInfo
};
console.log(`[DWM] getDeviceInfo successful:`, deviceInfo);
} catch (err) {
results.deviceInfo = {
success: false,
error: err.message
};
console.log(`[DWM] getDeviceInfo failed:`, err.message);
}
// Test 3: Try to get binary state
try {
console.log(`[DWM] Testing getBinaryState`);
const state = await wemo.getBinaryState(host, devicePort);
results.binaryState = {
success: true,
state: state
};
console.log(`[DWM] getBinaryState successful:`, state);
} catch (err) {
results.binaryState = {
success: false,
error: err.message
};
console.log(`[DWM] getBinaryState failed:`, err.message);
}
return json(res, results);
}
// ── Devices ────────────────────────────────────────────────────────────
if (url === '/api/devices' && method === 'GET') {
@@ -114,18 +188,47 @@ async function handleRequest(req, res) {
const devicePort = port ? parseInt(port, 10) : 49153;
const manualEntry = { host, port: devicePort };
console.log(`[DWM] Attempting to add device manually: ${host}:${devicePort}`);
try {
// Try to discover this specific device
const devices = await wemo.discoverDevices(5000, [manualEntry]);
if (devices.length > 0) {
// First try direct device info fetch
let device = null;
try {
console.log(`[DWM] Trying direct device info fetch for ${host}:${devicePort}`);
device = await wemo.getDeviceInfo(host, devicePort);
if (device) {
device.host = host;
device.port = devicePort;
device.manual = true; // Mark as manually added
console.log(`[DWM] Direct fetch successful:`, device);
}
} catch (directErr) {
console.log(`[DWM] Direct fetch failed:`, directErr.message);
}
// If direct fetch failed, try discovery with manual entry
if (!device) {
console.log(`[DWM] Trying discovery with manual entry`);
const devices = await wemo.discoverDevices(5000, [manualEntry]);
if (devices.length > 0) {
device = devices[0];
device.manual = true; // Mark as manually added
console.log(`[DWM] Discovery successful:`, device);
}
}
if (device) {
// Add to existing devices
const allDevices = [...store.getDevices(), ...devices];
const allDevices = [...store.getDevices(), ...[device]];
store.saveDevices(allDevices);
return json(res, devices[0], 201);
console.log(`[DWM] Device added successfully: ${device.friendlyName || device.host}`);
return json(res, device, 201);
} else {
return jsonErr(res, 'No Wemo device found at this address', 404);
console.log(`[DWM] No device found at ${host}:${devicePort}`);
return jsonErr(res, `No Wemo device found at ${host}:${devicePort}. Check IP address and port.`, 404);
}
} catch (err) {
console.log(`[DWM] Error adding device:`, err);
return jsonErr(res, `Failed to connect: ${err.message}`, 500);
}
}