Skip to content

Commit

Permalink
Fix yet another way
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Sep 4, 2024
1 parent ea4c7e6 commit c1dc12b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class TeslaFleetApiPlatform implements DynamicPlatformPlugin {
return;
}
this.TeslaFleetApi.vehicle!;
product.display_name ??= "Tesla";
const name = product.display_name || "Tesla";
const uuid = this.api.hap.uuid.generate(
`${PLATFORM_NAME}:${product.vin}`,
);
Expand All @@ -85,12 +85,9 @@ export class TeslaFleetApiPlatform implements DynamicPlatformPlugin {
accessory.displayName,
);
} else {
this.log.debug(
"Adding new accessory:",
product.display_name,
);
this.log.debug("Adding new accessory:", name);
accessory = new this.api.platformAccessory<VehicleContext>(
product.display_name,
name,
uuid,
Categories.OTHER,
);
Expand All @@ -99,7 +96,7 @@ export class TeslaFleetApiPlatform implements DynamicPlatformPlugin {

accessory.context.vin = product.vin;
accessory.context.state = product.state;
accessory.displayName = product.display_name;
accessory.displayName = name;

new VehicleAccessory(this, accessory);
});
Expand All @@ -118,8 +115,7 @@ export class TeslaFleetApiPlatform implements DynamicPlatformPlugin {
return;
}
this.TeslaFleetApi.energy!;
product.site_name ??= "Tesla Energy";

const name = product.site_name || "Tesla Energy";
const uuid = this.api.hap.uuid.generate(
`${PLATFORM_NAME}:${product.id}`,
);
Expand All @@ -133,9 +129,9 @@ export class TeslaFleetApiPlatform implements DynamicPlatformPlugin {
accessory.displayName,
);
} else {
this.log.debug("Adding new accessory:", product.site_name);
this.log.debug("Adding new accessory:", name);
accessory = new this.api.platformAccessory<EnergyContext>(
product.site_name,
name,
uuid,
Categories.OTHER,
);
Expand All @@ -146,7 +142,7 @@ export class TeslaFleetApiPlatform implements DynamicPlatformPlugin {
accessory.context.battery = product.components.battery;
accessory.context.grid = product.components.grid;
accessory.context.solar = product.components.solar;
accessory.displayName = product.site_name;
accessory.displayName = name;

new EnergyAccessory(this, accessory);
});
Expand Down

0 comments on commit c1dc12b

Please sign in to comment.