UNPKG

homebridge-ecowitt-weather-sensors

Version:

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

104 lines 5.56 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.EcowittAccessory = void 0; const utils = __importStar(require("./Utils")); //------------------------------------------------------------------------------ class EcowittAccessory { platform; accessory; modelName; accessoryName; channel; requiredData = []; // fields that must be provided optionalData = []; // fields that are used if available unusedData = []; // fields that are not used / displayed accessoryId; shortServiceId; constructor(platform, accessory, modelName, accessoryName, channel = undefined) { this.platform = platform; this.accessory = accessory; this.modelName = modelName; this.accessoryName = accessoryName; this.channel = channel; this.accessoryId = this.platform.serviceId(this.modelName, this.channel); this.shortServiceId = this.platform.shortServiceId(this.modelName, this.channel); const accessoryInfo = this.accessory.getService(this.platform.Service.AccessoryInformation); accessoryInfo .setCharacteristic(this.platform.Characteristic.Manufacturer, platform.baseStationInfo.protocol) .setCharacteristic(this.platform.Characteristic.Model, this.accessoryName.split(' ')[0]) .setCharacteristic(this.platform.Characteristic.Name, this.accessoryName) .setCharacteristic(this.platform.Characteristic.ProductData, `${platform.baseStationInfo.frequency} Hz`) .setCharacteristic(this.platform.Characteristic.SerialNumber, this.accessoryId) .setCharacteristic(this.platform.Characteristic.HardwareRevision, platform.baseStationInfo.hardwareRevision) .setCharacteristic(this.platform.Characteristic.SoftwareRevision, platform.baseStationInfo.softwareRevision) .setCharacteristic(this.platform.Characteristic.FirmwareRevision, platform.baseStationInfo.firmwareRevision); } //---------------------------------------------------------------------------- // eslint-disable-next-line @typescript-eslint/no-unused-vars update(dataReport) { this.platform.log.error(`Update function not implemented for ${this.modelName}. ` + `Please file a bug report at ${utils.BUG_REPORT_LINK}`); } //--------------------------------------------------------------------------- addBattery(name, chargeable = false) { const battery = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery, name); battery.setCharacteristic(this.platform.Characteristic.Name, `${name}`); battery.setCharacteristic(this.platform.Characteristic.ChargingState, chargeable ? this.platform.Characteristic.ChargingState.NOT_CHARGING : this.platform.Characteristic.ChargingState.NOT_CHARGEABLE); battery.setCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); return battery; } //--------------------------------------------------------------------------- updateBatteryLevel(service, batteryLevel) { service.updateCharacteristic(this.platform.Characteristic.BatteryLevel, batteryLevel); } //--------------------------------------------------------------------------- updateStatusLowBattery(service, lowBattery) { service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, lowBattery ? this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); } //--------------------------------------------------------------------------- updateChargingState(service, charging = false) { service.updateCharacteristic(this.platform.Characteristic.ChargingState, charging ? this.platform.Characteristic.ChargingState.CHARGING : this.platform.Characteristic.ChargingState.NOT_CHARGING); } } exports.EcowittAccessory = EcowittAccessory; //# sourceMappingURL=EcowittAccessory.js.map