UNPKG

homebridge-ecowitt-weather-sensors

Version:

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

123 lines 5.43 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 () { 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.AirQualitySensor = void 0; const Sensor_1 = require("./Sensor"); const utils = __importStar(require("./../Utils")); //------------------------------------------------------------------------------ class AirQualitySensor 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.AirQualitySensor, name, platform.serviceUuid(id))); this.platform = platform; this.accessory = accessory; this.id = id; this.name = name; this.setName(name); this.setStatusActive(false); } //--------------------------------------------------------------------------- updatePM10(pm10, time) { if (!Number.isFinite(pm10)) { this.platform.log.warn(`Cannot update ${this.name}, pm10 ${pm10} is NaN`); this.updateStatusActive(false); return; } if (pm10 < 0) { this.platform.log.warn(`PM10 below the minimum of 0mcg/m³ for ${this.id}`); pm10 = 0; } else if (pm10 > 1000) { this.platform.log.warn(`PM10 above the maximum of 1000mcg/m³ for ${this.id}`); pm10 = 1000; } const pm10Str = `${pm10.toFixed(0)} mcg/m³`; const staticNames = utils.truthy(this.platform.config?.additional?.staticNames); this.updateName(staticNames ? this.name : `${this.name} ${pm10Str}`); this.updatePM10Density(pm10); this.updatePM10Quality(pm10); this.updateStatusActive(true); this.updateTime(time); } //--------------------------------------------------------------------------- updatePM25(pm25, time) { if (!Number.isFinite(pm25)) { this.platform.log.warn(`Cannot update ${this.name}, pm2.5 ${pm25} is NaN`); this.updateStatusActive(false); return; } if (pm25 < 0) { this.platform.log.warn(`PM25 below the minimum of 0mcg/m³ for ${this.id}`); pm25 = 0; } else if (pm25 > 1000) { this.platform.log.warn(`PM25 above the maximum of 1000mcg/m³ for ${this.id}`); pm25 = 1000; } const pm25Str = `${pm25.toFixed(0)} mcg/m³`; const staticNames = utils.truthy(this.platform.config?.additional?.staticNames); this.updateName(staticNames ? this.name : `${this.name} ${pm25Str}`); this.updatePM25Density(pm25); this.updatePM25Quality(pm25); this.updateStatusActive(true); this.updateTime(time); } //--------------------------------------------------------------------------- updatePM10Density(pm10) { this.service.updateCharacteristic(this.platform.Characteristic.PM10Density, pm10); } //--------------------------------------------------------------------------- updatePM25Density(pm25) { this.service.updateCharacteristic(this.platform.Characteristic.PM2_5Density, pm25); } //--------------------------------------------------------------------------- updatePM10Quality(pm10) { const airQuality = utils.toAirQuality(pm10, 'pm10'); this.platform.log.debug(`Setting ${this.name} pm10 quality to ${airQuality.description}`); this.service.updateCharacteristic(this.platform.Characteristic.AirQuality, airQuality.scale); } //--------------------------------------------------------------------------- updatePM25Quality(pm25) { const airQuality = utils.toAirQuality(pm25, 'pm25'); this.platform.log.debug(`Setting ${this.name} pm2.5 quality to ${airQuality.description}`); this.service.updateCharacteristic(this.platform.Characteristic.AirQuality, airQuality.scale); } } exports.AirQualitySensor = AirQualitySensor; //# sourceMappingURL=AirQualitySensor.js.map