iobroker.gree-hvac
Version:
Adapter for Gree and C&H conditioners
88 lines (87 loc) • 2.54 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var adapter_utils_exports = {};
__export(adapter_utils_exports, {
default: () => adapter_utils_default
});
module.exports = __toCommonJS(adapter_utils_exports);
class AdapterUtils {
/**
*
*/
static fahrenheitToCelsius(fahrenheit) {
return Math.round((fahrenheit - 32) * 5 / 9);
}
/**
*
*/
static celsiusToFahrenheit(celsius) {
return Math.round(celsius * 1.8 + 32);
}
/**
*
*/
static validateIPList(ipList) {
try {
const ipPattern = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
for (const networkItem of ipList) {
if (!ipPattern.test(networkItem.deviceIp)) {
return false;
}
}
return true;
} catch {
return false;
}
}
/**
*
*/
static convertValue(values, value, mapItem) {
if (!mapItem.fromConverter) {
return value;
}
return mapItem.fromConverter(values, value);
}
/**
*
*/
static mapValue(value, mapItem) {
var _a;
const definition = JSON.parse(mapItem.definition);
if ((_a = definition.native) == null ? void 0 : _a.valuesMap) {
const valuesMap = definition.native.valuesMap;
const valueMap = valuesMap.find((item) => item.targetValue === value);
if (valueMap) {
return valueMap.value;
}
}
return value;
}
/**
*
*/
static areObjectsTheSame(adapterObject, definition) {
let result = JSON.stringify(adapterObject.common) === JSON.stringify(definition.common);
result = result && JSON.stringify(adapterObject.native) === JSON.stringify(definition.native);
return result;
}
}
var adapter_utils_default = AdapterUtils;
//# sourceMappingURL=adapter-utils.js.map