homebridge-ecowitt-weather-sensors
Version:
Homebridge support for your Fine Offset weather station (Ecowitt, Ambient, Froggit, GoGen, and more)
83 lines • 3.83 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 (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LightSensor = void 0;
const Sensor_1 = require("./Sensor");
const utils = __importStar(require("./../Utils"));
//------------------------------------------------------------------------------
class LightSensor extends Sensor_1.Sensor {
constructor(platform, accessory, id, name) {
super(platform, accessory, accessory.services.filter(s => s.subtype === platform.serviceUuid(id))[0]
|| accessory.addService(platform.Service.LightSensor, name, platform.serviceUuid(id)));
this.platform = platform;
this.accessory = accessory;
this.id = id;
this.name = name;
// adjust bounds of lux value
this.service.getCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel)
.setProps({
minValue: 0,
maxValue: 150000,
});
this.setName(name);
this.setStatusActive(false);
}
//---------------------------------------------------------------------------
update(solarRadiation, time) {
var _a, _b, _c, _d;
if (!Number.isFinite(solarRadiation)) {
this.platform.log.warn(`Cannot update ${this.name}, solar radiation ${solarRadiation} is NaN`);
this.updateStatusActive(false);
return;
}
const luxFactor = ((_b = (_a = this.platform.config) === null || _a === void 0 ? void 0 : _a.additional) === null || _b === void 0 ? void 0 : _b.luxFactor) || 126.7;
let lux = luxFactor * solarRadiation;
let luxStr = '';
if (lux < 0.0) { // ambient light characterstic min is 0
this.platform.log.warn(`Solar radiation below the minimum of 0.0lx for ${this.id}`);
lux = 0.0;
luxStr = '0lx';
}
else if (lux > 150000) { // ambient light characterstic max is 150000
this.platform.log.warn(`Solar radiation above the maximum of 150000lx for ${this.id}`);
lux = 150000;
luxStr = '150000lx';
}
else {
luxStr = `${Math.round(lux)}lx`;
}
const staticNames = utils.truthy((_d = (_c = this.platform.config) === null || _c === void 0 ? void 0 : _c.additional) === null || _d === void 0 ? void 0 : _d.staticNames);
this.updateName(staticNames ? this.name : `${this.name} ${luxStr}`);
this.updateLux(lux);
this.updateStatusActive(true);
this.updateTime(time);
}
//---------------------------------------------------------------------------
updateLux(lux) {
this.service.updateCharacteristic(this.platform.Characteristic.CurrentAmbientLightLevel, lux);
}
}
exports.LightSensor = LightSensor;
//# sourceMappingURL=LightSensor.js.map