Skip to content

Commit

Permalink
Add invertersCount to InverterConfiguraton
Browse files Browse the repository at this point in the history
  • Loading branch information
longzheng committed Nov 3, 2024
1 parent 8ebaac9 commit 9f44ffe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/coordinator/helpers/derSample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('generateDerSample', () => {
ConnectStatus.Connected |
ConnectStatus.Operating,
},
invertersCount: 1,
} satisfies typeof result);
});

Expand Down Expand Up @@ -193,6 +194,7 @@ describe('generateDerSample', () => {
ConnectStatus.Connected |
ConnectStatus.Operating,
},
invertersCount: 2,
} satisfies typeof result);
});
});
2 changes: 2 additions & 0 deletions src/coordinator/helpers/derSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const derSampleDataSchema = z.object({
operationalModeStatus: z.number(),
genConnectStatus: z.number(),
}),
invertersCount: z.number(),
});

export type DerSampleData = z.infer<typeof derSampleDataSchema>;
Expand Down Expand Up @@ -124,5 +125,6 @@ export function generateDerSample({
0,
) satisfies ConnectStatus,
},
invertersCount: invertersData.length,
};
}
10 changes: 10 additions & 0 deletions src/coordinator/helpers/inverterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type InverterConfiguration =
| { type: 'disconnect' }
| {
type: 'limit';
invertersCount: number;
targetSolarWatts: number;
targetSolarPowerRatio: number;
};
Expand Down Expand Up @@ -278,13 +279,18 @@ export class InverterController {
})),
);

const maxInvertersCount = Math.max(
...recentDerSamples.map((sample) => sample.invertersCount),
);

const rampedInverterConfiguration = ((): InverterConfiguration => {
const configuration = calculateInverterConfiguration({
activeInverterControlLimit:
this.controlLimitsCache.activeInverterControlLimit,
nameplateMaxW: averagedNameplateMaxW,
siteWatts: averagedSiteWatts,
solarWatts: averagedSolarWatts,
maxInvertersCount,
});

switch (configuration.type) {
Expand Down Expand Up @@ -335,6 +341,7 @@ export class InverterController {

return {
type: 'limit',
invertersCount: configuration.invertersCount,
targetSolarWatts: rampedTargetSolarWatts,
targetSolarPowerRatio: rampedTargetSolarPowerRatio,
};
Expand All @@ -351,11 +358,13 @@ export function calculateInverterConfiguration({
siteWatts,
solarWatts,
nameplateMaxW,
maxInvertersCount,
}: {
activeInverterControlLimit: ActiveInverterControlLimit;
siteWatts: number;
solarWatts: number;
nameplateMaxW: number;
maxInvertersCount: number;
}): InverterConfiguration {
const logger = pinoLogger.child({
module: 'calculateInverterConfiguration',
Expand Down Expand Up @@ -435,6 +444,7 @@ export function calculateInverterConfiguration({

return {
type: 'limit',
invertersCount: maxInvertersCount,
targetSolarWatts,
targetSolarPowerRatio: roundToDecimals(targetSolarPowerRatio, 4),
};
Expand Down

0 comments on commit 9f44ffe

Please sign in to comment.