UNPKG

homebridge-ecowitt-weather-sensors

Version:

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

152 lines 8.75 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.WS68 = void 0; const EcowittAccessory_1 = require("./../EcowittAccessory"); const LightSensor_1 = require("./../sensors/LightSensor"); const UltravioletSensor_1 = require("./../sensors/UltravioletSensor"); const WindSensor_1 = require("./../sensors/WindSensor"); const BatterySensor_1 = require("./../sensors/BatterySensor"); const utils = __importStar(require("./../Utils")); //------------------------------------------------------------------------------ class WS68 extends EcowittAccessory_1.EcowittAccessory { platform; accessory; static properties = ['solarRadiation', 'uvIndex', 'windDirection', 'windSpeed', 'windGustSpeed', 'windMaxDailySpeed']; battery; solarRadiation; uvIndex; windDirection; windSpeed; windGust; maxDailyGust; constructor(platform, accessory) { super(platform, accessory, 'WS68', 'WS68 4-in-1 Solar Weather Sensor'); this.platform = platform; this.accessory = accessory; this.requiredData = ['wh68batt', 'solarradiation', 'uv', 'winddir', 'windspeedmph', 'windgustmph', 'maxdailygust']; 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, ['solarRadiation', `${this.shortServiceId}:solarRadiation`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:solarRadiation`); this.solarRadiation = new LightSensor_1.LightSensor(platform, accessory, `${this.accessoryId}:solarRadiation`, nameOverride || 'Solar Radiation'); } else { this.solarRadiation = new LightSensor_1.LightSensor(platform, accessory, `${this.accessoryId}:solarRadiation`, 'Solar Radiation'); this.solarRadiation.removeService(); this.solarRadiation = undefined; } if (!utils.includesAny(hidden, ['uvIndex', `${this.shortServiceId}:uvIndex`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:uvIndex`); this.uvIndex = new UltravioletSensor_1.UltravioletSensor(platform, accessory, `${this.accessoryId}:uvIndex`, nameOverride || 'UV Index'); } else { this.uvIndex = new UltravioletSensor_1.UltravioletSensor(platform, accessory, `${this.accessoryId}:uvIndex`, 'UV Index'); this.uvIndex.removeService(); this.uvIndex = 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; } } //---------------------------------------------------------------------------- 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}`); } const batt = parseFloat(dataReport['wh68batt']); const batteryLevel = batt / 1.6; const lowBattery = batt <= 1.2; this.battery?.updateLevel(utils.boundRange(batteryLevel * 100), dataReport.dateutc); this.battery?.updateStatusLow(lowBattery, dataReport.dateutc); this.solarRadiation?.update(parseFloat(dataReport['solarradiation']), dataReport.dateutc); this.uvIndex?.update(parseFloat(dataReport['uv']), utils.lookup(this.platform.config?.thresholds, 'uvIndex'), 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); } } exports.WS68 = WS68; //# sourceMappingURL=WS68.js.map