UNPKG

homebridge-vwconnectid

Version:
88 lines 6.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SettingAccessory = void 0; class SettingAccessory { constructor(platform, accessory) { this.platform = platform; this.accessory = accessory; this.accessory.getService(this.platform.Service.AccessoryInformation) .setCharacteristic(this.platform.Characteristic.Manufacturer, 'Volkswagen') .setCharacteristic(this.platform.Characteristic.Model, this.platform.vwConn.vehicles.data.find(({ vin }) => vin === this.platform.config.weconnect.vin).model) .setCharacteristic(this.platform.Characteristic.SerialNumber, this.platform.config.weconnect.vin); this.service = this.accessory.getService(this.platform.Service.Switch) || this.accessory.addService(this.platform.Service.Switch); this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name); this.service.getCharacteristic(this.platform.Characteristic.On) .onSet(this.setOn.bind(this)) .onGet(this.getOn.bind(this)); switch (this.accessory.context.device.setting) { case 'climatizationAtUnlock': this.platform.idStatusEmitter.on('climatisationAtUnlockUpdated', () => { this.service.updateCharacteristic(this.platform.Characteristic.On, this.platform.vwConn.idData.climatisation.climatisationSettings.value.climatizationAtUnlock); }); break; case 'climatisationWindowHeating': this.platform.idStatusEmitter.on('windowHeatingUpdated', () => { this.service.updateCharacteristic(this.platform.Characteristic.On, this.platform.vwConn.idData.climatisation.climatisationSettings.value.windowHeatingEnabled); }); break; case 'climatisationFrontLeft': this.platform.idStatusEmitter.on('zoneFrontLeftUpdated', () => { this.service.updateCharacteristic(this.platform.Characteristic.On, this.platform.vwConn.idData.climatisation.climatisationSettings.value.zoneFrontLeftEnabled); }); break; case 'climatisationFrontRight': this.platform.idStatusEmitter.on('zoneFrontRightUpdated', () => { this.service.updateCharacteristic(this.platform.Characteristic.On, this.platform.vwConn.idData.climatisation.climatisationSettings.value.zoneFrontRightEnabled); }); break; case 'reducedAC': this.platform.idStatusEmitter.on('reducedACupdated', () => { this.service.updateCharacteristic(this.platform.Characteristic.On, this.platform.vwConn.idData.charging.chargingSettings.value.maxChargeCurrentAC === 'reduced'); }); break; case 'autoUnlockPlug': this.platform.idStatusEmitter.on('autoUnlockPlugUpdated', () => { this.service.updateCharacteristic(this.platform.Characteristic.On, this.platform.vwConn.idData.charging.chargingSettings.value.autoUnlockPlugWhenCharged === 'permanent'); }); break; default: break; } } async setOn(value) { const val = value; switch (this.accessory.context.device.setting) { case "reducedAC": this.platform.vwConn.setChargingSetting("chargeCurrent", val ? "reduced" : "maximum"); break; case "autoUnlockPlug": this.platform.vwConn.setChargingSetting("autoUnlockPlug", val); break; default: this.platform.vwConn.setClimatisationSetting(this.accessory.context.device.setting, val); break; } this.platform.log.info('Set Characteristic On ->', value); } async getOn() { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; switch (this.accessory.context.device.setting) { case "reducedAC": return (typeof ((_c = (_b = (_a = this.platform.vwConn.idData.charging) === null || _a === void 0 ? void 0 : _a.chargingSettings) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.maxChargeCurrentAC) !== 'undefined') ? this.platform.vwConn.idData.charging.chargingSettings.value.maxChargeCurrentAC === 'reduced' : false; case "autoUnlockPlug": return (typeof ((_f = (_e = (_d = this.platform.vwConn.idData.charging) === null || _d === void 0 ? void 0 : _d.chargingSettings) === null || _e === void 0 ? void 0 : _e.value) === null || _f === void 0 ? void 0 : _f.autoUnlockPlugWhenCharged) !== 'undefined') ? this.platform.vwConn.idData.charging.chargingSettings.value.autoUnlockPlugWhenCharged === 'permanent' : false; case "climatizationAtUnlock": return (typeof ((_j = (_h = (_g = this.platform.vwConn.idData.climatisation) === null || _g === void 0 ? void 0 : _g.climatisationSettings) === null || _h === void 0 ? void 0 : _h.value) === null || _j === void 0 ? void 0 : _j.climatizationAtUnlock) !== 'undefined') ? this.platform.vwConn.idData.climatisation.climatisationSettings.value.climatizationAtUnlock : false; case "climatisationWindowHeating": return (typeof ((_m = (_l = (_k = this.platform.vwConn.idData.climatisation) === null || _k === void 0 ? void 0 : _k.climatisationSettings) === null || _l === void 0 ? void 0 : _l.value) === null || _m === void 0 ? void 0 : _m.windowHeatingEnabled) !== 'undefined') ? this.platform.vwConn.idData.climatisation.climatisationSettings.value.windowHeatingEnabled : false; case "climatisationFrontLeft": return (typeof ((_q = (_p = (_o = this.platform.vwConn.idData.climatisation) === null || _o === void 0 ? void 0 : _o.climatisationSettings) === null || _p === void 0 ? void 0 : _p.value) === null || _q === void 0 ? void 0 : _q.zoneFrontLeftEnabled) !== 'undefined') ? this.platform.vwConn.idData.climatisation.climatisationSettings.value.zoneFrontLeftEnabled : false; case "climatisationFrontRight": return (typeof ((_t = (_s = (_r = this.platform.vwConn.idData.climatisation) === null || _r === void 0 ? void 0 : _r.climatisationSettings) === null || _s === void 0 ? void 0 : _s.value) === null || _t === void 0 ? void 0 : _t.zoneFrontRightEnabled) !== 'undefined') ? this.platform.vwConn.idData.climatisation.climatisationSettings.value.zoneFrontRightEnabled : false; default: return false; } } } exports.SettingAccessory = SettingAccessory; //# sourceMappingURL=settingsAccessory.js.map