homebridge-daikin-smart-ac
Version:
A Homebridge plugin for Daikin Wifi Adapter AC using Local API
127 lines • 5.03 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Status = exports.FanDirection = exports.FanSpeed = exports.Mode = void 0;
var Mode;
(function (Mode) {
Mode[Mode["Auto"] = 0] = "Auto";
Mode[Mode["Dry"] = 1] = "Dry";
Mode[Mode["Cool"] = 2] = "Cool";
Mode[Mode["Heat"] = 3] = "Heat";
Mode[Mode["Fan"] = 4] = "Fan";
Mode[Mode["UNKNOWN"] = 5] = "UNKNOWN";
})(Mode = exports.Mode || (exports.Mode = {}));
var FanSpeed;
(function (FanSpeed) {
FanSpeed[FanSpeed["Night"] = 0] = "Night";
FanSpeed[FanSpeed["S1"] = 1] = "S1";
FanSpeed[FanSpeed["S2"] = 2] = "S2";
FanSpeed[FanSpeed["S3"] = 3] = "S3";
FanSpeed[FanSpeed["S4"] = 4] = "S4";
FanSpeed[FanSpeed["S5"] = 5] = "S5";
FanSpeed[FanSpeed["UNKNOWN"] = 6] = "UNKNOWN";
})(FanSpeed = exports.FanSpeed || (exports.FanSpeed = {}));
var FanDirection;
(function (FanDirection) {
FanDirection[FanDirection["Off"] = 0] = "Off";
FanDirection[FanDirection["Vertical"] = 1] = "Vertical";
FanDirection[FanDirection["Horizontal"] = 2] = "Horizontal";
FanDirection[FanDirection["VerticalAndHorizontal"] = 3] = "VerticalAndHorizontal";
FanDirection[FanDirection["UNKNOWN"] = 4] = "UNKNOWN";
})(FanDirection = exports.FanDirection || (exports.FanDirection = {}));
class Status {
constructor(controlInfo, sensorInfo) {
this.successUpdate = false;
this.fanDirection = FanDirection.UNKNOWN;
this.fanSpeed = FanSpeed.UNKNOWN;
this.heatTargetTemperature = 0;
this.coolTargetTemperature = 0;
this.mode = Mode.UNKNOWN;
this.roomTemperature = 0;
this.power = false;
this.MODES = {
'0': Mode.Auto,
'2': Mode.Dry,
'3': Mode.Cool,
'4': Mode.Heat,
'6': Mode.Fan
};
this.FAN_SPEEDS = {
A: FanSpeed.Night,
B: FanSpeed.Night,
'3': FanSpeed.S1,
'4': FanSpeed.S2,
'5': FanSpeed.S3,
'6': FanSpeed.S4,
'7': FanSpeed.S5
};
this.FAN_DIRECTIONS = {
'0': FanDirection.Off,
'1': FanDirection.Vertical,
'2': FanDirection.Horizontal,
'3': FanDirection.VerticalAndHorizontal
};
this.mirrorObj = (obj) => {
return Object.entries(obj).reduce((acc, [key, value]) => {
return {
...acc,
[value]: key
};
}, {});
};
this.M_FAN_DIRECTIONS = this.mirrorObj(this.FAN_DIRECTIONS);
this.M_FAN_SPEEDS = this.mirrorObj(this.FAN_SPEEDS);
this.M_MODES = this.mirrorObj(this.MODES);
if (!controlInfo || !sensorInfo) {
return;
}
this.update(controlInfo, sensorInfo);
}
get wasSuccessUpdate() {
return this.successUpdate;
}
get targetTemperature() {
if (this.mode === Mode.Heat) {
return this.heatTargetTemperature;
}
return this.coolTargetTemperature;
}
update(controlInfo, sensorInfo) {
var _a, _b, _c, _d, _e, _f;
if (!controlInfo || !sensorInfo) {
return;
}
this.fanSpeed =
(_b = this.FAN_SPEEDS[(_a = controlInfo.f_rate) === null || _a === void 0 ? void 0 : _a.toString()]) !== null && _b !== void 0 ? _b : FanSpeed.UNKNOWN;
this.mode = (_d = this.MODES[(_c = controlInfo.mode) === null || _c === void 0 ? void 0 : _c.toString()]) !== null && _d !== void 0 ? _d : Mode.UNKNOWN;
this.fanDirection =
(_f = this.FAN_DIRECTIONS[(_e = controlInfo.f_dir) === null || _e === void 0 ? void 0 : _e.toString()]) !== null && _f !== void 0 ? _f : FanDirection.UNKNOWN;
this.power = controlInfo.pow === '1';
this.heatTargetTemperature = parseFloat(controlInfo.dt4 || '0');
this.coolTargetTemperature = parseFloat(controlInfo.dt3 || '0');
try {
this.roomTemperature = parseFloat(sensorInfo.htemp || '0');
}
catch (_g) {
// keep previous value
}
this.successUpdate = true;
}
toParams() {
var _a, _b, _c, _d;
const params = new URLSearchParams();
params.set('f_dir', (_a = this.M_FAN_DIRECTIONS[this.fanDirection.toString()]) !== null && _a !== void 0 ? _a : '');
params.set('f_rate', (_b = this.M_FAN_SPEEDS[this.fanSpeed.toString()]) !== null && _b !== void 0 ? _b : '');
params.set('stemp', (_c = this.targetTemperature.toFixed(1)) !== null && _c !== void 0 ? _c : '');
params.set('mode', (_d = this.M_MODES[this.mode.toString()]) !== null && _d !== void 0 ? _d : '');
params.set('pow', this.power ? '1' : '0');
params.set('shum', '');
return params.toString();
}
clone() {
const copy = new this.constructor();
Object.assign(copy, this);
return copy;
}
}
exports.Status = Status;
//# sourceMappingURL=Status.js.map