UNPKG

homebridge-ecowitt-weather-sensors

Version:

Homebridge support for your Fine Offset weather station (Ecowitt, Ambient, Froggit, GoGen, and more)

92 lines 5.76 kB
"use strict"; 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.WH41 = void 0; const EcowittAccessory_1 = require("./../EcowittAccessory"); const AirQualitySensor_1 = require("./../sensors/AirQualitySensor"); const BatterySensor_1 = require("./../sensors/BatterySensor"); const utils = __importStar(require("./../Utils")); //------------------------------------------------------------------------------ class WH41 extends EcowittAccessory_1.EcowittAccessory { constructor(platform, accessory, channel) { var _a, _b, _c, _d, _e; super(platform, accessory, 'WH41', 'WH41 PM2.5 Air Quality Sensor', channel); this.platform = platform; this.accessory = accessory; this.channel = channel; this.requiredData = [`pm25batt${this.channel}`, `pm25_ch${this.channel}`, `pm25_avg_24h_ch${this.channel}`]; const hideConfig = ((_a = this.platform.config) === null || _a === void 0 ? void 0 : _a.hidden) || {}; const hideConfigCustom = ((_b = this.platform.config) === null || _b === void 0 ? void 0 : _b.customHidden) || []; const hidden = Object.keys(hideConfig).filter(k => !!hideConfig[k]).concat(hideConfigCustom); if (!utils.includesAny(hidden, ['battery', `${this.shortServiceId}:battery`])) { const nameOverride = utils.lookup((_c = this.platform.config) === null || _c === void 0 ? void 0 : _c.nameOverrides, `${this.shortServiceId}:battery`); this.battery = new BatterySensor_1.BatterySensor(platform, accessory, `${this.accessoryId}:battery`, nameOverride || 'Battery'); } else { this.battery = new BatterySensor_1.BatterySensor(platform, accessory, `${this.accessoryId}:battery`, 'Battery'); this.battery.removeService(); this.battery = undefined; } if (!utils.includesAny(hidden, ['airQualityPM25', `${this.shortServiceId}:airQualityPM25`])) { const nameOverride = utils.lookup((_d = this.platform.config) === null || _d === void 0 ? void 0 : _d.nameOverrides, `${this.shortServiceId}:airQualityPM25`); this.airQualityPM25 = new AirQualitySensor_1.AirQualitySensor(platform, accessory, `${this.accessoryId}:airQualityPM25`, nameOverride || 'PM2.5 Air Quality'); } else { this.airQualityPM25 = new AirQualitySensor_1.AirQualitySensor(platform, accessory, `${this.accessoryId}:airQualityPM25`, 'airQualityPM25'); this.airQualityPM25.removeService(); this.airQualityPM25 = undefined; } if (!utils.includesAny(hidden, ['airQualityPM25Avg', `${this.shortServiceId}:airQualityPM25Avg`])) { const nameOverride = utils.lookup((_e = this.platform.config) === null || _e === void 0 ? void 0 : _e.nameOverrides, `${this.shortServiceId}:airQualityPM25Avg`); this.airQualityPM25Avg = new AirQualitySensor_1.AirQualitySensor(platform, accessory, `${this.accessoryId}:airQualityPM25Avg`, nameOverride || 'PM2.5 Air Quality 24h Avg'); } else { this.airQualityPM25Avg = new AirQualitySensor_1.AirQualitySensor(platform, accessory, `${this.accessoryId}:airQualityPM25Avg`, 'airQualityPM25Avg'); this.airQualityPM25Avg.removeService(); this.airQualityPM25Avg = undefined; } } //---------------------------------------------------------------------------- update(dataReport) { var _a, _b, _c, _d, _e; 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}`); } const batt = parseFloat(dataReport[`pm25batt${this.channel}`]); const batteryLevel = batt / 5.0; const lowBattery = batt <= 1.1; (_a = this.battery) === null || _a === void 0 ? void 0 : _a.updateLevel(utils.boundRange(batteryLevel * 100), dataReport.dateutc); (_b = this.battery) === null || _b === void 0 ? void 0 : _b.updateStatusLow(lowBattery, dataReport.dateutc); (_c = this.battery) === null || _c === void 0 ? void 0 : _c.updateChargingState(batt === 6, dataReport.dateutc); (_d = this.airQualityPM25) === null || _d === void 0 ? void 0 : _d.updatePM25(parseFloat(dataReport[`pm25_ch${this.channel}`]), dataReport.dateutc); (_e = this.airQualityPM25Avg) === null || _e === void 0 ? void 0 : _e.updatePM25(parseFloat(dataReport[`pm25_avg_24h_ch${this.channel}`]), dataReport.dateutc); } } exports.WH41 = WH41; WH41.properties = ['airQualityPM25', 'airQualityPM25Avg']; //# sourceMappingURL=WH41.js.map