UNPKG

@k-roon/homebridge-hejhome-ir

Version:
67 lines 3.17 kB
import { IrBaseAccessory } from './IrBaseAccessory.js'; export class IrAirconditionerAccessory extends IrBaseAccessory { isOn = false; mode = 2; // 0 cool, 1 heat, 2 auto targetTemp = 24; fan = 0; // 0~3 swing = false; constructor(platform, accessory, device) { super(platform, accessory, device, 'HeaterCooler'); const { Characteristic } = this.platform.api.hap; /* 필수 특성 -------------------------------------------------- */ this.service.getCharacteristic(Characteristic.Active) .onGet(() => (this.isOn ? 1 : 0)) .onSet(v => this.setActive(!!v)); this.service.getCharacteristic(Characteristic.TargetHeaterCoolerState) .setProps({ validValues: [0, 1, 2] }) // AUTO / HEAT / COOL .onGet(() => this.mode) .onSet(v => this.setMode(v)); /* 온도 ------------------------------------------------------- */ this.service.getCharacteristic(Characteristic.CoolingThresholdTemperature) .setProps({ minValue: 18, maxValue: 30, minStep: 1 }) .onGet(() => this.targetTemp) .onSet(v => this.setTemperature(v)); this.service.getCharacteristic(Characteristic.HeatingThresholdTemperature) .setProps({ minValue: 18, maxValue: 30, minStep: 1 }) .onGet(() => this.targetTemp) .onSet(v => this.setTemperature(v)); /* 팬 속도 ---------------------------------------------------- */ this.service.getCharacteristic(Characteristic.RotationSpeed) .setProps({ minValue: 0, maxValue: 100, minStep: 33 }) .onGet(() => this.fan * 33) // 0-33-66-99 .onSet(v => this.setFanSpeed(v)); /* 스윙(바람 방향 자동) -------------------------------------- */ this.service.getCharacteristic(Characteristic.SwingMode) .onGet(() => (this.swing ? 1 : 0)) .onSet(v => this.setSwing(!!v)); /* 선택 특성 -------------------------------------------------- */ this.service.getCharacteristic(Characteristic.CurrentTemperature) .onGet(() => 25); // 외부 센서와 연동 가능 this.service.getCharacteristic(Characteristic.TemperatureDisplayUnits) .onGet(() => 0); // 섭씨 고정 } /* ========== SET 핸들러들 ========== */ async setActive(on) { await this.sendCommand('power', on ? 'true' : 'false'); this.isOn = on; } async setMode(state) { const map = { 2: '0', 1: '1', 0: '2' }; // COOL/HEAT/AUTO await this.sendCommand('mode', map[state]); this.mode = state; } async setTemperature(temp) { this.targetTemp = Math.round(temp); await this.sendCommand('temperature', this.targetTemp); } async setFanSpeed(percent) { const step = Math.round(percent / 33); // 0~3 await this.sendCommand('fanSpeed', String(step)); this.fan = step; } async setSwing(on) { await this.sendCommand('swing', on ? 'true' : 'false'); this.swing = on; } } //# sourceMappingURL=IrAirconditionerAccessory.js.map