Skip to content

Commit

Permalink
add durationoptions type
Browse files Browse the repository at this point in the history
  • Loading branch information
purplenicole730 committed Oct 4, 2023
1 parent 9ba95af commit 7b277e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/board.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { type Board, PowerMode } from './board/board';
export { type Board, type DurationOptions, PowerMode } from './board/board';
export { BoardClient } from './board/client';
4 changes: 3 additions & 1 deletion src/components/board/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type ValueOf<T> = T[keyof T];
export const { PowerMode } = pb;
export type PowerMode = ValueOf<typeof pb.PowerMode>;

export type DurationOptions = Duration.AsObject;

/**
* Represents a physical general purpose compute board that contains various
* components such as analog readers, and digital interrupts.
Expand Down Expand Up @@ -90,7 +92,7 @@ export interface Board extends Resource {
setPowerMode(
name: string,
powerMode: PowerMode,
duration: Duration,
duration: DurationOptions,
extra?: StructType
): Promise<void>;
}
9 changes: 6 additions & 3 deletions src/components/board/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Options, StructType } from '../../types';

import pb from '../../gen/component/board/v1/board_pb';
import { promisify, doCommandFromClient } from '../../utils';
import type { Board, PowerMode } from './board';
import type { Board, DurationOptions, PowerMode } from './board';

/**
* A gRPC-web client for the Board component.
Expand Down Expand Up @@ -206,14 +206,17 @@ export class BoardClient implements Board {
async setPowerMode(
name: string,
powerMode: PowerMode,
duration?: Duration,
durationObj?: DurationOptions,
extra = {}
) {
const { boardService } = this;
const request = new pb.SetPowerModeRequest();
request.setName(name);
request.setPowerMode(powerMode);
if (duration) {
if (durationObj) {
const duration = new Duration();
duration.setNanos(durationObj.nanos);
duration.setSeconds(durationObj.seconds);
request.setDuration(duration);
}
request.setExtra(Struct.fromJavaScript(extra));
Expand Down
7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ export { type Base, type BaseProperties, BaseClient } from './components/base';
* @group Raw Protobufs
*/
export { default as boardApi } from './gen/component/board/v1/board_pb';
export { type Board, BoardClient, PowerMode } from './components/board';
export {
type Board,
BoardClient,
type DurationOptions,
PowerMode,
} from './components/board';

/**
* Raw Protobuf interfaces for a Camera component.
Expand Down

0 comments on commit 7b277e1

Please sign in to comment.