import { Appliance } from '../appliance.js'; import type { TranslationMap } from '../types.js'; export class DaikinBRP069 extends Appliance { static TRANSLATIONS: TranslationMap = { mode: { '2': 'dry', '3': 'cool', '4': 'hot', '6': 'fan', '0': 'auto', '1': 'auto-1', '7': 'auto-7', '10': 'off', }, f_rate: { 'A': 'auto', 'B': 'silence', '3': '1', '4': '2', '5': '3', '6': '4', '7': '5', }, f_dir: { '0': 'off', '1': 'vertical', '2': 'horizontal', '3': '3d', }, en_hol: { '0': 'off', '1': 'on', }, en_streamer: { '0': 'off', '1': 'on', }, adv: { '': 'off', '2': 'powerful', '2/13': 'powerful streamer', '12': 'econo', '12/13': 'econo streamer', '13': 'streamer', }, spmode_kind: { '0': 'streamer', '1': 'powerful', '2': 'econo', }, spmode: { '0': 'off', '1': 'on', }, }; static VALUES_TRANSLATION: Record = { otemp: 'outside temp', htemp: 'inside temp', stemp: 'target temp', ver: 'firmware adapter', pow: 'power', cmpfreq: 'compressor frequency', f_rate: 'fan rate', f_dir: 'fan direction', err: 'error code', en_hol: 'away_mode', cur: 'internal clock', adv: 'advanced mode', filter_sign_info: 'filter dirty', }; static VALUES_SUMMARY: string[] = [ 'name', 'ip', 'mac', 'mode', 'f_rate', 'f_dir', 'htemp', 'otemp', 'stemp', 'cmpfreq', 'en_hol', 'err', 'cur', 'adv', ]; static HTTP_RESOURCES: string[] = [ 'common/basic_info', 'aircon/get_sensor_info', 'aircon/get_model_info', 'aircon/get_control_info', 'aircon/get_day_power_ex', 'aircon/get_week_power', 'aircon/get_year_power', ]; static INFO_RESOURCES: string[] = [ 'aircon/get_sensor_info', 'aircon/get_control_info', ]; static MAX_CONCURRENT_REQUESTS = 1; constructor(deviceId: string, httpsRejectUnauthorized = true) { super(deviceId, httpsRejectUnauthorized); } parseResponse(responseBody: string): Record { const response = super.parseResponse(responseBody); if (response['f_dir_ud'] === '0' && response['f_dir_lr'] === '0') { response['f_dir'] = '0'; } else if (response['f_dir_ud'] === 'S' && response['f_dir_lr'] === '0') { response['f_dir'] = '1'; } else if (response['f_dir_ud'] === '0' && response['f_dir_lr'] === 'S') { response['f_dir'] = '2'; } else if (response['f_dir_ud'] === 'S' && response['f_dir_lr'] === 'S') { response['f_dir'] = '3'; } return response; } async init(): Promise { await this.autoSetClock(); await this.updateStatus(DaikinBRP069.HTTP_RESOURCES); } getInfoResources(): string[] { if (this.supportEnergyConsumption) { return DaikinBRP069.INFO_RESOURCES.concat([ 'aircon/get_day_power_ex', 'aircon/get_week_power', ]); } return DaikinBRP069.INFO_RESOURCES; } async set(settings: Record): Promise { const resource = 'aircon/get_control_info'; const currentVal = await this.getResource(resource); this.values.updateByResource(resource, currentVal); this.values.updateByResource( resource, Object.fromEntries( Object.entries(settings).map(([k, v]) => [ k, (this.constructor as typeof DaikinBRP069).humanToDaikin(k, v), ]), ), ); if (settings.mode === 'off') { this.values.set('pow', '0'); this.values.set('mode', currentVal.mode || ''); } else if ('mode' in settings || !settings) { this.values.set('pow', '1'); } for (const [k, val] of [['stemp', 'dt'], ['shum', 'dh'], ['f_rate', 'dfr']] as const) { if (!(k in settings)) { const key = val + (this.values.get('mode') || ''); if (key in currentVal) { this.values.set(k, currentVal[key]); } } } const params: Record = { mode: this.values.get('mode') || '', pow: this.values.get('pow') || '', shum: this.values.get('shum') || '', stemp: this.values.get('stemp') || '', }; if (this.supportFanRate) { params.f_rate = this.values.get('f_rate') || ''; } if (this.supportSwingMode) { if (this.values.has('f_dir_lr') && this.values.has('f_dir_ud')) { const f_dir_ud = ['1', '3'].includes(this.values.get('f_dir') || '') ? 'S' : '0'; const f_dir_lr = ['2', '3'].includes(this.values.get('f_dir') || '') ? 'S' : '0'; params['f_dir_ud'] = f_dir_ud; params['f_dir_lr'] = f_dir_lr; } else { params['f_dir'] = this.values.get('f_dir') || '0'; } } await this.getResource('aircon/set_control_info', params); } async setHoliday(mode: string): Promise { const value = DaikinBRP069.humanToDaikin('en_hol', mode); if (value === '0' || value === '1') { this.values.set('en_hol', value); await this.getResource('common/set_holiday', { en_hol: value }); } } async setAdvancedMode(mode: string, value: string): Promise { const modeVal = DaikinBRP069.humanToDaikin('spmode_kind', mode); const valueVal = DaikinBRP069.humanToDaikin('spmode', value); if (valueVal === '0' || valueVal === '1') { const response = await this.getResource('aircon/set_special_mode', { spmode_kind: modeVal, set_spmode: valueVal, }); this.values.updateByResource('aircon/set_special_mode', response); } } async setStreamer(mode: string): Promise { const value = DaikinBRP069.humanToDaikin('en_streamer', mode); if (value === '0' || value === '1') { const response = await this.getResource('aircon/set_special_mode', { en_streamer: value, }); this.values.updateByResource('aircon/set_special_mode', response); } } async setClock(): Promise { const now = new Date(); await this.getResource('common/notify_date_time', { date: now.toISOString().split('T')[0].replace(/-/g, '/'), zone: 'GMT', time: now.toTimeString().split(' ')[0], }); } async autoSetClock(): Promise { try { await this.getResource('common/get_datetime', { cur: '' }); } catch { // Ignore errors } } }