-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Battery types, batteryProps, set default unit to mAh (#63)
* Battery types, batteryProps, set default unit to mAh * Update lib/components/battery.ts
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { z } from "zod" | ||
import { | ||
commonComponentProps, | ||
lrPins, | ||
lrPolarPins, | ||
type CommonComponentProps, | ||
} from "lib/common/layout" | ||
import { expectTypesMatch } from "lib/typecheck" | ||
|
||
/** @deprecated use battery_capacity from circuit-json when circuit-json is updated */ | ||
const capacity = z | ||
.number() | ||
.or(z.string().endsWith("mAh")) | ||
.transform((v) => { | ||
if (typeof v === "string") { | ||
const valString = v.replace("mAh", "") | ||
const num = Number.parseFloat(valString) | ||
if (Number.isNaN(num)) { | ||
throw new Error("Invalid capacity") | ||
} | ||
return num | ||
} | ||
return v | ||
}) | ||
.describe("Battery capacity in mAh") | ||
|
||
export interface BatteryProps extends CommonComponentProps { | ||
capacity?: number | string | ||
} | ||
|
||
export const batteryProps = commonComponentProps.extend({ | ||
capacity: capacity.optional(), | ||
}) | ||
export const batteryPins = lrPolarPins | ||
|
||
expectTypesMatch<BatteryProps, z.input<typeof batteryProps>>(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters