another shot at brightness adjustments
Build Images and Deploy / Update-PROD-Stack (push) Successful in 19s
Build Images and Deploy / Update-PROD-Stack (push) Successful in 19s
This commit is contained in:
@@ -131,19 +131,34 @@ async function getBrightness(host, port) {
|
|||||||
const res = await soapWithFallback(host, port, BE_URL, BE_SVC, 'GetBinaryState');
|
const res = await soapWithFallback(host, port, BE_URL, BE_SVC, 'GetBinaryState');
|
||||||
const raw = String(res['BinaryState'] ?? '0');
|
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)
|
// Example: "1|50|0" where 50 is the brightness level (0-100)
|
||||||
if (raw.includes('|')) {
|
if (raw.includes('|')) {
|
||||||
const parts = raw.split('|');
|
const parts = raw.split('|');
|
||||||
if (parts.length >= 2) {
|
if (parts.length >= 2) {
|
||||||
const brightness = parseInt(parts[1], 10);
|
const brightness = parseInt(parts[1], 10);
|
||||||
|
console.log(`[DWM] Brightness from pipe format: ${brightness}`);
|
||||||
return !isNaN(brightness) ? brightness : null;
|
return !isNaN(brightness) ? brightness : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If device is on but no brightness info, assume 100%
|
||||||
// If device is off, return 0
|
// 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) {
|
} catch (err) {
|
||||||
|
console.log(`[DWM] getBrightness failed: ${err.message}, falling back to binary state`);
|
||||||
// Fallback for non-dimmer devices
|
// Fallback for non-dimmer devices
|
||||||
const isOn = await getBinaryState(host, port);
|
const isOn = await getBinaryState(host, port);
|
||||||
return isOn ? 100 : 0;
|
return isOn ? 100 : 0;
|
||||||
@@ -161,12 +176,13 @@ async function setBrightness(host, port, brightness) {
|
|||||||
console.log(`[DWM] Brightness 0, turning device off`);
|
console.log(`[DWM] Brightness 0, turning device off`);
|
||||||
await setBinaryState(host, port, false);
|
await setBinaryState(host, port, false);
|
||||||
} else {
|
} else {
|
||||||
// For dimmers, use the brightness format: "brightness|0"
|
// For dimmers, use the correct format: BinaryState=1, brightness=level
|
||||||
// For non-dimmers, just turn on
|
// This matches the Python pywemo implementation
|
||||||
try {
|
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', {
|
await soapWithFallback(host, port, BE_URL, BE_SVC, 'SetBinaryState', {
|
||||||
BinaryState: `${level}|0`
|
BinaryState: '1',
|
||||||
|
brightness: level.toString()
|
||||||
});
|
});
|
||||||
console.log(`[DWM] Dimmer brightness set successfully`);
|
console.log(`[DWM] Dimmer brightness set successfully`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user