homebridge-connect-my-pool-home-automation
Version:
HomeKit integration for Astral Viron Gateway via Home Automation
89 lines • 4.11 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LightingAccessory = void 0;
const action_1 = require("../action");
const status_1 = require("../status");
const accessory_1 = require("./accessory");
const settings_1 = require("../settings");
/**
* Channel Accessory
* An instance of this class is created for each accessory your platform registers
* Each accessory may expose multiple services of different service types.
*/
class LightingAccessory extends accessory_1.Accessory {
constructor(platform, accessory, device, status) {
super(platform, accessory, device, status);
this.lightingZoneConfigStatus = this.getLightingZoneConfigStatus(status);
}
setUpServices() {
super.setUpServices();
this.createLightingService();
this.services[0].setPrimaryService(true);
super.updatePlatform();
}
createLightingService() {
this.log.debug('Creating %s service for controller', this.deviceName);
const zoneService = this.accessory.getServiceById(this.service.Lightbulb, this.deviceType)
|| this.accessory.addService(this.service.Lightbulb, this.deviceName, this.deviceType);
zoneService.getCharacteristic(this.Characteristic.On)
.onGet(this.getOnState.bind(this))
.onSet(this.setOnState.bind(this));
this.services.push(zoneService);
return zoneService;
}
/// /////////////////////
// GET AND SET CONFIG STATUS
/// /////////////////////
getLightingZoneConfigStatus(status) {
const currentstatus = status;
const currentdevice = this.device;
const currentConfig = currentdevice.data;
if (currentstatus) {
const lightStatus = currentstatus.lighting_zones.find(l => l.lighting_zone_number === currentConfig.lighting_zone_number);
const lightConfigStatus = Object.assign({}, new status_1.LightingZoneStatus(currentConfig.lighting_zone_number, true), currentConfig, lightStatus);
this.debugLog('lightConfigStatus', lightConfigStatus);
return lightConfigStatus;
}
else {
const lightConfigStatus = Object.assign({}, currentConfig, new status_1.LightingZoneStatus(currentConfig.lighting_zone_number));
this.debugLog('lightConfigStatus', lightConfigStatus);
return lightConfigStatus;
}
}
setConfigStatus(status) {
this.lightingZoneConfigStatus = this.getLightingZoneConfigStatus(status);
}
async updateStatus(status) {
await super.updateStatus(status);
this.services[0].getCharacteristic(this.Characteristic.On)
.updateValue(this.getOnState());
const lightingZoneConfigStatus = this.lightingZoneConfigStatus;
if (lightingZoneConfigStatus.hasStatus) {
if (lightingZoneConfigStatus.color_enabled === true && lightingZoneConfigStatus.color) {
this.services[0].getCharacteristic(this.Characteristic.Hue).updateValue(lightingZoneConfigStatus.color);
}
}
}
/// /////////////////////
// GET AND SET FUNCTIONS
/// /////////////////////
getOnState() {
const lightingZoneConfigStatus = this.lightingZoneConfigStatus;
const value = lightingZoneConfigStatus.mode === settings_1.LightingMode.OFF ? false : true;
this.debugLog('getOnState', value);
this.stateOn = value;
return this.stateOn;
}
setOnState(value) {
this.debugLog('setOnState', value);
if (this.stateOn === value) {
return;
}
this.stateOn = value;
this.platform.setPoolAction(action_1.PoolAction.SetLightingZoneMode, this.device.deviceTypeNumber, String(value === false ? settings_1.LightingMode.OFF : settings_1.LightingMode.ON)).then((res) => {
this.debugLog('setOnState Result', res);
});
}
}
exports.LightingAccessory = LightingAccessory;
//# sourceMappingURL=lightingAccessory.js.map