homebridge-lookin-http-ac
Version:
66 lines • 3.12 kB
JavaScript
import { AccessoryAC } from './acAccessory.js';
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes';
import { SensorPoller } from './sensorPoller.js';
import { TemperatureAccessory } from './temperatureAccessory.js';
import { HumidityAccessory } from './humidityAccessory.js';
export class Platform {
log;
config;
api;
Service;
Characteristic;
accessories = new Map();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
CustomServices;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
CustomCharacteristics;
constructor(log, config, api) {
this.log = log;
this.config = config;
this.api = api;
this.Service = api.hap.Service;
this.Characteristic = api.hap.Characteristic;
this.CustomServices = new EveHomeKitTypes(this.api).Services;
this.CustomCharacteristics = new EveHomeKitTypes(this.api).Characteristics;
this.api.on('didFinishLaunching', () => {
this.discoverDevices();
});
}
configureAccessory(accessory) {
this.accessories.set(accessory.UUID, accessory);
}
discoverDevices() {
for (const accessory of this.accessories.values()) {
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
}
this.accessories.clear();
const devices = this.config.devices;
if (!Array.isArray(devices)) {
this.log.warn('No devices configured under "devices" in platform config.');
return;
}
for (const device of devices) {
if (!device.name) {
this.log.warn('Skipping device without "name":', device);
continue;
}
this.log.info('Adding new accessory:', device.name);
const sensorPoller = new SensorPoller(device.ip, device.name, this.log);
//Temperature
const uuidTemp = this.api.hap.uuid.generate(device.name + ' Temperature Sensor');
const accessoryTemp = new this.api.platformAccessory(device.name + ' Temperature Sensor', uuidTemp);
new TemperatureAccessory(this, accessoryTemp, sensorPoller);
//Humidity
const uuidHum = this.api.hap.uuid.generate(device.name + ' Humidity Sensor');
const accessoryHum = new this.api.platformAccessory(device.name + ' Humidity Sensor', uuidHum);
new HumidityAccessory(this, accessoryHum, sensorPoller);
//AC
const uuidAC = this.api.hap.uuid.generate(device.name);
const accessoryAC = new this.api.platformAccessory(device.name, uuidAC);
new AccessoryAC(this, accessoryAC, device.ip, sensorPoller, device.irMap, device.off, device.debug, device.reqNum, device.reqTime, device.debounceTime, device.lowThreshold, device.mediumThreshold);
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessoryTemp, accessoryHum, accessoryAC]);
}
}
}
//# sourceMappingURL=platform.js.map