homebridge-connect-my-pool
Version:
Partially complete HomeKit integration for Astral Viron Gateway
181 lines • 9.43 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HeaterAccessory = void 0;
const zoneAccessory_1 = require("./zoneAccessory");
class HeaterAccessory extends zoneAccessory_1.ZoneAccessory {
constructor(platform, controller, zone) {
super(platform, controller, zone);
//accessory.updateReachability(true);
}
////////////////////////
// UPDATE CHARACTERISTICS FROM ZONE
////////////////////////
/// /////////////////////
// GET AND SET FUNCTIONS
/// /////////////////////
getCurrentHeatingCoolingState(newStatus) {
var status = newStatus !== null && newStatus !== void 0 ? newStatus : this.previousStatus;
// set this to a valid value for CurrentHeatingCoolingState
var value = this.getHeatingCoolingCharacteristic(status === null || status === void 0 ? void 0 : status.status, status === null || status === void 0 ? void 0 : status.isRunning);
this.debug('Get CurrentHeatingCoolingState:', value);
return value;
}
/**
* Handle requests to get the current value of the "Target Heating Cooling State" characteristic
*/
getTargetHeatingCoolingState(newStatus) {
var status = newStatus !== null && newStatus !== void 0 ? newStatus : this.previousStatus;
// set this to a valid value for TargetHeatingCoolingState
var value = this.getHeatingCoolingCharacteristic(status === null || status === void 0 ? void 0 : status.status, status === null || status === void 0 ? void 0 : status.isRunning);
this.debug('Get TargetHeatingCoolingState:', value);
return value;
}
/**
* Handle requests to set the "Target Heating Cooling State" characteristic
*/
setTargetHeatingCoolingState(value) {
this.debug('Set TargetHeatingCoolingState:', value);
}
/**
* Handle requests to get the current value of the "Current Temperature" characteristic
*/
getCurrentTemperature(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.currentTemp) !== null && _a !== void 0 ? _a : 0;
this.debug('Get CurrentTemperature:', value);
return value;
}
/**
* Handle requests to get the current value of the "Is Active" characteristic
*/
getIsRunning(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.isRunning) !== null && _a !== void 0 ? _a : false;
this.debug('Get Is Running:', value);
return value;
}
getContactSensorState(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.isRunning) !== null && _a !== void 0 ? _a : false) ? this.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED : this.Characteristic.ContactSensorState.CONTACT_DETECTED;
this.debug('Get Is Contact Sensor State:', value);
return value;
}
/**
* Handle requests to get the current value of the "Target Temperature" characteristic
*/
getTargetTemperature(newStatus) {
var _a;
var status = newStatus !== null && newStatus !== void 0 ? newStatus : this.previousStatus;
// set this to a valid value for TargetTemperature
var value = (_a = status === null || status === void 0 ? void 0 : status.targetTemp) !== null && _a !== void 0 ? _a : 10;
this.debug('Get TargetTemperature:', value);
return value;
}
/**
* Handle requests to set the "Target Temperature" characteristic
*/
setTargetTemperature(value) {
this.debug('Set TargetTemperature:', value);
}
// /**
// * Handle requests to get the current value of the "Temperature Display Units" characteristic
// */
getTemperatureDisplayUnits() {
this.debug('Get TemperatureDisplayUnits');
return this.Characteristic.TemperatureDisplayUnits.CELSIUS;
}
setStatus(newStatus) {
var _a;
super.setStatus(newStatus);
if (newStatus && (!(newStatus.zoneType === "heating" /* HEATING */ || newStatus.zoneType === "solar" /* SOLAR */)))
(_a = this.log) === null || _a === void 0 ? void 0 : _a.error('setStatus Heater', newStatus.zoneType, typeof newStatus);
if (newStatus) {
if (!this.currentStatus)
this.currentStatus = newStatus;
else
this.previousStatus = this.currentStatus;
this.heaterSensorService.getCharacteristic(this.Characteristic.StatusActive)
.updateValue(this.getIsRunning(newStatus));
this.heaterSensorService.getCharacteristic(this.Characteristic.ContactSensorState)
.updateValue(this.getContactSensorState(newStatus));
this.zoneService.getCharacteristic(this.Characteristic.CurrentHeatingCoolingState)
.updateValue(this.getCurrentHeatingCoolingState(newStatus));
this.zoneService.getCharacteristic(this.Characteristic.TargetHeatingCoolingState)
.updateValue(this.getTargetHeatingCoolingState(newStatus));
this.zoneService.getCharacteristic(this.Characteristic.CurrentTemperature)
.updateValue(this.getCurrentTemperature(newStatus));
this.zoneService.getCharacteristic(this.Characteristic.TargetTemperature)
.updateValue(this.getTargetTemperature(newStatus));
this.currentStatus = newStatus;
}
}
////////////////////////
// ZONE SERVICE FUNCTIONS
////////////////////////
setupServices() {
this.debug('setupServices', 'heaterAccessory');
this.zoneService = this.createZoneService();
this.zoneService.setPrimaryService(true);
this.heaterSensorService = this.createHeaterSensor();
super.setupServices();
}
getHeatingCoolingCharacteristic(value, isRunning) {
if (value === "ON" /* ON */ || (value === "AUTO" /* AUTO */ && (isRunning !== null && isRunning !== void 0 ? isRunning : false)))
return this.Characteristic.CurrentHeatingCoolingState.HEAT;
else
return this.Characteristic.CurrentHeatingCoolingState.OFF;
}
createZoneService() {
this.debug('Creating %s service for controller', this.name);
const zoneService = this.accessory.getServiceById(this.Service.Thermostat, this.zone.type) || this.accessory.addService(this.Service.Thermostat, this.name, this.zone.type);
//zoneService.setCharacteristic(this.Characteristic.ConfiguredName, this.name)
zoneService.getCharacteristic(this.Characteristic.CurrentHeatingCoolingState)
.setProps({
maxValue: this.Characteristic.CurrentHeatingCoolingState.HEAT
})
.onGet(this.getCurrentHeatingCoolingState.bind(this));
zoneService.getCharacteristic(this.Characteristic.TargetHeatingCoolingState)
.setProps({
maxValue: this.Characteristic.TargetHeatingCoolingState.HEAT
})
.onGet(this.getTargetHeatingCoolingState.bind(this))
.onSet(this.setTargetHeatingCoolingState.bind(this));
zoneService.getCharacteristic(this.Characteristic.CurrentTemperature)
.setProps({
maxValue: 50,
minStep: 1
})
.onGet(this.getCurrentTemperature.bind(this));
zoneService.getCharacteristic(this.Characteristic.TargetTemperature)
.setProps({
maxValue: 40,
minStep: 1
})
.onGet(this.getTargetTemperature.bind(this))
.onSet(this.setTargetTemperature.bind(this));
zoneService.getCharacteristic(this.Characteristic.TemperatureDisplayUnits)
.setValue(this.Characteristic.TemperatureDisplayUnits.CELSIUS);
this.enabledServices.push(zoneService);
return zoneService;
}
// Configure the contact sensor on the Heater.
createHeaterSensor() {
const heaterSensorService = this.accessory.getServiceById(this.Service.ContactSensor, 'heatersensor') || this.accessory.addService(this.Service.ContactSensor, this.zone.name + " Running", 'heatersensor');
heaterSensorService.getCharacteristic(this.Characteristic.StatusActive)
.setValue(this.getIsRunning())
.onGet(this.getIsRunning.bind(this));
heaterSensorService.getCharacteristic(this.Characteristic.ContactSensorState)
.setValue(this.getContactSensorState())
.onGet(this.getContactSensorState.bind(this));
this.enabledServices.push(heaterSensorService);
return heaterSensorService;
}
}
exports.HeaterAccessory = HeaterAccessory;
//# sourceMappingURL=heaterAccessory.js.map