Skip to content

Commit

Permalink
fix: duplicate serial numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-seinhorst committed Mar 24, 2024
1 parent 185d56d commit f579053
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "homebridge-porsche-taycan",
"displayName": "Porsche EV",
"version": "1.21.0",
"version": "1.21.1",
"description": "Homekit support for your Porsche EV (Taycan and Macan), enable direct charge, start precool/heat, power consumption insights and more!",
"license": "Apache-2.0",
"author": "Jasper Seinhorst",
Expand Down
2 changes: 1 addition & 1 deletion src/Accessories/Battery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Battery implements PorscheAccessory {
this.accessory.getService(this.Service.AccessoryInformation)!
.setCharacteristic(this.Characteristic.Manufacturer, 'Porsche')
.setCharacteristic(this.Characteristic.Model, this.accessory.context.device.modelDescription)
.setCharacteristic(this.Characteristic.SerialNumber, this.accessory.context.device.vin);
.setCharacteristic(this.Characteristic.SerialNumber, `${this.accessory.context.device.vin}-battery`);

this.batteryDevice = this.accessory.getService(this.Service.HumiditySensor) || this.accessory.addService(this.Service.HumiditySensor);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Accessories/Charger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class Charger implements PorscheAccessory {
this.accessory.getService(this.Service.AccessoryInformation)!
.setCharacteristic(this.Characteristic.Manufacturer, 'Porsche')
.setCharacteristic(this.Characteristic.Model, this.accessory.context.device.modelDescription)
.setCharacteristic(this.Characteristic.SerialNumber, this.accessory.context.device.vin);
.setCharacteristic(this.Characteristic.SerialNumber, `${this.accessory.context.device.vin}-charger`);

this.lowBatteryLevel = this.config.lowBattery || 35;
this.chargerService = this.accessory.getService(this.Service.ContactSensor) || this.accessory.addService(this.Service.ContactSensor);
Expand Down
2 changes: 1 addition & 1 deletion src/Accessories/ChargingPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class ChargingPower implements PorscheAccessory {
this.accessory.getService(this.Service.AccessoryInformation)!
.setCharacteristic(this.Characteristic.Manufacturer, 'Porsche')
.setCharacteristic(this.Characteristic.Model, this.accessory.context.device.modelDescription)
.setCharacteristic(this.Characteristic.SerialNumber, this.accessory.context.device.vin);
.setCharacteristic(this.Characteristic.SerialNumber, `${this.accessory.context.device.vin}-charging-power`);

this.chargingPower = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Accessories/DirectCharge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class DirectCharge implements PorscheAccessory {
this.accessory.getService(this.Service.AccessoryInformation)!
.setCharacteristic(this.Characteristic.Manufacturer, 'Porsche')
.setCharacteristic(this.Characteristic.Model, this.accessory.context.device.modelDescription)
.setCharacteristic(this.Characteristic.SerialNumber, this.accessory.context.device.vin);
.setCharacteristic(this.Characteristic.SerialNumber, `${this.accessory.context.device.vin}-direct-charge`);

this.switchService = this.accessory.getService(this.Service.Switch) || this.accessory.addService(this.Service.Switch);
this.switchService.getCharacteristic(this.Characteristic.On).on('set', this.setStatus.bind(this));
Expand Down
2 changes: 1 addition & 1 deletion src/Accessories/Occupancy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Charger implements PorscheAccessory {
this.accessory.getService(this.Service.AccessoryInformation)!
.setCharacteristic(this.Characteristic.Manufacturer, 'Porsche')
.setCharacteristic(this.Characteristic.Model, this.accessory.context.device.modelDescription)
.setCharacteristic(this.Characteristic.SerialNumber, this.accessory.context.device.vin);
.setCharacteristic(this.Characteristic.SerialNumber, `${this.accessory.context.device.vin}-occupancy`);

this.occupancyService = this.accessory.getService(this.Service.OccupancySensor) || this.accessory.addService(this.Service.OccupancySensor);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Accessories/PrecoolHeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class PrecoolHeat implements PorscheAccessory {
this.accessory.getService(this.Service.AccessoryInformation)!
.setCharacteristic(this.Characteristic.Manufacturer, 'Porsche')
.setCharacteristic(this.Characteristic.Model, this.accessory.context.device.modelDescription)
.setCharacteristic(this.Characteristic.SerialNumber, this.accessory.context.device.vin);
.setCharacteristic(this.Characteristic.SerialNumber, `${this.accessory.context.device.vin}-precool-heat`);

this.switchService = this.accessory.getService(this.Service.Switch) || this.accessory.addService(this.Service.Switch);
this.switchService.getCharacteristic(this.Characteristic.On).on('set', this.setStatus.bind(this));
Expand Down
40 changes: 21 additions & 19 deletions src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,76 +65,77 @@ export class PorscheTaycanPlatform implements DynamicPlatformPlugin {
const platformVehicle: PlatformVehicle = { vehicle, accessories: [] };

// Register Charger
const chargerName = 'Charger';
const chargerUuid = this.api.hap.uuid.generate(`${vehicle.vin}-charger`);
const chargerExistingAccessory = this.accessories.find(accessory => accessory.UUID === chargerUuid);

if (chargerExistingAccessory) {
platformVehicle.accessories.push(new Charger(this.config, this.log, this.api, chargerExistingAccessory));
} else {
this.log.info('Charger added as accessory');
const accessory = new this.api.platformAccessory('Charger', chargerUuid);
this.log.info(`${chargerName} added as accessory`);
const accessory = new this.api.platformAccessory(chargerName, chargerUuid);
accessory.context.device = vehicle;
platformVehicle.accessories.push(new Charger(this.config, this.log, this.api, accessory));
this.api.registerPlatformAccessories('homebridge-porsche-taycan', 'PorscheTaycan', [accessory]);
}

// Register Precool / heat
const precoolHeatName = 'Precool/heat';
const precoolHeatUuid = this.api.hap.uuid.generate(`${vehicle.vin}-precool-heat`);
const precoolHeatExistingAccessory = this.accessories.find(accessory => accessory.UUID === precoolHeatUuid);

if (precoolHeatExistingAccessory) {
platformVehicle.accessories.push(new PrecoolHeat(this.config, this.log, this.api, precoolHeatExistingAccessory));
} else {
this.log.info('Precool/heat added as accessory');
const accessory = new this.api.platformAccessory('Precool/heat', precoolHeatUuid);
this.log.info(`${precoolHeatName} added as accessory`);
const accessory = new this.api.platformAccessory(precoolHeatName, precoolHeatUuid);
accessory.context.device = vehicle;
platformVehicle.accessories.push(new PrecoolHeat(this.config, this.log, this.api, accessory));
this.api.registerPlatformAccessories('homebridge-porsche-taycan', 'PorscheTaycan', [accessory]);
}

// Register Direct charge
const directChargeName = 'Direct charge';
const directChargeUuid = this.api.hap.uuid.generate(`${vehicle.vin}-direct-charge`);
const directChargeExistingAccessory = this.accessories.find(accessory => accessory.UUID === directChargeUuid);

if (directChargeExistingAccessory) {
platformVehicle.accessories.push(new DirectCharge(this.config, this.log, this.api, directChargeExistingAccessory));
} else {
this.log.info('Direct charge added as accessory');
const accessory = new this.api.platformAccessory('Direct charge', directChargeUuid);
this.log.info(`${directChargeName} added as accessory`);
const accessory = new this.api.platformAccessory(directChargeName, directChargeUuid);
accessory.context.device = vehicle;
platformVehicle.accessories.push(new DirectCharge(this.config, this.log, this.api, accessory));
this.api.registerPlatformAccessories('homebridge-porsche-taycan', 'PorscheTaycan', [accessory]);
}

// (Optionally) Register Battery
const batteryChargeUuid = this.api.hap.uuid.generate(`${vehicle.vin}-battery`);
const batteryExistingAccessory = this.accessories.find(accessory => accessory.UUID === batteryChargeUuid);
const batteryName = 'Battery';
const batteryUuid = this.api.hap.uuid.generate(`${vehicle.vin}-battery`);
const batteryExistingAccessory = this.accessories.find(accessory => accessory.UUID === batteryUuid);
if (this.config.batteryDevice === true) {

if (batteryExistingAccessory) {
platformVehicle.accessories.push(new Battery(this.config, this.log, this.api, batteryExistingAccessory));
} else {
this.log.info('Battery added as accessory');
const accessory = new this.api.platformAccessory('Battery', batteryChargeUuid);
this.log.info(`${batteryName} added as accessory`);
const accessory = new this.api.platformAccessory(batteryName, batteryUuid);
accessory.context.device = vehicle;
platformVehicle.accessories.push(new Battery(this.config, this.log, this.api, accessory));
this.api.registerPlatformAccessories('homebridge-porsche-taycan', 'PorscheTaycan', [accessory]);
}
} else {
if (batteryExistingAccessory) {
this.api.unregisterPlatformAccessories(batteryChargeUuid, 'homebridge-porsche-taycan', [batteryExistingAccessory]);
this.api.unregisterPlatformAccessories(batteryUuid, 'homebridge-porsche-taycan', [batteryExistingAccessory]);
}
}

// (Optionally) Charging Power
const chargingPowerName = 'Charging Power';
const chargingPowerUuid = this.api.hap.uuid.generate(`${vehicle.vin}-charging-power`);
const chargingPowerExistingAccessory = this.accessories.find(accessory => accessory.UUID === chargingPowerUuid);
if (this.config.chargingPowerDevice === true) {
if (chargingPowerExistingAccessory) {
platformVehicle.accessories.push(new ChargingPower(this.config, this.log, this.api, chargingPowerExistingAccessory));
} else {
this.log.info('Charging Power added as accessory');
const accessory = new this.api.platformAccessory('Charging Power', chargingPowerUuid);
this.log.info(`${chargingPowerName} added as accessory`);
const accessory = new this.api.platformAccessory(chargingPowerName, chargingPowerUuid);
accessory.context.device = vehicle;
platformVehicle.accessories.push(new ChargingPower(this.config, this.log, this.api, accessory));
this.api.registerPlatformAccessories('homebridge-porsche-taycan', 'PorscheTaycan', [accessory]);
Expand All @@ -146,14 +147,15 @@ export class PorscheTaycanPlatform implements DynamicPlatformPlugin {
}

// (Optionally) Occupancy
const occupancyName = 'Occupancy';
const occupancyUuid = this.api.hap.uuid.generate(`${vehicle.vin}-occupancy`);
const occupancyExistingAccessory = this.accessories.find(accessory => accessory.UUID === occupancyUuid);
if (this.config.locationConfig && this.config.locationConfig.lat && this.config.locationConfig.long) {
if (occupancyExistingAccessory) {
platformVehicle.accessories.push(new Occupancy(this.config, this.log, this.api, occupancyExistingAccessory));
} else {
this.log.info('Occupancy added as accessory');
const accessory = new this.api.platformAccessory('Occupancy', occupancyUuid);
this.log.info(`${occupancyName} added as accessory`);
const accessory = new this.api.platformAccessory(occupancyName, occupancyUuid);
accessory.context.device = vehicle;
platformVehicle.accessories.push(new Occupancy(this.config, this.log, this.api, accessory));
this.api.registerPlatformAccessories('homebridge-porsche-taycan', 'PorscheTaycan', [accessory]);
Expand Down

0 comments on commit f579053

Please sign in to comment.