UNPKG

homebridge-ecowitt-weather-sensors

Version:

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

120 lines 6.72 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.WH52 = void 0; const EcowittAccessory_1 = require("./../EcowittAccessory"); const HumiditySensor_1 = require("./../sensors/HumiditySensor"); const TemperatureSensor_1 = require("./../sensors/TemperatureSensor"); const ConductivitySensor_1 = require("./../sensors/ConductivitySensor"); const BatterySensor_1 = require("./../sensors/BatterySensor"); const utils = __importStar(require("./../Utils")); //------------------------------------------------------------------------------ class WH52 extends EcowittAccessory_1.EcowittAccessory { platform; accessory; channel; static properties = ['soilMoisture', 'soilTemperature', 'soilConductivity']; battery; soilMoisture; soilTemperature; soilConductivity; constructor(platform, accessory, channel) { super(platform, accessory, 'WH52', 'WH52 3-in-1 SoilSensor', channel); this.platform = platform; this.accessory = accessory; this.channel = channel; this.requiredData = [`soil_ec_batt${this.channel}`, `soil_ec_hum${this.channel}`, `soil_ec_temp${this.channel}`, `soil_ec${this.channel}`]; this.unusedData = [`soil_ec_hum_ad${this.channel}`, `soil_ec_ad${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); if (!utils.includesAny(hidden, ['battery', `${this.shortServiceId}:battery`])) { const 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, ['soilmoisture', `${this.shortServiceId}:soilmoisture`])) { const nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:soilmoisture`); this.soilMoisture = new HumiditySensor_1.HumiditySensor(platform, accessory, `${this.accessoryId}:soilmoisture`, nameOverride || 'Soil Moisture'); } else { this.soilMoisture = new HumiditySensor_1.HumiditySensor(platform, accessory, `${this.accessoryId}:soilmoisture`, 'Soil Moisture'); this.soilMoisture.removeService(); this.soilMoisture = undefined; } if (!utils.includesAny(hidden, ['soiltemperature', `${this.shortServiceId}:soiltemperature`])) { const nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:soiltemperature`); this.soilTemperature = new TemperatureSensor_1.TemperatureSensor(platform, accessory, `${this.accessoryId}:soiltemperature`, nameOverride || 'Soil Temperature'); } else { this.soilTemperature = new TemperatureSensor_1.TemperatureSensor(platform, accessory, `${this.accessoryId}:soiltemperature`, 'Soil Temperature'); this.soilTemperature.removeService(); this.soilTemperature = undefined; } if (!utils.includesAny(hidden, ['soilconductivity', `${this.shortServiceId}:soilconductivity`])) { const nameOverride = utils.lookup(this.platform.config?.nameOverrides, `${this.shortServiceId}:soilconductivity`); this.soilConductivity = new ConductivitySensor_1.ConductivitySensor(platform, accessory, `${this.accessoryId}:soilconductivity`, nameOverride || 'Soil Conductivity'); } else { this.soilConductivity = new ConductivitySensor_1.ConductivitySensor(platform, accessory, `${this.accessoryId}:soilconductivity`, 'Soil Conductivity'); this.soilConductivity.removeService(); this.soilConductivity = 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[`soil_ec_batt${this.channel}`]); 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.soilMoisture?.update(parseFloat(dataReport[`soil_ec_hum${this.channel}`]), dataReport.dateutc); this.soilTemperature?.update(parseFloat(dataReport[`soil_ec_temp${this.channel}`]), dataReport.dateutc); this.soilConductivity?.update(parseFloat(dataReport[`soil_ec${this.channel}`]), utils.lookup(this.platform.config?.thresholds, 'soilConductivity'), dataReport.dateutc); } } exports.WH52 = WH52; //# sourceMappingURL=WH52.js.map