Skip to content

Commit

Permalink
feat: Add device accessory information
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-seinhorst committed Mar 29, 2023
1 parent daaa4e0 commit 8dbd38a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/Accessories/Charger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default class Charger implements PorscheAccessory {
private sensorType: 'occupancy' | 'contact';

constructor(public config: PlatformConfig, public readonly log: Logger, public readonly api: API, public accessory: PlatformAccessory) {
this.accessory.getService(this.Service.AccessoryInformation)!
.setCharacteristic(this.Characteristic.Manufacturer, 'homebridge-porsche-taycan')
.setCharacteristic(this.Characteristic.Model, this.accessory.context.device.modelDescription)
.setCharacteristic(this.Characteristic.SerialNumber, this.accessory.context.device.vin);

this.lowBatteryLevel = this.config.lowBattery || 35;
this.sensorType = this.config.chargerDevice || 'occupancy';
this.chargerService = this.accessory.getService(this.sensorType === 'occupancy' ? this.Service.OccupancySensor : this.Service.ContactSensor)
Expand Down
5 changes: 5 additions & 0 deletions src/Accessories/DirectCharge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default class DirectCharge implements PorscheAccessory {
private heartBeatActive = false;

constructor(public config: PlatformConfig, public readonly log: Logger, public readonly api: API, public accessory: PlatformAccessory) {
this.accessory.getService(this.Service.AccessoryInformation)!
.setCharacteristic(this.Characteristic.Manufacturer, 'homebridge-porsche-taycan')
.setCharacteristic(this.Characteristic.Model, this.accessory.context.device.modelDescription)
.setCharacteristic(this.Characteristic.SerialNumber, this.accessory.context.device.vin);

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));
this.switchService.setCharacteristic(this.Characteristic.On, false);
Expand Down
11 changes: 8 additions & 3 deletions src/Accessories/DirectClimatisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ export default class DirectClimatisation implements PorscheAccessory {
private heartBeatActive = false;

constructor(public config: PlatformConfig, public readonly log: Logger, public readonly api: API, public accessory: PlatformAccessory) {
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));
this.switchService.setCharacteristic(this.Characteristic.On, false);
this.accessory.getService(this.Service.AccessoryInformation)!
.setCharacteristic(this.Characteristic.Manufacturer, 'homebridge-porsche-taycan')
.setCharacteristic(this.Characteristic.Model, this.accessory.context.device.modelDescription)
.setCharacteristic(this.Characteristic.SerialNumber, this.accessory.context.device.vin);

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));
this.switchService.setCharacteristic(this.Characteristic.On, false);
}

private async setStatus(value, callback) {
Expand Down
6 changes: 3 additions & 3 deletions src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class PorscheTaycanPlatform implements DynamicPlatformPlugin {
// Register Charger
const chargerUuid = this.api.hap.uuid.generate(`${vehicle.vin}-charger`);
const chargerExistingAccessory = this.accessories.find(accessory => accessory.UUID === chargerUuid);
const chargerAccessoryName = `${vehicle.modelDescription} Charger`;
const chargerAccessoryName = 'Charger';

if (chargerExistingAccessory) {
platformVehicle.accessories.push(new Charger(this.config, this.log, this.api, chargerExistingAccessory));
Expand All @@ -55,7 +55,7 @@ export class PorscheTaycanPlatform implements DynamicPlatformPlugin {
// Register DirectCharge
const directChargeUuid = this.api.hap.uuid.generate(`${vehicle.vin}-direct-charge`);
const directChargeExistingAccessory = this.accessories.find(accessory => accessory.UUID === directChargeUuid);
const directChargeAccessoryName = `${vehicle.modelDescription} Direct Charge`;
const directChargeAccessoryName = 'Direct Charge';

if (directChargeExistingAccessory) {
platformVehicle.accessories.push(new DirectCharge(this.config, this.log, this.api, directChargeExistingAccessory));
Expand All @@ -70,7 +70,7 @@ export class PorscheTaycanPlatform implements DynamicPlatformPlugin {
// Register DirectClimatisation
const directClimatisationUuid = this.api.hap.uuid.generate(`${vehicle.vin}-direct-climatisation`);
const directClimatisationExistingAccessory = this.accessories.find(accessory => accessory.UUID === directClimatisationUuid);
const directClimatisationAccessoryName = `${vehicle.modelDescription} Direct Climatisation`;
const directClimatisationAccessoryName = 'Direct Climatisation';

if (directClimatisationExistingAccessory) {
platformVehicle.accessories.push(new DirectClimatisation(this.config, this.log, this.api, directClimatisationExistingAccessory));
Expand Down

0 comments on commit 8dbd38a

Please sign in to comment.