UNPKG

homebridge-ecowitt-weather-sensors

Version:

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

133 lines 6.83 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.LDS01 = void 0; const EcowittAccessory_1 = require("./../EcowittAccessory"); const DistanceSensor_1 = require("./../sensors/DistanceSensor"); const BatterySensor_1 = require("./../sensors/BatterySensor"); const utils = __importStar(require("./../Utils")); class LDS01 extends EcowittAccessory_1.EcowittAccessory { platform; accessory; channel; static properties = ['airGap', 'currentDepth', 'totalDepth']; battery; currentDepth; totalDepth; airGap; constructor(platform, accessory, channel) { super(platform, accessory, 'LDS01', 'LDS01 Laser Distance Sensor', channel); this.platform = platform; this.accessory = accessory; this.channel = channel; this.requiredData = [`ldsbatt${this.channel}`, `air_ch${this.channel}`]; this.optionalData = [`depth_ch${this.channel}`, `thi_ch${this.channel}`]; 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, ['airGap', `${this.shortServiceId}:airGap`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:airGap`); this.airGap = new DistanceSensor_1.DistanceSensor(platform, accessory, `${this.accessoryId}:airGap`, nameOverride || 'Air Gap'); } else { this.airGap = new DistanceSensor_1.DistanceSensor(platform, accessory, `${this.accessoryId}:airGap`, 'Air Gap'); this.airGap.removeService(); this.airGap = undefined; } if (!utils.includesAny(hidden, ['currentDepth', `${this.shortServiceId}:currentDepth`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:currentDepth`); this.currentDepth = new DistanceSensor_1.DistanceSensor(platform, accessory, `${this.accessoryId}:currentDepth`, nameOverride || 'Current Depth'); } else { this.currentDepth = new DistanceSensor_1.DistanceSensor(platform, accessory, `${this.accessoryId}:currentDepth`, 'Current Depth'); this.currentDepth.removeService(); this.currentDepth = undefined; } if (!utils.includesAny(hidden, ['totalDepth', `${this.shortServiceId}:totalDepth`])) { nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:totalDepth`); this.totalDepth = new DistanceSensor_1.DistanceSensor(platform, accessory, `${this.accessoryId}:totalDepth`, nameOverride || 'Total Depth'); } else { this.totalDepth = new DistanceSensor_1.DistanceSensor(platform, accessory, `${this.accessoryId}:totalDepth`, 'Total Depth'); this.totalDepth.removeService(); this.totalDepth = 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[`ldsbatt${this.channel}`]); const batteryLevel = batt / 3.3; const lowBattery = batt <= 2.3; this.battery?.updateLevel(utils.boundRange(batteryLevel * 100), dataReport.dateutc); this.battery?.updateStatusLow(lowBattery, dataReport.dateutc); this.airGap?.updateDepth(parseFloat(dataReport[`air_ch${this.channel}`]), utils.lookup(this.platform.config?.thresholds, 'airGap'), dataReport.dateutc); // optional if (dataReport[`depth_ch${this.channel}`] === undefined) { this.currentDepth?.removeService(); this.currentDepth = undefined; } else { this.currentDepth?.updateDepth(parseFloat(dataReport[`depth_ch${this.channel}`]), utils.lookup(this.platform.config?.thresholds, 'currentDepth'), dataReport.dateutc); } // optional // case when set to 0 means not set by the user const totalDepth = dataReport[`thi_ch${this.channel}`]; if (totalDepth === undefined || parseFloat(totalDepth) === 0) { this.totalDepth?.removeService(); this.totalDepth = undefined; } else { this.totalDepth?.updateDepth(parseFloat(totalDepth), utils.lookup(this.platform.config?.thresholds, 'totalDepth'), dataReport.dateutc); } } } exports.LDS01 = LDS01; //# sourceMappingURL=LDS01.js.map