homebridge-connect-my-pool
Version:
Partially complete HomeKit integration for Astral Viron Gateway
99 lines • 5.46 kB
JavaScript
"use strict";
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _ZoneAccessory_buttons;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZoneAccessory = void 0;
const constants_1 = require("../constants");
class ZoneAccessory {
constructor(platform, controller, zone) {
var _a;
this.enabledServices = [];
_ZoneAccessory_buttons.set(this, {});
this.identifyAccessory = () => {
var _a;
(_a = this.log) === null || _a === void 0 ? void 0 : _a.info(this.accessory.displayName, "Identify!");
};
this.eventZone = (zoneStatus) => {
if (this.zone.type === zoneStatus.zoneType) {
//this.debug('System Zone Event %s', zoneStatus.zoneType)
this.debug('Calling SetStatus Zone %s', zoneStatus.zoneType);
this.setStatus(zoneStatus);
}
};
this.api = platform.api;
this.debug = platform.debug.bind(platform);
this.hap = this.api.hap;
this.Service = platform.api.hap.Service;
this.Characteristic = platform.api.hap.Characteristic;
this.log = platform.log;
this.platform = platform;
this.gateway = platform.gateway;
const uuid = this.api.hap.uuid.generate(controller.name + zone.type);
// create a new accessory
(_a = this.log) === null || _a === void 0 ? void 0 : _a.info('Adding new accessory: %s, %s', `${zone.name}`, zone.type);
var categories = 9 /* THERMOSTAT */;
if (zone.type === "pool_and_spa" /* POOL_AND_SPA */)
categories = 15 /* PROGRAMMABLE_SWITCH */;
else if (zone.type === "lighting" /* LIGHTING */)
categories = 7 /* OUTLET */;
this.accessory = new this.api.platformAccessory(`${zone.name}`, uuid, categories);
this.controller = controller;
this.zone = zone;
var zoneName = zone.name;
this.accessory.on('identify', this.identifyAccessory.bind(this));
this.name = zoneName;
this.serial = `0000-0000-0001`;
this.model = `${controller.name}-${this.name}`;
this.debug('Name %s', this.name);
__classPrivateFieldSet(this, _ZoneAccessory_buttons, {}, "f");
this.gateway.on("ZONE" /* ZONE */, this.eventZone.bind(this));
this.setAccessoryInformationService();
this.setupServices();
}
////////////////////////
// UPDATE CHARACTERISTICS FROM ZONE
////////////////////////
////////////////////////
// GET AND SET FUNCTIONS
////////////////////////
////////////////////////
// ZONE SERVICE FUNCTIONS
////////////////////////
setAccessoryInformationService() {
// if((this.accessory = this.platform.accessories.find((x: PlatformAccessory) => x.UUID === uuid)!) === undefined) {
var _a, _b;
var infoService = this.accessory.getService(this.Service.AccessoryInformation);
if (infoService) {
infoService
.updateCharacteristic(this.Characteristic.Name, this.name)
.updateCharacteristic(this.Characteristic.Manufacturer, constants_1.MANUFACTURER)
.updateCharacteristic(this.Characteristic.Model, this.model)
.updateCharacteristic(this.Characteristic.SerialNumber, this.serial)
.updateCharacteristic(this.Characteristic.FirmwareRevision, constants_1.PLUGIN_VERSION);
var configuredName = infoService.getCharacteristic(this.Characteristic.ConfiguredName) || infoService.addCharacteristic(this.Characteristic.ConfiguredName);
if (configuredName.value === '')
configuredName.setValue(this.name);
var hardwareRevision = infoService.getCharacteristic(this.Characteristic.HardwareRevision) || infoService.addCharacteristic(this.Characteristic.HardwareRevision);
hardwareRevision.setValue((_a = this.controller.macAddress) !== null && _a !== void 0 ? _a : constants_1.PLUGIN_VERSION);
var softwareRevision = infoService.getCharacteristic(this.Characteristic.SoftwareRevision) || infoService.addCharacteristic(this.Characteristic.SoftwareRevision);
softwareRevision.setValue((_b = this.controller.systemVersion) !== null && _b !== void 0 ? _b : constants_1.PLUGIN_VERSION);
this.enabledServices.push(infoService);
}
}
setStatus(newStatus) {
}
setupServices() {
// link the accessory to your platform
this.api.publishExternalAccessories(constants_1.PLUGIN_NAME, [this.accessory]);
// Refresh the accessory cache with these values.
this.api.updatePlatformAccessories([this.accessory]);
}
}
exports.ZoneAccessory = ZoneAccessory;
_ZoneAccessory_buttons = new WeakMap();
//# sourceMappingURL=zoneAccessory.js.map