Compare commits

...

2 Commits

Author SHA1 Message Date
sebseb7
a09da9a835 u 2025-12-25 05:48:56 +01:00
sebseb7
c794dbaab8 u 2025-12-25 05:43:36 +01:00
4 changed files with 78 additions and 9 deletions

View File

@@ -141,6 +141,8 @@ export class ACInfinityClient {
.replace(/[^a-z0-9]+/g, '-') .replace(/[^a-z0-9]+/g, '-')
.replace(/^-|-$/g, ''); .replace(/^-|-$/g, '');
console.log(`[AC] Debug: Device ${deviceId} (${device.devName}) Type: ${device.devType}`);
// --- Device Level Sensors --- // --- Device Level Sensors ---
// Temperature (Celsius * 100) // Temperature (Celsius * 100)
@@ -272,12 +274,23 @@ export class ACInfinityClient {
const settings = await this.getDeviceModeSettings(devId, port); const settings = await this.getDeviceModeSettings(devId, port);
if (!settings) throw new Error('Could not fetch existing settings'); if (!settings) throw new Error('Could not fetch existing settings');
console.log(`[AC] Debug: Device Settings for ${devId}:${port}`, JSON.stringify(settings));
// Log device info if available to check type? We don't have devType here easily without passing it or fetching list again.
// But settings usually contains some info.
// 2. Prepare updates // 2. Prepare updates
// Constrain level 0-10 // Constrain level 0-10
const safeLevel = Math.max(0, Math.min(10, Math.round(level))); const safeLevel = Math.max(0, Math.min(10, Math.round(level)));
// Mode 1 = ON (Manual), 0 = OFF // AtType Constants from reverse engineering
const mode = safeLevel === 0 ? 0 : 1; 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 // Merge with existing settings
// We need to send back mostly specific keys. // We need to send back mostly specific keys.
@@ -293,7 +306,23 @@ export class ACInfinityClient {
// Add mode/speak // Add mode/speak
params.append('mode', mode.toString()); 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());
// CRITICAL FIX: Explicitly set atType to match the mode!
// atType: 1 = OFF, 2 = ON, 3 = AUTO
params.append('atType', mode.toString());
// Ensure onSpead (Max Speed) matches target if in ON mode
if (mode === AtType.ON) {
params.append('onSpead', safeLevel.toString());
} else {
// In OFF mode, ensure onSpead is at least present (maybe 10 or 0? Leaving existing or default)
if (!params.has('onSpead')) params.append('onSpead', '10');
}
// Copy other relevant fields from settings if they exist to maintain state // Copy other relevant fields from settings if they exist to maintain state
// Common fields seen in other implementations: // Common fields seen in other implementations:
@@ -316,7 +345,10 @@ export class ACInfinityClient {
if (!params.has('transitionType')) params.append('transitionType', '0'); if (!params.has('transitionType')) params.append('transitionType', '0');
// 3. Send update // 3. Send update
const response = await fetch(`${this.host}/api/dev/addDevMode?${params.toString()}`, { const requestUrl = `${this.host}/api/dev/addDevMode?${params.toString()}`;
console.log(`[AC] Debug: Sending request to ${requestUrl}`);
const response = await fetch(requestUrl, {
method: 'POST', method: 'POST',
headers: { headers: {
'User-Agent': 'ACController/1.9.7 (com.acinfinity.humiture; build:533; iOS 18.5.0) Alamofire/5.10.2', 'User-Agent': 'ACController/1.9.7 (com.acinfinity.humiture; build:533; iOS 18.5.0) Alamofire/5.10.2',
@@ -331,7 +363,7 @@ export class ACInfinityClient {
throw new ACInfinityClientError(`Set mode failed: ${JSON.stringify(data)}`); 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; return true;
} catch (error) { } catch (error) {
console.error('[AC] Error setting device port:', error); console.error('[AC] Error setting device port:', error);

17
debug_db.js Normal file
View File

@@ -0,0 +1,17 @@
const Database = require('better-sqlite3');
const path = require('path');
const dbPath = path.resolve(__dirname, 'server/data/sensors.db');
const db = new Database(dbPath, { readonly: true });
console.log('--- RULES ---');
const rules = db.prepare('SELECT * FROM rules').all();
console.log(JSON.stringify(rules, null, 2));
console.log('\n--- OUTPUT CHANNELS ---');
const outputs = db.prepare('SELECT * FROM output_events WHERE channel = "CircFanLevel" ORDER BY timestamp DESC LIMIT 10').all();
console.table(outputs);
console.log('\n--- SENSOR DATA (ac:tent:temperature) ---');
const sensors = db.prepare('SELECT * FROM sensor_events WHERE device = "ac" AND channel = "tent:temperature" ORDER BY timestamp DESC LIMIT 5').all();
console.table(sensors);

17
uiserver/debug_db.js Normal file
View File

@@ -0,0 +1,17 @@
const Database = require('better-sqlite3');
const path = require('path');
const dbPath = path.resolve(__dirname, '../server/data/sensors.db');
const db = new Database(dbPath, { readonly: true });
console.log('--- RULES ---');
const rules = db.prepare('SELECT * FROM rules').all();
console.log(JSON.stringify(rules, null, 2));
console.log('\n--- OUTPUT CHANNELS ---');
const outputs = db.prepare("SELECT * FROM output_events WHERE channel = 'CircFanLevel' ORDER BY timestamp DESC LIMIT 10").all();
console.table(outputs);
console.log('\n--- SENSOR DATA (ac:tent:temperature) ---');
const sensors = db.prepare("SELECT * FROM sensor_events WHERE device = 'ac' AND channel = 'tent:temperature' ORDER BY timestamp DESC LIMIT 5").all();
console.table(sensors);

View File

@@ -297,10 +297,15 @@ function syncOutputStates() {
if (row.value > 0) { if (row.value > 0) {
const binding = OUTPUT_BINDINGS[row.channel]; const binding = OUTPUT_BINDINGS[row.channel];
if (binding) { if (binding) {
let commandValue = row.value;
if (binding.type === 'switch') {
commandValue = row.value > 0 ? 1 : 0;
}
const success = sendCommandToDevicePrefix(`${binding.device}:`, { const success = sendCommandToDevicePrefix(`${binding.device}:`, {
device: binding.channel, device: binding.channel,
action: 'set_state', action: 'set_state',
value: 1 value: commandValue
}); });
if (!success) { if (!success) {
@@ -747,9 +752,7 @@ module.exports = {
`); `);
const last = lastStmt.get(channel); const last = lastStmt.get(channel);
if (channel === 'CircFanLevel') { // Debug log removed
console.log('[RuleRunner] Debug Bindings:', JSON.stringify(OUTPUT_BINDINGS['CircFanLevel']));
}
const valueChanged = !last || Math.abs(last.value - value) >= Number.EPSILON; const valueChanged = !last || Math.abs(last.value - value) >= Number.EPSILON;