homebridge-thermometer-am2320
Version:
AM2320 temperature/humidity sensor bridge for Homebridge: https://github.com/nfarina/homebridge"
56 lines • 2.38 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const sensor_1 = __importDefault(require("./sensor"));
let hap;
class AM2320Plugin {
constructor(log, config, _api) {
var _a, _b;
this.log = log;
this.name = config.name;
this.name_temperature = (_a = config.name_temperature) !== null && _a !== void 0 ? _a : this.name;
this.name_humidity = (_b = config.name_humidity) !== null && _b !== void 0 ? _b : this.name;
this.am2320 = new sensor_1.default(config.options);
const self = this;
this.temperatureService = new hap.Service.TemperatureSensor(this.name_temperature, this.name_temperature);
this.temperatureService.getCharacteristic(hap.Characteristic.CurrentTemperature)
.on("get" /* GET */, async (callback) => {
const value = await self.am2320.getCurrentTemperature();
callback(undefined, value);
});
this.humidityService = new hap.Service.HumiditySensor(this.name_humidity, this.name_humidity);
this.humidityService.getCharacteristic(hap.Characteristic.CurrentRelativeHumidity)
.on("get" /* GET */, async (callback) => {
const value = await self.am2320.getCurrentRelativeHumidity();
callback(undefined, value);
});
this.informationService = new hap.Service.AccessoryInformation()
.setCharacteristic(hap.Characteristic.Manufacturer, "Kawabata Farm")
.setCharacteristic(hap.Characteristic.Model, "AM2320");
log.info("AM2320 finished initializing!");
}
/*
* This method is optional to implement. It is called when HomeKit ask to identify the accessory.
* Typical this only ever happens at the pairing process.
*/
identify() {
this.log("Identify!");
}
/*
* This method is called directly after creation of this instance.
* It should return all services which should be added to the accessory.
*/
getServices() {
return [
this.temperatureService,
this.humidityService,
this.informationService,
];
}
}
module.exports = (api) => {
hap = api.hap;
api.registerAccessory("AM2320", AM2320Plugin);
};
//# sourceMappingURL=accessory.js.map