Derive device voltages from project settings

This commit is contained in:
Julian Appel 2026-07-29 09:53:58 +02:00
parent b1a11397b3
commit 084103bf54
39 changed files with 2696 additions and 76 deletions

View file

@ -0,0 +1,35 @@
export type ElectricalPhaseType = "single_phase" | "three_phase";
export interface ProjectVoltageSettings {
singlePhaseVoltageV: number;
threePhaseVoltageV: number;
}
export function resolveProjectVoltage(
phaseType: ElectricalPhaseType,
settings: ProjectVoltageSettings
) {
return phaseType === "three_phase"
? settings.threePhaseVoltageV
: settings.singlePhaseVoltageV;
}
export function resolveCircuitPhaseType(
sectionKey: string,
devicePhaseTypes: ReadonlyArray<string | null | undefined> = []
): ElectricalPhaseType {
if (sectionKey === "three_phase") {
return "three_phase";
}
if (sectionKey === "lighting" || sectionKey === "single_phase") {
return "single_phase";
}
const assignedPhaseTypes = devicePhaseTypes.filter(
(phaseType): phaseType is ElectricalPhaseType =>
phaseType === "single_phase" || phaseType === "three_phase"
);
return assignedPhaseTypes.length > 0 &&
assignedPhaseTypes.every((phaseType) => phaseType === "three_phase")
? "three_phase"
: "single_phase";
}