homebridge-vwconnectid
Version:
Homebridge plugin for Volkswagen ID.x cars
52 lines • 2.41 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RouteSwitchAccessory = void 0;
class RouteSwitchAccessory {
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.route.name);
this.service.getCharacteristic(this.platform.Characteristic.On)
.onGet(this.getOn.bind(this))
.onSet(this.setOn.bind(this));
}
async getOn() {
return false;
}
async setOn(value) {
try {
if (value) {
let destination = {};
let destinations = new Array();
for (const dest of this.accessory.context.route.stopovers) {
const stopover = {
poiProvider: 'unknown',
destinationType: 'stopover',
destinationName: dest.name,
address: dest.address,
geoCoordinate: { longitude: dest.lon, latitude: dest.lat }
};
destinations.push(stopover);
}
;
destination['destinations'] = destinations;
console.log(JSON.stringify(destination));
this.platform.vwConn.setDestination(destination);
setTimeout(() => {
this.accessory.getService(this.platform.Service.Switch).getCharacteristic(this.platform.Characteristic.On).updateValue(false);
}, 500);
}
}
catch (err) {
console.log(err);
}
}
}
exports.RouteSwitchAccessory = RouteSwitchAccessory;
//# sourceMappingURL=routeSwitchAccessory.js.map