Skip to content

Commit

Permalink
default to spst
Browse files Browse the repository at this point in the history
  • Loading branch information
techmannih committed Feb 13, 2025
1 parent 0285ced commit 992639a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
16 changes: 4 additions & 12 deletions lib/components/normal-components/Switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,21 @@ import { NormalComponent } from "../base-components/NormalComponent/NormalCompon
import type { BaseSymbolName } from "lib/utils/constants"
import { z } from "zod"

// Extend the SwitchProps type to include spst, spdt, dpst, and dpdt as optional boolean properties
export interface ExtendedSwitchProps extends z.infer<typeof switchProps> {
spst?: boolean
spdt?: boolean
dpst?: boolean
dpdt?: boolean
}

// Modify the Switch class to use ExtendedSwitchProps
export class Switch extends NormalComponent<typeof switchProps> {
// Ensure props are correctly typed as ExtendedSwitchProps
get config() {
let baseSymbolName: BaseSymbolName

// Destructure the boolean flags from the props
const { spst, spdt, dpst, dpdt, type } = this.props as ExtendedSwitchProps

let switchType: "spst" | "spdt" | "dpst" | "dpdt" | undefined = undefined
let switchType: "spst" | "spdt" | "dpst" | "dpdt" = "spst"

// Set the switch type based on the boolean flags (if provided)
if (spst) {
switchType = "spst"
} else if (spdt) {
Expand All @@ -31,12 +26,10 @@ export class Switch extends NormalComponent<typeof switchProps> {
switchType = "dpst"
} else if (dpdt) {
switchType = "dpdt"
} else if (type) {
switchType = type
}

// Fallback to 'type' prop if no boolean flags are set
switchType = switchType ?? type ?? "dpdt" // Default to 'dpdt' if neither are provided

// Set the appropriate schematic name based on the type
switch (switchType) {
case "spst":
baseSymbolName = "SPST_switch"
Expand Down Expand Up @@ -67,12 +60,11 @@ export class Switch extends NormalComponent<typeof switchProps> {
const { db } = this.root!
const { _parsedProps: props } = this

// Ensure correct fallback for 'isNormallyClosed' if not explicitly set
const source_component = db.source_component.insert({
ftype: "simple_switch",
name: props.name,
switch_type: props.type,
is_normally_closed: props.isNormallyClosed ?? false, // Fallback to false if not provided
is_normally_closed: props.isNormallyClosed ?? false,
} as any)

this.source_component_id = source_component.source_component_id
Expand Down
Loading

0 comments on commit 992639a

Please sign in to comment.