homebridge-ecowitt-weather-sensors
Version:
Homebridge support for your Fine Offset weather station (Ecowitt, Ambient, Froggit, GoGen, and more)
91 lines • 4.58 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.BASE = void 0;
const EcowittAccessory_1 = require("./../EcowittAccessory");
const TemperatureSensor_1 = require("./../sensors/TemperatureSensor");
const HumiditySensor_1 = require("./../sensors/HumiditySensor");
const utils = __importStar(require("./../Utils"));
//------------------------------------------------------------------------------
class BASE extends EcowittAccessory_1.EcowittAccessory {
platform;
accessory;
modelName;
static properties = ['indoorTemperature', 'indoorHumidity'];
temperature;
humidity;
constructor(platform, accessory, modelName) {
super(platform, accessory, 'BASE', `${modelName} Gateway`);
this.platform = platform;
this.accessory = accessory;
this.modelName = modelName;
this.requiredData = ['tempinf', 'humidityin'];
this.unusedData = ['baromrelin', 'baromabsin'];
const hideConfig = this.platform.config?.hidden || {};
const hideConfigCustom = this.platform.config?.customHidden || [];
const hidden = Object.keys(hideConfig).filter(k => !!hideConfig[k]).concat(hideConfigCustom);
if (!utils.includesAny(hidden, ['indoorTemperature', `${this.shortServiceId}:indoorTemperature`, `${modelName}:indoorTemperature`])) {
const temperatureName = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:indoorTemperature`);
this.temperature = new TemperatureSensor_1.TemperatureSensor(platform, accessory, `${this.accessoryId}:indoorTemperature`, temperatureName || 'Temperature');
}
else {
this.temperature = new TemperatureSensor_1.TemperatureSensor(platform, accessory, `${this.accessoryId}:indoorTemperature`, 'Temperature');
this.temperature.removeService();
this.temperature = undefined;
}
if (!utils.includesAny(hidden, ['indoorHumidity', `${this.shortServiceId}:indoorHumidity`, `${modelName}:indoorHumidity`])) {
const humidityName = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:indoorHumidity`);
this.humidity = new HumiditySensor_1.HumiditySensor(platform, accessory, `${this.accessoryId}:indoorHumidity`, humidityName || 'Humidity');
}
else {
this.humidity = new HumiditySensor_1.HumiditySensor(platform, accessory, `${this.accessoryId}:indoorHumidity`, 'Humidity');
this.humidity.removeService();
this.humidity = undefined;
}
}
//----------------------------------------------------------------------------
update(dataReport) {
if (!utils.includesAll(Object.keys(dataReport), this.requiredData)) {
throw new Error(`Update on ${this.accessoryId} requires data ${this.requiredData}`);
}
else {
this.platform.log.debug(`Updating accessory ${this.accessoryId}`);
}
this.temperature?.update(parseFloat(dataReport.tempinf), dataReport.dateutc);
this.humidity?.update(parseFloat(dataReport.humidityin), dataReport.dateutc);
}
}
exports.BASE = BASE;
//# sourceMappingURL=BASE.js.map