/* * Automatically generated by codegen/smith.ts. * Do not edit this file or add other files to this directory. */ import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect' import { seamApiLtsVersion } from 'lib/lts-version.js' import { getAuthHeadersForClientSessionToken, warnOnInsecureuserIdentifierKey, } from 'lib/seam/connect/auth.js' import { type Client, createClient } from 'lib/seam/connect/client.js' import { isSeamHttpOptionsWithApiKey, isSeamHttpOptionsWithClient, isSeamHttpOptionsWithClientSessionToken, isSeamHttpOptionsWithConsoleSessionToken, isSeamHttpOptionsWithPersonalAccessToken, type SeamHttpFromPublishableKeyOptions, SeamHttpInvalidOptionsError, type SeamHttpOptions, type SeamHttpOptionsWithApiKey, type SeamHttpOptionsWithClient, type SeamHttpOptionsWithClientSessionToken, type SeamHttpOptionsWithConsoleSessionToken, type SeamHttpOptionsWithPersonalAccessToken, type SeamHttpRequestOptions, } from 'lib/seam/connect/options.js' import { limitToSeamHttpRequestOptions, parseOptions, } from 'lib/seam/connect/parse-options.js' import { SeamHttpClientSessions } from 'lib/seam/connect/routes/client-sessions/index.js' import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js' import { SeamPaginator } from 'lib/seam/connect/seam-paginator.js' import type { SetNonNullable } from 'lib/types.js' import { SeamHttpThermostatsDailyPrograms } from './daily-programs/index.js' import { SeamHttpThermostatsSchedules } from './schedules/index.js' import { SeamHttpThermostatsSimulate } from './simulate/index.js' export class SeamHttpThermostats { client: Client readonly defaults: Required readonly ltsVersion = seamApiLtsVersion static ltsVersion = seamApiLtsVersion constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) { const options = parseOptions(apiKeyOrOptions) this.client = 'client' in options ? options.client : createClient(options) this.defaults = limitToSeamHttpRequestOptions(options) } static fromClient( client: SeamHttpOptionsWithClient['client'], options: Omit = {}, ): SeamHttpThermostats { const constructorOptions = { ...options, client } if (!isSeamHttpOptionsWithClient(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing client') } return new SeamHttpThermostats(constructorOptions) } static fromApiKey( apiKey: SeamHttpOptionsWithApiKey['apiKey'], options: Omit = {}, ): SeamHttpThermostats { const constructorOptions = { ...options, apiKey } if (!isSeamHttpOptionsWithApiKey(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing apiKey') } return new SeamHttpThermostats(constructorOptions) } static fromClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options: Omit< SeamHttpOptionsWithClientSessionToken, 'clientSessionToken' > = {}, ): SeamHttpThermostats { const constructorOptions = { ...options, clientSessionToken } if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError('Missing clientSessionToken') } return new SeamHttpThermostats(constructorOptions) } static async fromPublishableKey( publishableKey: string, userIdentifierKey: string, options: SeamHttpFromPublishableKeyOptions = {}, ): Promise { warnOnInsecureuserIdentifierKey(userIdentifierKey) const clientOptions = parseOptions({ ...options, publishableKey }) if (isSeamHttpOptionsWithClient(clientOptions)) { throw new SeamHttpInvalidOptionsError( 'The client option cannot be used with SeamHttpThermostats.fromPublishableKey', ) } const client = createClient(clientOptions) const clientSessions = SeamHttpClientSessions.fromClient(client) const { token } = await clientSessions.getOrCreate({ user_identifier_key: userIdentifierKey, }) return SeamHttpThermostats.fromClientSessionToken(token, options) } static fromConsoleSessionToken( consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'], workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'], options: Omit< SeamHttpOptionsWithConsoleSessionToken, 'consoleSessionToken' | 'workspaceId' > = {}, ): SeamHttpThermostats { const constructorOptions = { ...options, consoleSessionToken, workspaceId } if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing consoleSessionToken or workspaceId', ) } return new SeamHttpThermostats(constructorOptions) } static fromPersonalAccessToken( personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'], workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'], options: Omit< SeamHttpOptionsWithPersonalAccessToken, 'personalAccessToken' | 'workspaceId' > = {}, ): SeamHttpThermostats { const constructorOptions = { ...options, personalAccessToken, workspaceId } if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) { throw new SeamHttpInvalidOptionsError( 'Missing personalAccessToken or workspaceId', ) } return new SeamHttpThermostats(constructorOptions) } createPaginator( request: SeamHttpRequest, ): SeamPaginator { return new SeamPaginator(this, request) } async updateClientSessionToken( clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], ): Promise { const { headers } = this.client.defaults const authHeaders = getAuthHeadersForClientSessionToken({ clientSessionToken, }) for (const key of Object.keys(authHeaders)) { if (headers[key] == null) { throw new Error( 'Cannot update a clientSessionToken on a client created without a clientSessionToken', ) } } this.client.defaults.headers = { ...headers, ...authHeaders } const clientSessions = SeamHttpClientSessions.fromClient(this.client) await clientSessions.get() } get dailyPrograms(): SeamHttpThermostatsDailyPrograms { return SeamHttpThermostatsDailyPrograms.fromClient( this.client, this.defaults, ) } get schedules(): SeamHttpThermostatsSchedules { return SeamHttpThermostatsSchedules.fromClient(this.client, this.defaults) } get simulate(): SeamHttpThermostatsSimulate { return SeamHttpThermostatsSimulate.fromClient(this.client, this.defaults) } activateClimatePreset( parameters?: ThermostatsActivateClimatePresetParameters, options: ThermostatsActivateClimatePresetOptions = {}, ): ThermostatsActivateClimatePresetRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/activate_climate_preset', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } cool( parameters?: ThermostatsCoolParameters, options: ThermostatsCoolOptions = {}, ): ThermostatsCoolRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/cool', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } createClimatePreset( parameters?: ThermostatsCreateClimatePresetParameters, options: ThermostatsCreateClimatePresetOptions = {}, ): ThermostatsCreateClimatePresetRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/create_climate_preset', method: 'POST', body: parameters, responseKey: undefined, options, }) } deleteClimatePreset( parameters?: ThermostatsDeleteClimatePresetParameters, options: ThermostatsDeleteClimatePresetOptions = {}, ): ThermostatsDeleteClimatePresetRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/delete_climate_preset', method: 'POST', body: parameters, responseKey: undefined, options, }) } get( parameters?: ThermostatsGetParameters, options: ThermostatsGetOptions = {}, ): ThermostatsGetRequest { if (!this.defaults.isUndocumentedApiEnabled) { throw new Error( 'Cannot use undocumented API without isUndocumentedApiEnabled', ) } return new SeamHttpRequest(this, { pathname: '/thermostats/get', method: 'POST', body: parameters, responseKey: 'thermostat', options, }) } heat( parameters?: ThermostatsHeatParameters, options: ThermostatsHeatOptions = {}, ): ThermostatsHeatRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/heat', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } heatCool( parameters?: ThermostatsHeatCoolParameters, options: ThermostatsHeatCoolOptions = {}, ): ThermostatsHeatCoolRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/heat_cool', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } list( parameters?: ThermostatsListParameters, options: ThermostatsListOptions = {}, ): ThermostatsListRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/list', method: 'POST', body: parameters, responseKey: 'devices', options, }) } off( parameters?: ThermostatsOffParameters, options: ThermostatsOffOptions = {}, ): ThermostatsOffRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/off', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } setFallbackClimatePreset( parameters?: ThermostatsSetFallbackClimatePresetParameters, options: ThermostatsSetFallbackClimatePresetOptions = {}, ): ThermostatsSetFallbackClimatePresetRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/set_fallback_climate_preset', method: 'POST', body: parameters, responseKey: undefined, options, }) } setFanMode( parameters?: ThermostatsSetFanModeParameters, options: ThermostatsSetFanModeOptions = {}, ): ThermostatsSetFanModeRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/set_fan_mode', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } setHvacMode( parameters?: ThermostatsSetHvacModeParameters, options: ThermostatsSetHvacModeOptions = {}, ): ThermostatsSetHvacModeRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/set_hvac_mode', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } setTemperatureThreshold( parameters?: ThermostatsSetTemperatureThresholdParameters, options: ThermostatsSetTemperatureThresholdOptions = {}, ): ThermostatsSetTemperatureThresholdRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/set_temperature_threshold', method: 'PATCH', body: parameters, responseKey: undefined, options, }) } updateClimatePreset( parameters?: ThermostatsUpdateClimatePresetParameters, options: ThermostatsUpdateClimatePresetOptions = {}, ): ThermostatsUpdateClimatePresetRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/update_climate_preset', method: 'PATCH', body: parameters, responseKey: undefined, options, }) } updateWeeklyProgram( parameters?: ThermostatsUpdateWeeklyProgramParameters, options: ThermostatsUpdateWeeklyProgramOptions = {}, ): ThermostatsUpdateWeeklyProgramRequest { return new SeamHttpRequest(this, { pathname: '/thermostats/update_weekly_program', method: 'POST', body: parameters, responseKey: 'action_attempt', options, }) } } export type ThermostatsActivateClimatePresetParameters = RouteRequestBody<'/thermostats/activate_climate_preset'> /** * @deprecated Use ThermostatsActivateClimatePresetParameters instead. */ export type ThermostatsActivateClimatePresetBody = ThermostatsActivateClimatePresetParameters /** * @deprecated Use ThermostatsActivateClimatePresetRequest instead. */ export type ThermostatsActivateClimatePresetResponse = SetNonNullable< Required> > export type ThermostatsActivateClimatePresetRequest = SeamHttpRequest< ThermostatsActivateClimatePresetResponse, 'action_attempt' > export type ThermostatsActivateClimatePresetOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type ThermostatsCoolParameters = RouteRequestBody<'/thermostats/cool'> /** * @deprecated Use ThermostatsCoolParameters instead. */ export type ThermostatsCoolBody = ThermostatsCoolParameters /** * @deprecated Use ThermostatsCoolRequest instead. */ export type ThermostatsCoolResponse = SetNonNullable< Required> > export type ThermostatsCoolRequest = SeamHttpRequest< ThermostatsCoolResponse, 'action_attempt' > export type ThermostatsCoolOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type ThermostatsCreateClimatePresetParameters = RouteRequestBody<'/thermostats/create_climate_preset'> /** * @deprecated Use ThermostatsCreateClimatePresetParameters instead. */ export type ThermostatsCreateClimatePresetBody = ThermostatsCreateClimatePresetParameters /** * @deprecated Use ThermostatsCreateClimatePresetRequest instead. */ export type ThermostatsCreateClimatePresetResponse = SetNonNullable< Required> > export type ThermostatsCreateClimatePresetRequest = SeamHttpRequest< void, undefined > export interface ThermostatsCreateClimatePresetOptions {} export type ThermostatsDeleteClimatePresetParameters = RouteRequestBody<'/thermostats/delete_climate_preset'> /** * @deprecated Use ThermostatsDeleteClimatePresetParameters instead. */ export type ThermostatsDeleteClimatePresetParams = ThermostatsDeleteClimatePresetParameters /** * @deprecated Use ThermostatsDeleteClimatePresetRequest instead. */ export type ThermostatsDeleteClimatePresetResponse = SetNonNullable< Required> > export type ThermostatsDeleteClimatePresetRequest = SeamHttpRequest< void, undefined > export interface ThermostatsDeleteClimatePresetOptions {} export type ThermostatsGetParameters = RouteRequestBody<'/thermostats/get'> /** * @deprecated Use ThermostatsGetParameters instead. */ export type ThermostatsGetParams = ThermostatsGetParameters /** * @deprecated Use ThermostatsGetRequest instead. */ export type ThermostatsGetResponse = SetNonNullable< Required> > export type ThermostatsGetRequest = SeamHttpRequest< ThermostatsGetResponse, 'thermostat' > export interface ThermostatsGetOptions {} export type ThermostatsHeatParameters = RouteRequestBody<'/thermostats/heat'> /** * @deprecated Use ThermostatsHeatParameters instead. */ export type ThermostatsHeatBody = ThermostatsHeatParameters /** * @deprecated Use ThermostatsHeatRequest instead. */ export type ThermostatsHeatResponse = SetNonNullable< Required> > export type ThermostatsHeatRequest = SeamHttpRequest< ThermostatsHeatResponse, 'action_attempt' > export type ThermostatsHeatOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type ThermostatsHeatCoolParameters = RouteRequestBody<'/thermostats/heat_cool'> /** * @deprecated Use ThermostatsHeatCoolParameters instead. */ export type ThermostatsHeatCoolBody = ThermostatsHeatCoolParameters /** * @deprecated Use ThermostatsHeatCoolRequest instead. */ export type ThermostatsHeatCoolResponse = SetNonNullable< Required> > export type ThermostatsHeatCoolRequest = SeamHttpRequest< ThermostatsHeatCoolResponse, 'action_attempt' > export type ThermostatsHeatCoolOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type ThermostatsListParameters = RouteRequestBody<'/thermostats/list'> /** * @deprecated Use ThermostatsListParameters instead. */ export type ThermostatsListParams = ThermostatsListParameters /** * @deprecated Use ThermostatsListRequest instead. */ export type ThermostatsListResponse = SetNonNullable< Required> > export type ThermostatsListRequest = SeamHttpRequest< ThermostatsListResponse, 'devices' > export interface ThermostatsListOptions {} export type ThermostatsOffParameters = RouteRequestBody<'/thermostats/off'> /** * @deprecated Use ThermostatsOffParameters instead. */ export type ThermostatsOffBody = ThermostatsOffParameters /** * @deprecated Use ThermostatsOffRequest instead. */ export type ThermostatsOffResponse = SetNonNullable< Required> > export type ThermostatsOffRequest = SeamHttpRequest< ThermostatsOffResponse, 'action_attempt' > export type ThermostatsOffOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type ThermostatsSetFallbackClimatePresetParameters = RouteRequestBody<'/thermostats/set_fallback_climate_preset'> /** * @deprecated Use ThermostatsSetFallbackClimatePresetParameters instead. */ export type ThermostatsSetFallbackClimatePresetBody = ThermostatsSetFallbackClimatePresetParameters /** * @deprecated Use ThermostatsSetFallbackClimatePresetRequest instead. */ export type ThermostatsSetFallbackClimatePresetResponse = SetNonNullable< Required> > export type ThermostatsSetFallbackClimatePresetRequest = SeamHttpRequest< void, undefined > export interface ThermostatsSetFallbackClimatePresetOptions {} export type ThermostatsSetFanModeParameters = RouteRequestBody<'/thermostats/set_fan_mode'> /** * @deprecated Use ThermostatsSetFanModeParameters instead. */ export type ThermostatsSetFanModeBody = ThermostatsSetFanModeParameters /** * @deprecated Use ThermostatsSetFanModeRequest instead. */ export type ThermostatsSetFanModeResponse = SetNonNullable< Required> > export type ThermostatsSetFanModeRequest = SeamHttpRequest< ThermostatsSetFanModeResponse, 'action_attempt' > export type ThermostatsSetFanModeOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type ThermostatsSetHvacModeParameters = RouteRequestBody<'/thermostats/set_hvac_mode'> /** * @deprecated Use ThermostatsSetHvacModeParameters instead. */ export type ThermostatsSetHvacModeBody = ThermostatsSetHvacModeParameters /** * @deprecated Use ThermostatsSetHvacModeRequest instead. */ export type ThermostatsSetHvacModeResponse = SetNonNullable< Required> > export type ThermostatsSetHvacModeRequest = SeamHttpRequest< ThermostatsSetHvacModeResponse, 'action_attempt' > export type ThermostatsSetHvacModeOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' > export type ThermostatsSetTemperatureThresholdParameters = RouteRequestBody<'/thermostats/set_temperature_threshold'> /** * @deprecated Use ThermostatsSetTemperatureThresholdParameters instead. */ export type ThermostatsSetTemperatureThresholdBody = ThermostatsSetTemperatureThresholdParameters /** * @deprecated Use ThermostatsSetTemperatureThresholdRequest instead. */ export type ThermostatsSetTemperatureThresholdResponse = SetNonNullable< Required> > export type ThermostatsSetTemperatureThresholdRequest = SeamHttpRequest< void, undefined > export interface ThermostatsSetTemperatureThresholdOptions {} export type ThermostatsUpdateClimatePresetParameters = RouteRequestBody<'/thermostats/update_climate_preset'> /** * @deprecated Use ThermostatsUpdateClimatePresetParameters instead. */ export type ThermostatsUpdateClimatePresetBody = ThermostatsUpdateClimatePresetParameters /** * @deprecated Use ThermostatsUpdateClimatePresetRequest instead. */ export type ThermostatsUpdateClimatePresetResponse = SetNonNullable< Required> > export type ThermostatsUpdateClimatePresetRequest = SeamHttpRequest< void, undefined > export interface ThermostatsUpdateClimatePresetOptions {} export type ThermostatsUpdateWeeklyProgramParameters = RouteRequestBody<'/thermostats/update_weekly_program'> /** * @deprecated Use ThermostatsUpdateWeeklyProgramParameters instead. */ export type ThermostatsUpdateWeeklyProgramBody = ThermostatsUpdateWeeklyProgramParameters /** * @deprecated Use ThermostatsUpdateWeeklyProgramRequest instead. */ export type ThermostatsUpdateWeeklyProgramResponse = SetNonNullable< Required> > export type ThermostatsUpdateWeeklyProgramRequest = SeamHttpRequest< ThermostatsUpdateWeeklyProgramResponse, 'action_attempt' > export type ThermostatsUpdateWeeklyProgramOptions = Pick< SeamHttpRequestOptions, 'waitForActionAttempt' >