UNPKG

homebridge-daikin-oneplus

Version:
55 lines 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DaikinOnePlusScheduleSwitch = void 0; /** * Platform 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 DaikinOnePlusScheduleSwitch { constructor(platform, accessory, deviceId, daikinApi) { this.platform = platform; this.accessory = accessory; this.deviceId = deviceId; this.daikinApi = daikinApi; // set accessory information this.accessory.getService(this.platform.Service.AccessoryInformation) .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Daikin') .setCharacteristic(this.platform.Characteristic.Model, accessory.context.device.model) .setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.context.device.id) .setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.device.firmwareVersion); // you can create multiple services for each accessory this.service = this.accessory.getService(this.platform.Service.Switch) || this.accessory.addService(this.platform.Service.Switch); // set the service name, this is what is displayed as the default name on the Home app this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName); this.service.getCharacteristic(this.platform.Characteristic.On) .onGet(() => { this.daikinApi.updateNow(); return this.handleCurrentStateGet(); }) .onSet(this.handleCurrentStateSet.bind(this)); this.updateValues(); this.daikinApi.addListener(this.updateValues.bind(this)); } updateValues() { const value = this.handleCurrentStateGet(); this.service.updateCharacteristic(this.platform.Characteristic.On, value); } /** * Handle requests to get the current value of the "On" characteristic */ handleCurrentStateGet() { return this.daikinApi.deviceHasData(this.deviceId) && this.daikinApi.getScheduleState(this.deviceId); } /** * Handle requests to set the "On" characteristic */ async handleCurrentStateSet(value) { this.platform.log.debug('%s - Set Schedule State: %s', this.accessory.displayName, value); await this.daikinApi.setScheduleState(this.deviceId, Boolean(value)); } } exports.DaikinOnePlusScheduleSwitch = DaikinOnePlusScheduleSwitch; //# sourceMappingURL=platformScheduleSwitch.js.map