UNPKG

homebridge-hivehome-control

Version:

Allows control of Hive devices, including water heaters, through Homebridge.

65 lines 3.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HiveHeatingAccessory = void 0; const log_1 = require("../../util/log"); const hive_api_1 = require("../hive-api"); const hiveAccessory_1 = require("./hiveAccessory"); /** * An instance of this class is created for each Heating accessory. Exposes the * Boost service for the Heating device. */ class HiveHeatingAccessory extends hiveAccessory_1.HiveAccessory { constructor(platform, accessory, hiveSession) { // Initialize the base class first, then initialize the services. super(platform, accessory, hiveSession); this.platform = platform; this.accessory = accessory; this.hiveSession = hiveSession; this.kBoostName = 'Boost'; // Convenience references to Characteristic and Service. const Characteristic = this.platform.Characteristic; const Service = this.platform.Service; // // Create a switch for the Boost service offered by this heating device. // const boostConName = `${this.accessory.displayName} ${this.kBoostName}`; this.boostService = this.accessory.getService(this.kBoostName) || this.addService(Service.Switch, this.kBoostName, this.kBoostName, boostConName); // // Register handlers for all dynamic characteristics. // this.boostService.getCharacteristic(Characteristic.On) .onGet(() => this.currentState[this.kBoostName] === hive_api_1.HeatingMode.kOn) .onSet((active) => this.setDeviceState(this.kBoostName, active ? hive_api_1.HeatingMode.kOn : hive_api_1.HeatingMode.kOff)); } // Return true if services have been initialized. servicesReady() { return !!this.boostService; } // Get the device power state and push to Homekit when it changes. async updateDeviceAndCurrentState() { // Retrieve the newly-updated device data... this.hiveDevice = await this.hiveSession.heating.getClimate(this.hiveDevice); // ... and use it to populate the current state. this.currentState[this.kBoostName] = await this.hiveSession.heating.getBoostStatus(this.hiveDevice); } // Push the current state to Homekit. async updateHomekitState() { this.boostService.updateCharacteristic(this.platform.Characteristic.On, this.currentState[this.kBoostName] === hive_api_1.HeatingMode.kOn); } async setDeviceState(serviceName, newState) { if (newState === hive_api_1.HeatingMode.kOn) { await this.hiveSession.heating.setBoostOn(this.hiveDevice, this.config.heatingBoostMins, this.config.heatingBoostTemp); log_1.Log.info(`Enabled ${this.accessory.displayName} Boost to ${this.config.heatingBoostTemp} degrees for ${this.config.heatingBoostMins} minutes`); } else { await this.hiveSession.heating.setBoostOff(this.hiveDevice); log_1.Log.info(`Turned off ${this.accessory.displayName} Boost`); } this.currentState[serviceName] = newState; } } exports.HiveHeatingAccessory = HiveHeatingAccessory; //# sourceMappingURL=hiveHeatingAccessory.js.map