From 9e6101dc3cc6cd037eb1ae50412a63790dbe8269 Mon Sep 17 00:00:00 2001 From: Mike Johnston Date: Mon, 30 Mar 2026 22:57:42 -0400 Subject: [PATCH] another shot at brightness adjustments --- packages/homebridge-plugin/lib/wemo-client.js | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/homebridge-plugin/lib/wemo-client.js b/packages/homebridge-plugin/lib/wemo-client.js index e967033..5b9d85a 100644 --- a/packages/homebridge-plugin/lib/wemo-client.js +++ b/packages/homebridge-plugin/lib/wemo-client.js @@ -131,19 +131,34 @@ async function getBrightness(host, port) { const res = await soapWithFallback(host, port, BE_URL, BE_SVC, 'GetBinaryState'); const raw = String(res['BinaryState'] ?? '0'); - // For dimmers, BinaryState contains brightness info in format: "1|brightness|..." + console.log(`[DWM] Raw BinaryState response: "${raw}"`); + + // For dimmers, check if brightness is available as a separate parameter + // This matches the Python pywemo implementation + if (res.brightness !== undefined) { + const brightness = parseInt(res.brightness, 10); + console.log(`[DWM] Brightness from separate parameter: ${brightness}`); + return !isNaN(brightness) ? brightness : null; + } + + // Fallback: Check if BinaryState contains brightness info in format: "1|brightness|..." // Example: "1|50|0" where 50 is the brightness level (0-100) if (raw.includes('|')) { const parts = raw.split('|'); if (parts.length >= 2) { const brightness = parseInt(parts[1], 10); + console.log(`[DWM] Brightness from pipe format: ${brightness}`); return !isNaN(brightness) ? brightness : null; } } + // If device is on but no brightness info, assume 100% // If device is off, return 0 - return raw === '1' || raw === '8' ? 100 : 0; + const isOn = raw === '1' || raw === '8'; + console.log(`[DWM] No brightness info, using binary state: ${isOn ? 100 : 0}`); + return isOn ? 100 : 0; } catch (err) { + console.log(`[DWM] getBrightness failed: ${err.message}, falling back to binary state`); // Fallback for non-dimmer devices const isOn = await getBinaryState(host, port); return isOn ? 100 : 0; @@ -161,12 +176,13 @@ async function setBrightness(host, port, brightness) { console.log(`[DWM] Brightness 0, turning device off`); await setBinaryState(host, port, false); } else { - // For dimmers, use the brightness format: "brightness|0" - // For non-dimmers, just turn on + // For dimmers, use the correct format: BinaryState=1, brightness=level + // This matches the Python pywemo implementation try { - console.log(`[DWM] Trying dimmer brightness format: ${level}|0`); + console.log(`[DWM] Trying dimmer format: BinaryState=1, brightness=${level}`); await soapWithFallback(host, port, BE_URL, BE_SVC, 'SetBinaryState', { - BinaryState: `${level}|0` + BinaryState: '1', + brightness: level.toString() }); console.log(`[DWM] Dimmer brightness set successfully`); } catch (err) {