homebridge-connect-my-pool
Version:
Partially complete HomeKit integration for Astral Viron Gateway
145 lines • 8.63 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PoolSpaAccessory = void 0;
const zoneAccessory_1 = require("./zoneAccessory");
class PoolSpaAccessory extends zoneAccessory_1.ZoneAccessory {
constructor(platform, controller, zone) {
super(platform, controller, zone);
//this.setUpServices();
//accessory.updateReachability(true);
}
setStatus(newStatus) {
var _a;
super.setStatus(newStatus);
if (newStatus && !(newStatus.zoneType === "pool_and_spa" /* POOL_AND_SPA */))
(_a = this.log) === null || _a === void 0 ? void 0 : _a.error('setStatus Pool Spa', newStatus.zoneType, typeof newStatus);
if (newStatus) {
if (!this.currentStatus)
this.currentStatus = newStatus;
else
this.previousStatus = this.currentStatus;
this.poolFilterSensorService.getCharacteristic(this.Characteristic.StatusActive)
.updateValue(this.getIsPoolFilterRunning(newStatus));
this.poolFilterSensorService.getCharacteristic(this.Characteristic.ContactSensorState)
.updateValue(this.getPoolFilterContactSensorState(newStatus));
this.spaJetsSensorService.getCharacteristic(this.Characteristic.StatusActive)
.updateValue(this.getIsSpaJetsRunning(newStatus));
this.spaJetsSensorService.getCharacteristic(this.Characteristic.ContactSensorState)
.updateValue(this.getSpaJetsContactSensorState(newStatus));
this.spaBlowerSensorService.getCharacteristic(this.Characteristic.StatusActive)
.updateValue(this.getIsSpaBlowerRunning(newStatus));
this.spaBlowerSensorService.getCharacteristic(this.Characteristic.ContactSensorState)
.updateValue(this.getSpaBlowerContactSensorState(newStatus));
this.currentStatus = newStatus;
}
}
/// /////////////////////
// UPDATE CHARACTERISTICS FROM ZONE
/// /////////////////////
/// /////////////////////
// GET AND SET FUNCTIONS
/// /////////////////////
/**
* Handle requests to get the current value of the "Is Active" characteristic
*/
getIsPoolFilterRunning(newStatus) {
var _a;
var status = newStatus !== null && newStatus !== void 0 ? newStatus : this.previousStatus;
// set this to a valid value for CurrentTemperature
var value = (_a = status === null || status === void 0 ? void 0 : status.isPoolFilterRunning) !== null && _a !== void 0 ? _a : false;
this.debug('Get Is Pool Filter Running:', value);
return value;
}
getPoolFilterContactSensorState(newStatus) {
var _a;
var status = newStatus !== null && newStatus !== void 0 ? newStatus : this.previousStatus;
// set this to a valid value for CurrentTemperature
var value = ((_a = status === null || status === void 0 ? void 0 : status.isPoolFilterRunning) !== null && _a !== void 0 ? _a : false) ? this.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : this.Characteristic.ContactSensorState.CONTACT_DETECTED;
this.debug('Get Pool Filter Contact Sensor State:', value);
return value;
}
getIsSpaJetsRunning(newStatus) {
var _a;
var status = newStatus !== null && newStatus !== void 0 ? newStatus : this.previousStatus;
// set this to a valid value for CurrentTemperature
var value = (_a = status === null || status === void 0 ? void 0 : status.isSpaJetsRunning) !== null && _a !== void 0 ? _a : false;
this.debug('Get Is Spa Jets Running:', value);
return value;
}
getSpaJetsContactSensorState(newStatus) {
var _a;
var status = newStatus !== null && newStatus !== void 0 ? newStatus : this.previousStatus;
// set this to a valid value for CurrentTemperature
var value = ((_a = status === null || status === void 0 ? void 0 : status.isSpaJetsRunning) !== null && _a !== void 0 ? _a : false) ? this.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : this.Characteristic.ContactSensorState.CONTACT_DETECTED;
this.debug('Get Spa Jets Contact Sensor State:', value);
return value;
}
getIsSpaBlowerRunning(newStatus) {
var _a;
var status = newStatus !== null && newStatus !== void 0 ? newStatus : this.previousStatus;
// set this to a valid value for CurrentTemperature
var value = (_a = status === null || status === void 0 ? void 0 : status.isSpaBlowerRunning) !== null && _a !== void 0 ? _a : false;
this.debug('Get Is Spa Blower Running:', value);
return value;
}
getSpaBlowerContactSensorState(newStatus) {
var _a;
var status = newStatus !== null && newStatus !== void 0 ? newStatus : this.previousStatus;
// set this to a valid value for CurrentTemperature
var value = ((_a = status === null || status === void 0 ? void 0 : status.isSpaBlowerRunning) !== null && _a !== void 0 ? _a : false) ? this.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : this.Characteristic.ContactSensorState.CONTACT_DETECTED;
this.debug('Get Spa Blower Contact Sensor State:', value);
return value;
}
////////////////////////
// ZONE SERVICE FUNCTIONS
////////////////////////
setupServices() {
this.debug('setupServices', 'poolSpaAccessory');
this.poolFilterSensorService = this.createPoolFilterSensorService();
this.zoneService.setPrimaryService(true);
this.spaJetsSensorService = this.createSpaJetsSensorService();
this.spaBlowerSensorService = this.createSpaBlowerSensorService();
super.setupServices();
}
// Configure the contact sensor on the Heater.
createPoolFilterSensorService() {
// Clear out any previous contact sensor service.
const poolFilterSensorService = this.accessory.getServiceById(this.Service.ContactSensor, 'poolfilter') || this.accessory.addService(this.Service.ContactSensor, this.zone.name + " Running", 'poolfilter');
poolFilterSensorService.getCharacteristic(this.Characteristic.StatusActive)
.setValue(this.getIsPoolFilterRunning())
.onGet(this.getIsPoolFilterRunning.bind(this));
poolFilterSensorService.getCharacteristic(this.Characteristic.ContactSensorState)
.setValue(this.getPoolFilterContactSensorState())
.onGet(this.getPoolFilterContactSensorState.bind(this));
this.enabledServices.push(poolFilterSensorService);
return poolFilterSensorService;
}
// Configure the contact sensor on the Heater.
createSpaJetsSensorService() {
// Clear out any previous contact sensor service.
const spaJetsSensorService = this.accessory.getServiceById(this.Service.ContactSensor, 'spajets') || this.accessory.addService(this.Service.ContactSensor, this.zone.name + " Spa Jets Running", 'spajets');
spaJetsSensorService.getCharacteristic(this.Characteristic.StatusActive)
.setValue(this.getIsSpaJetsRunning())
.onGet(this.getIsSpaJetsRunning.bind(this));
spaJetsSensorService.getCharacteristic(this.Characteristic.ContactSensorState)
.setValue(this.getSpaJetsContactSensorState())
.onGet(this.getSpaJetsContactSensorState.bind(this));
this.enabledServices.push(spaJetsSensorService);
return spaJetsSensorService;
}
// Configure the contact sensor on the Heater.
createSpaBlowerSensorService() {
// Clear out any previous contact sensor service.
const spaBlowerSensorService = this.accessory.getServiceById(this.Service.ContactSensor, 'spablower') || this.accessory.addService(this.Service.ContactSensor, this.zone.name + " Spa Jets Running", 'spablower');
spaBlowerSensorService.getCharacteristic(this.Characteristic.StatusActive)
.setValue(this.getIsSpaBlowerRunning())
.onGet(this.getIsSpaBlowerRunning.bind(this));
spaBlowerSensorService.getCharacteristic(this.Characteristic.ContactSensorState)
.setValue(this.getSpaBlowerContactSensorState())
.onGet(this.getSpaBlowerContactSensorState.bind(this));
this.enabledServices.push(spaBlowerSensorService);
return spaBlowerSensorService;
}
}
exports.PoolSpaAccessory = PoolSpaAccessory;
//# sourceMappingURL=poolSpaAccessory.js.map