diff --git a/src/components/switch/client.ts b/src/components/switch/client.ts index db3ddaa50..c78fab078 100644 --- a/src/components/switch/client.ts +++ b/src/components/switch/client.ts @@ -1,5 +1,5 @@ import { Struct, type JsonValue } from '@bufbuild/protobuf'; -import type { CallOptions, PromiseClient } from '@connectrpc/connect'; +import type { CallOptions, Client } from '@connectrpc/connect'; import { SwitchService } from '../../gen/component/switch/v1/switch_connect'; import { SetPositionRequest, @@ -17,7 +17,7 @@ import type { Switch } from './switch'; * @group Clients */ export class SwitchClient implements Switch { - private client: PromiseClient; + private client: Client; public readonly name: string; private readonly options: Options; public callOptions: CallOptions = { headers: {} as Record }; @@ -65,7 +65,15 @@ export class SwitchClient implements Switch { this.options.requestLogger?.(request); const resp = await this.client.getNumberOfPositions(request, callOptions); - return resp.numberOfPositions; + if ( + resp.labels.length > 0 && + resp.labels.length !== resp.numberOfPositions + ) { + throw new Error( + 'the number of labels does not match the number of positions' + ); + } + return [resp.numberOfPositions, resp.labels] as [number, string[]]; } async doCommand( diff --git a/src/components/switch/switch.ts b/src/components/switch/switch.ts index 79cd0e0a9..21bd1339e 100644 --- a/src/components/switch/switch.ts +++ b/src/components/switch/switch.ts @@ -50,7 +50,9 @@ export interface Switch extends Resource { getPosition: (extra?: Struct) => Promise; /** - * Get the total number of positions available on the switch. + * Get the total number of positions available on the switch, along with their + * labels. Labels should either be null, undefined, empty, or the same length + * has the number of positions. * * @example * @@ -65,5 +67,5 @@ export interface Switch extends Resource { * For more information, see [Switch * API](https://docs.viam.com/dev/reference/apis/components/switch/#getnumberofpositions). */ - getNumberOfPositions: (extra?: Struct) => Promise; + getNumberOfPositions: (extra?: Struct) => Promise<[number, string[]]>; }