This commit is contained in:
sebseb7
2025-12-25 05:43:36 +01:00
parent ab89cbc97f
commit c794dbaab8
4 changed files with 56 additions and 8 deletions

View File

@@ -276,8 +276,15 @@ export class ACInfinityClient {
// Constrain level 0-10
const safeLevel = Math.max(0, Math.min(10, Math.round(level)));
// Mode 1 = ON (Manual), 0 = OFF
const mode = safeLevel === 0 ? 0 : 1;
// AtType Constants from reverse engineering
const AtType = {
OFF: 1,
ON: 2,
AUTO: 3
};
// Mode 2 = ON (Manual), 1 = OFF
const mode = safeLevel === 0 ? AtType.OFF : AtType.ON;
// Merge with existing settings
// We need to send back mostly specific keys.
@@ -293,7 +300,11 @@ export class ACInfinityClient {
// Add mode/speak
params.append('mode', mode.toString());
params.append('speak', safeLevel.toString());
// NOTE: In Mode 1 (OFF), 'speak' sets the Minimum Speed (usually 0).
// In Mode 2 (ON), 'speak' sets the Maximum/Target Speed.
const speakValue = mode === AtType.OFF ? 0 : safeLevel;
params.append('speak', speakValue.toString());
// Copy other relevant fields from settings if they exist to maintain state
// Common fields seen in other implementations:
@@ -331,7 +342,7 @@ export class ACInfinityClient {
throw new ACInfinityClientError(`Set mode failed: ${JSON.stringify(data)}`);
}
console.log(`[AC] Set device ${devId} port ${port} to level ${safeLevel} (mode ${mode})`);
console.log(`[AC] Set device ${devId} port ${port} to level ${safeLevel} (mode ${mode}: ${mode === 1 ? 'OFF' : 'ON'})`);
return true;
} catch (error) {
console.error('[AC] Error setting device port:', error);