UNPKG

homebridge-sleeptracker

Version:

Homebridge plugin for SleepTracker smart beds - Control your bed's position and features through HomeKit

85 lines 3.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SleepTrackerDevice = void 0; class SleepTrackerDevice { constructor(platform, accessory) { this.platform = platform; this.accessory = accessory; // Basic bed service (using Switch service as base) this.service = this.accessory.getService(this.platform.Service.Switch) || this.accessory.addService(this.platform.Service.Switch); // Set up characteristics this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name); // Add position characteristic (0-100%) this.service.addCharacteristic(this.platform.Characteristic.RotationSpeed) .onSet(this.setPosition.bind(this)) .onGet(this.getPosition.bind(this)); // Add environmental sensors if enabled if (this.platform.config.enableEnvironmentSensors) { this.setupEnvironmentSensors(); } // Start the update interval this.startUpdateInterval(); } setupEnvironmentSensors() { // Temperature Sensor this.temperatureService = this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor); // Humidity Sensor this.humidityService = this.accessory.getService(this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor); } startUpdateInterval() { const interval = (this.platform.config.refreshInterval || 30) * 1000; // Convert to milliseconds setInterval(() => { this.updateSensorValues(); }, interval); } async setPosition(value) { try { // Implement the bed position control logic here this.platform.log.debug('Setting bed position to:', value); // Add your implementation here } catch (error) { this.platform.log.error('Error setting position:', error); } } async getPosition() { try { // Implement the bed position reading logic here return 0; // Placeholder return } catch (error) { this.platform.log.error('Error getting position:', error); throw new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */); } } async updateSensorValues() { try { if (this.temperatureService) { // Implement temperature reading logic const temperature = await this.getTemperature(); this.temperatureService.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, temperature); } if (this.humidityService) { // Implement humidity reading logic const humidity = await this.getHumidity(); this.humidityService.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, humidity); } } catch (error) { this.platform.log.error('Error updating sensor values:', error); } } async getTemperature() { // Implement your temperature reading logic here return 20; // Placeholder return } async getHumidity() { // Implement your humidity reading logic here return 50; // Placeholder return } } exports.SleepTrackerDevice = SleepTrackerDevice; //# sourceMappingURL=sleepTrackerDevice.js.map