homebridge-ecowitt-weather-sensors
Version:
Homebridge support for your Fine Offset weather station (Ecowitt, Ambient, Froggit, GoGen, and more)
96 lines • 3.99 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.LightSensor = void 0;
const Sensor_1 = require("./Sensor");
const utils = __importStar(require("./../Utils"));
//------------------------------------------------------------------------------
class LightSensor extends Sensor_1.Sensor {
platform;
accessory;
id;
name;
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) {
if (!Number.isFinite(solarRadiation)) {
this.platform.log.warn(`Cannot update ${this.name}, solar radiation ${solarRadiation} is NaN`);
this.updateStatusActive(false);
return;
}
const luxFactor = this.platform.config?.additional?.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(this.platform.config?.additional?.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