import { Appliance } from '../appliance.js'; import type { TranslationMap } from '../types.js'; export class DaikinSkyFi extends Appliance { static TRANSLATIONS: TranslationMap = { mode: { '0': 'off', '1': 'auto', '2': 'hot', '3': 'auto-3', '4': 'dry', '8': 'cool', '9': 'auto-9', '16': 'fan', }, f_rate: { '1': 'low', '2': 'medium', '3': 'high', '5': 'low/auto', '6': 'medium/auto', '7': 'high/auto', }, }; private static SKYFI_TO_DAIKIN: Record = { outsidetemp: 'otemp', roomtemp: 'htemp', settemp: 'stemp', opmode: 'pow', fanspeed: 'f_rate', acmode: 'mode', }; private static DAIKIN_TO_SKYFI: Record = Object.fromEntries( Object.entries(DaikinSkyFi.SKYFI_TO_DAIKIN).map(([k, v]) => [v, k]), ); private password: string; static HTTP_RESOURCES = ['ac.cgi', 'zones.cgi']; static INFO_RESOURCES = DaikinSkyFi.HTTP_RESOURCES; constructor(deviceId: string, password: string) { super(deviceId); this.baseUrl = `http://${this.deviceIp}:2000`; this.password = password; } parseResponse(responseBody: string): Record { const response: Record = {}; const pairs = responseBody.split('&'); for (const pair of pairs) { const [key, value] = pair.split('='); if (key) { response[key] = value || ''; } } if (response.fanflags === '3') { response.fanspeed = String(parseInt(response.fanspeed || '0', 10) + 4); } const mapped: Record = {}; for (const [key, value] of Object.entries(response)) { const newKey = DaikinSkyFi.SKYFI_TO_DAIKIN[key] || key; mapped[newKey] = value; } return mapped; } async getResource(path: string, params?: Record): Promise> { const allParams = { pass: this.password, ...params }; const result = await super.getResource(path, allParams); await new Promise((resolve) => setTimeout(resolve, 300)); return result; } async init(): Promise { await this.updateStatus(DaikinSkyFi.HTTP_RESOURCES); } async set(settings: Record): Promise { await this.updateStatus(['ac.cgi']); for (const [key, value] of Object.entries(settings)) { const skyfiKey = DaikinSkyFi.DAIKIN_TO_SKYFI[key]; if (skyfiKey) { this.values.set(skyfiKey, DaikinSkyFi.humanToDaikin(key, value)); } } if (settings.mode === 'off') { this.values.set('opmode', '0'); await this.getResource('set.cgi', { p: this.values.get('opmode') || '' }); } else { if (settings.mode) { this.values.set('opmode', '1'); } const params: Record = { p: this.values.get('opmode') || '0', t: this.values.get('settemp') || '', f: this.values.get('fanspeed') || '', m: this.values.get('acmode') || '', }; await this.getResource('set.cgi', params); } } get supportAwayMode(): boolean { return false; } get supportFanRate(): boolean { return true; } get supportSwingMode(): boolean { return false; } get supportHumidity(): boolean { return false; } get humidity(): number | null { return null; } }