homebridge-ecowitt-weather-sensors
Version:
Homebridge support for your Fine Offset weather station (Ecowitt, Ambient, Froggit, GoGen, and more)
87 lines • 5.14 kB
JavaScript
"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.EcowittAccessory = void 0;
const utils = __importStar(require("./Utils"));
//------------------------------------------------------------------------------
class EcowittAccessory {
constructor(platform, accessory, modelName, accessoryName, channel = undefined) {
this.platform = platform;
this.accessory = accessory;
this.modelName = modelName;
this.accessoryName = accessoryName;
this.channel = channel;
this.requiredData = []; // fields that must be provided
this.optionalData = []; // fields that are used if available
this.unusedData = []; // fields that are not used / displayed
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