UNPKG

homebridge-ecowitt-weather-sensors

Version:

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

282 lines 16.9 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.WN67 = void 0; const EcowittAccessory_1 = require("./../EcowittAccessory"); const TemperatureSensor_1 = require("./../sensors/TemperatureSensor"); const HumiditySensor_1 = require("./../sensors/HumiditySensor"); const WindSensor_1 = require("./../sensors/WindSensor"); const RainSensor_1 = require("./../sensors/RainSensor"); const BatterySensor_1 = require("./../sensors/BatterySensor"); const utils = __importStar(require("./../Utils")); //------------------------------------------------------------------------------ class WN67 extends EcowittAccessory_1.EcowittAccessory { platform; accessory; static properties = ['temperature', 'humidity', 'windDirection', 'windSpeed', 'windGustSpeed', 'windMaxDailySpeed', 'rainRate', 'rainEventTotal', 'rainHourlyTotal', 'rainLast24hTotal', 'rainDailyTotal', 'rainWeeklyTotal', 'rainMonthlyTotal', 'rainYearlyTotal']; battery; temperature; humidity; windDirection; windSpeed; windGust; maxDailyGust; rainRate; eventRain; hourlyRain; last24hRain; dailyRain; weeklyRain; monthlyRain; yearlyRain; totalRain; constructor(platform, accessory) { super(platform, accessory, 'WN67', 'WN67 5-in-1 Weather Sensor'); this.platform = platform; this.accessory = accessory; this.requiredData = [ 'wh65batt', 'tempf', 'humidity', 'winddir', 'windspeedmph', 'windgustmph', 'maxdailygust', 'eventrainin', 'hourlyrainin', 'dailyrainin', 'weeklyrainin', 'monthlyrainin' ]; this.optionalData = ['last24hrainin', 'yearlyrainin', 'rainratein', 'totalrainin']; const hideConfig = this.platform.config?.hidden || {}; const hideConfigCustom = this.platform.config?.customHidden || []; const hidden = Object.keys(hideConfig).filter(k => !!hideConfig[k]).concat(hideConfigCustom); let nameOverride; if (!utils.includesAny(hidden, ['battery', `${this.shortServiceId}:battery`])) { nameOverride = utils.lookup(this.platform.config?.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, ['temperature', `${this.shortServiceId}:temperature`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:temperature`); this.temperature = new TemperatureSensor_1.TemperatureSensor(platform, accessory, `${this.accessoryId}:temperature`, nameOverride || 'Temperature'); } else { this.temperature = new TemperatureSensor_1.TemperatureSensor(platform, accessory, `${this.accessoryId}:temperature`, 'Temperature'); this.temperature.removeService(); this.temperature = undefined; } if (!utils.includesAny(hidden, ['humidity', `${this.shortServiceId}:humidity`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:humidity`); this.humidity = new HumiditySensor_1.HumiditySensor(platform, accessory, `${this.accessoryId}:humidity`, nameOverride || 'Humidity'); } else { this.humidity = new HumiditySensor_1.HumiditySensor(platform, accessory, `${this.accessoryId}:humidity`, 'Humidity'); this.humidity.removeService(); this.humidity = undefined; } if (!utils.includesAny(hidden, ['winddirection', `${this.shortServiceId}:winddirection`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:winddirection`); this.windDirection = new WindSensor_1.WindSensor(platform, accessory, `${this.accessoryId}:winddirection`, nameOverride || 'Wind Direction'); } else { this.windDirection = new WindSensor_1.WindSensor(platform, accessory, `${this.accessoryId}:winddirection`, 'Wind Direction'); this.windDirection.removeService(); this.windDirection = undefined; } if (!utils.includesAny(hidden, ['windspeed', `${this.shortServiceId}:windspeed`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:windspeed`); this.windSpeed = new WindSensor_1.WindSensor(platform, accessory, `${this.accessoryId}:windspeed`, nameOverride || 'Wind Speed'); } else { this.windSpeed = new WindSensor_1.WindSensor(platform, accessory, `${this.accessoryId}:windspeed`, 'Wind Speed'); this.windSpeed.removeService(); this.windSpeed = undefined; } if (!utils.includesAny(hidden, ['windgustspeed', `${this.shortServiceId}:windgustspeed`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:windgustspeed`); this.windGust = new WindSensor_1.WindSensor(platform, accessory, `${this.accessoryId}:windgustspeed`, nameOverride || 'Wind Gust Speed'); } else { this.windGust = new WindSensor_1.WindSensor(platform, accessory, `${this.accessoryId}:windgustspeed`, 'Wind Gust Speed'); this.windGust.removeService(); this.windGust = undefined; } if (!utils.includesAny(hidden, ['windmaxdailyspeed', `${this.shortServiceId}:windmaxdailyspeed`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:windmaxdailyspeed`); this.maxDailyGust = new WindSensor_1.WindSensor(platform, accessory, `${this.accessoryId}:windmaxdailyspeed`, nameOverride || 'Wind Max Daily Speed'); } else { this.maxDailyGust = new WindSensor_1.WindSensor(platform, accessory, `${this.accessoryId}:windmaxdailyspeed`, 'Wind Max Daily Speed'); this.maxDailyGust.removeService(); this.maxDailyGust = undefined; } if (!utils.includesAny(hidden, ['rainrate', `${this.shortServiceId}:rainrate`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:rainrate`); this.rainRate = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainrate`, nameOverride || 'Rain Rate'); } else { this.rainRate = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainrate`, 'Rain Rate'); this.rainRate.removeService(); this.rainRate = undefined; } if (!utils.includesAny(hidden, ['raineventtotal', `${this.shortServiceId}:raineventtotal`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:raineventtotal`); this.eventRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:raineventtotal`, nameOverride || 'Rain Event Total'); } else { this.eventRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:raineventtotal`, 'Rain Event Total'); this.eventRain.removeService(); this.eventRain = undefined; } if (!utils.includesAny(hidden, ['rainhourlytotal', `${this.shortServiceId}:rainhourlytotal`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:rainhourlytotal`); this.hourlyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainhourlytotal`, nameOverride || 'Rain Hourly Total'); } else { this.hourlyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainhourlytotal`, 'Rain Hourly Total'); this.hourlyRain.removeService(); this.hourlyRain = undefined; } if (!utils.includesAny(hidden, ['rainLast24hTotal', `${this.shortServiceId}:rainLast24hTotal`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:rainLast24hTotal`); this.last24hRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainLast24hTotal`, nameOverride || 'Rain Last 24h Total'); } else { this.last24hRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainLast24hTotal`, 'Rain Last 24h Total'); this.last24hRain.removeService(); this.last24hRain = undefined; } if (!utils.includesAny(hidden, ['raindailytotal', `${this.shortServiceId}:raindailytotal`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:raindailytotal`); this.dailyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:raindailytotal`, nameOverride || 'Rain Daily Total'); } else { this.dailyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:raindailytotal`, 'Rain Daily Total'); this.dailyRain.removeService(); this.dailyRain = undefined; } if (!utils.includesAny(hidden, ['rainweeklytotal', `${this.shortServiceId}:rainweeklytotal`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:rainweeklytotal`); this.weeklyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainweeklytotal`, nameOverride || 'Rain Weekly Total'); } else { this.weeklyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainweeklytotal`, 'Rain Weekly Total'); this.weeklyRain.removeService(); this.weeklyRain = undefined; } if (!utils.includesAny(hidden, ['rainmonthlytotal', `${this.shortServiceId}:rainmonthlytotal`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:rainmonthlytotal`); this.monthlyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainmonthlytotal`, nameOverride || 'Rain Monthly Total'); } else { this.monthlyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainmonthlytotal`, 'Rain Monthly Total'); this.monthlyRain.removeService(); this.monthlyRain = undefined; } if (!utils.includesAny(hidden, ['rainyearlytotal', `${this.shortServiceId}:rainyearlytotal`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:rainyearlytotal`); this.yearlyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainyearlytotal`, nameOverride || 'Rain Yearly Total'); } else { this.yearlyRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainyearlytotal`, 'Rain Yearly Total'); this.yearlyRain.removeService(); this.yearlyRain = undefined; } if (!utils.includesAny(hidden, ['rainTotal', `${this.shortServiceId}:rainTotal`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:rainTotal`); this.totalRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainTotal`, nameOverride || 'Rain Total'); } else { this.totalRain = new RainSensor_1.RainSensor(platform, accessory, `${this.accessoryId}:rainTotal`, 'Rain Total'); this.totalRain.removeService(); this.totalRain = 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.battery?.updateStatusLow(dataReport.wh65batt === '1', dataReport.dateutc); this.temperature?.update(parseFloat(dataReport['tempf']), dataReport.dateutc); this.humidity?.update(parseFloat(dataReport['humidity']), dataReport.dateutc); this.windDirection?.updateDirection(parseFloat(dataReport.winddir), dataReport.dateutc); this.windSpeed?.updateSpeed(parseFloat(dataReport.windspeedmph), utils.lookup(this.platform.config?.thresholds, 'windSpeed'), dataReport.dateutc); this.windGust?.updateSpeed(parseFloat(dataReport.windgustmph), utils.lookup(this.platform.config?.thresholds, 'windGustSpeed'), dataReport.dateutc); this.maxDailyGust?.updateSpeed(parseFloat(dataReport.maxdailygust), utils.lookup(this.platform.config?.thresholds, 'windMaxDailySpeed'), dataReport.dateutc); // optional if (dataReport.rainratein === undefined) { this.rainRate?.removeService(); this.rainRate = undefined; } else { this.rainRate?.updateRate(parseFloat(dataReport.rainratein), utils.lookup(this.platform.config?.thresholds, 'rainRate'), dataReport.dateutc); } this.eventRain?.updateTotal(parseFloat(dataReport.eventrainin), utils.lookup(this.platform.config?.thresholds, 'rainEventTotal'), dataReport.dateutc); this.hourlyRain?.updateTotal(parseFloat(dataReport.hourlyrainin), utils.lookup(this.platform.config?.thresholds, 'rainHourlyTotal'), dataReport.dateutc); // optional if (dataReport.last24hrainin === undefined) { this.last24hRain?.removeService(); this.last24hRain = undefined; } else { this.last24hRain?.updateTotal(parseFloat(dataReport.last24hrainin), utils.lookup(this.platform.config?.thresholds, 'rainLast24hTotal'), dataReport.dateutc); } this.dailyRain?.updateTotal(parseFloat(dataReport.dailyrainin), utils.lookup(this.platform.config?.thresholds, 'rainDailyTotal'), dataReport.dateutc); this.weeklyRain?.updateTotal(parseFloat(dataReport.weeklyrainin), utils.lookup(this.platform.config?.thresholds, 'rainWeeklyTotal'), dataReport.dateutc); this.monthlyRain?.updateTotal(parseFloat(dataReport.monthlyrainin), utils.lookup(this.platform.config?.thresholds, 'rainMonthlyTotal'), dataReport.dateutc); // optional if (dataReport.yearlyrainin === undefined) { this.yearlyRain?.removeService(); this.yearlyRain = undefined; } else { this.yearlyRain?.updateTotal(parseFloat(dataReport.yearlyrainin), utils.lookup(this.platform.config?.thresholds, 'rainYearlyTotal'), dataReport.dateutc); } // optional if (dataReport.totalrainin === undefined) { this.totalRain?.removeService(); this.totalRain = undefined; } else { this.totalRain?.updateTotal(parseFloat(dataReport.totalrainin), utils.lookup(this.platform.config?.thresholds, 'rainTotal'), dataReport.dateutc); } } } exports.WN67 = WN67; //# sourceMappingURL=WN67.js.map