UNPKG

homebridge-ecowitt-weather-sensors

Version:

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

220 lines 16.4 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.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 { constructor(platform, accessory) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r; 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 = ['yearlyrainin', 'rainratein']; this.unusedData = ['totalrainin']; 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); let nameOverride; if (!utils.includesAny(hidden, ['battery', `${this.shortServiceId}:battery`])) { 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, ['temperature', `${this.shortServiceId}:temperature`])) { nameOverride = utils.lookup((_d = this.platform.config) === null || _d === void 0 ? void 0 : _d.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((_e = this.platform.config) === null || _e === void 0 ? void 0 : _e.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((_f = this.platform.config) === null || _f === void 0 ? void 0 : _f.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((_g = this.platform.config) === null || _g === void 0 ? void 0 : _g.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((_h = this.platform.config) === null || _h === void 0 ? void 0 : _h.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((_j = this.platform.config) === null || _j === void 0 ? void 0 : _j.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((_k = this.platform.config) === null || _k === void 0 ? void 0 : _k.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((_l = this.platform.config) === null || _l === void 0 ? void 0 : _l.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((_m = this.platform.config) === null || _m === void 0 ? void 0 : _m.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, ['raindailytotal', `${this.shortServiceId}:raindailytotal`])) { nameOverride = utils.lookup((_o = this.platform.config) === null || _o === void 0 ? void 0 : _o.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((_p = this.platform.config) === null || _p === void 0 ? void 0 : _p.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((_q = this.platform.config) === null || _q === void 0 ? void 0 : _q.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((_r = this.platform.config) === null || _r === void 0 ? void 0 : _r.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; } } //---------------------------------------------------------------------------- update(dataReport) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1; 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}`); } (_a = this.battery) === null || _a === void 0 ? void 0 : _a.updateStatusLow(dataReport.wh65batt === '1', dataReport.dateutc); (_b = this.temperature) === null || _b === void 0 ? void 0 : _b.update(parseFloat(dataReport['tempf']), dataReport.dateutc); (_c = this.humidity) === null || _c === void 0 ? void 0 : _c.update(parseFloat(dataReport['humidity']), dataReport.dateutc); (_d = this.windDirection) === null || _d === void 0 ? void 0 : _d.updateDirection(parseFloat(dataReport.winddir), dataReport.dateutc); (_e = this.windSpeed) === null || _e === void 0 ? void 0 : _e.updateSpeed(parseFloat(dataReport.windspeedmph), utils.lookup((_f = this.platform.config) === null || _f === void 0 ? void 0 : _f.thresholds, 'windSpeed'), dataReport.dateutc); (_g = this.windGust) === null || _g === void 0 ? void 0 : _g.updateSpeed(parseFloat(dataReport.windgustmph), utils.lookup((_h = this.platform.config) === null || _h === void 0 ? void 0 : _h.thresholds, 'windGustSpeed'), dataReport.dateutc); (_j = this.maxDailyGust) === null || _j === void 0 ? void 0 : _j.updateSpeed(parseFloat(dataReport.maxdailygust), utils.lookup((_k = this.platform.config) === null || _k === void 0 ? void 0 : _k.thresholds, 'windMaxDailySpeed'), dataReport.dateutc); if (dataReport.rainratein === undefined) { (_l = this.rainRate) === null || _l === void 0 ? void 0 : _l.removeService(); this.rainRate = undefined; } else { (_m = this.rainRate) === null || _m === void 0 ? void 0 : _m.updateRate(parseFloat(dataReport.rainratein), utils.lookup((_o = this.platform.config) === null || _o === void 0 ? void 0 : _o.thresholds, 'rainRate'), dataReport.dateutc); } (_p = this.eventRain) === null || _p === void 0 ? void 0 : _p.updateTotal(parseFloat(dataReport.eventrainin), utils.lookup((_q = this.platform.config) === null || _q === void 0 ? void 0 : _q.thresholds, 'rainEventTotal'), dataReport.dateutc); (_r = this.hourlyRain) === null || _r === void 0 ? void 0 : _r.updateTotal(parseFloat(dataReport.hourlyrainin), utils.lookup((_s = this.platform.config) === null || _s === void 0 ? void 0 : _s.thresholds, 'rainHourlyTotal'), dataReport.dateutc); (_t = this.dailyRain) === null || _t === void 0 ? void 0 : _t.updateTotal(parseFloat(dataReport.dailyrainin), utils.lookup((_u = this.platform.config) === null || _u === void 0 ? void 0 : _u.thresholds, 'rainDailyTotal'), dataReport.dateutc); (_v = this.weeklyRain) === null || _v === void 0 ? void 0 : _v.updateTotal(parseFloat(dataReport.weeklyrainin), utils.lookup((_w = this.platform.config) === null || _w === void 0 ? void 0 : _w.thresholds, 'rainWeeklyTotal'), dataReport.dateutc); (_x = this.monthlyRain) === null || _x === void 0 ? void 0 : _x.updateTotal(parseFloat(dataReport.monthlyrainin), utils.lookup((_y = this.platform.config) === null || _y === void 0 ? void 0 : _y.thresholds, 'rainMonthlyTotal'), dataReport.dateutc); if (dataReport.yearlyrainin === undefined) { (_z = this.yearlyRain) === null || _z === void 0 ? void 0 : _z.removeService(); this.yearlyRain = undefined; } else { (_0 = this.yearlyRain) === null || _0 === void 0 ? void 0 : _0.updateTotal(parseFloat(dataReport.yearlyrainin), utils.lookup((_1 = this.platform.config) === null || _1 === void 0 ? void 0 : _1.thresholds, 'rainYearlyTotal'), dataReport.dateutc); } } } exports.WN67 = WN67; WN67.properties = ['temperature', 'humidity', 'windDirection', 'windSpeed', 'windGustSpeed', 'windMaxDailySpeed', 'rainEventTotal', 'rainHourlyTotal', 'rainDailyTotal', 'rainWeekyTotal', 'rainMonthlyTotal', 'rainYearlyTotal']; //# sourceMappingURL=WN67.js.map