diff --git a/src/routes/camera.ts b/src/routes/camera.ts index b629fe7..b99a053 100644 --- a/src/routes/camera.ts +++ b/src/routes/camera.ts @@ -130,5 +130,32 @@ export const camera = (base: URL, init?: RequestInit, headers?: () => Promise(url, { ...init, method: 'DELETE' }, headers) } + }, + { + name: 'setCCDTemperature', + action: < + T = { + connected: boolean + pulseGuiding: boolean + coolerOn: boolean + coolerPower: number + CCDtemperature: number + heatSinkTemperature: number + state: string + } + >(body: { + temperature: number + }) => { + const url = new URL('camera/temperature', base) + + const data = JSON.stringify(body) + + return dispatchRequest( + url, + { ...init, method: 'PUT', body: JSON.stringify(body) }, + headers, + data + ) + } } ] as const diff --git a/tests/camera.spec.ts b/tests/camera.spec.ts index 88278b3..ea2c03d 100644 --- a/tests/camera.spec.ts +++ b/tests/camera.spec.ts @@ -124,5 +124,21 @@ suite('@observerly/hyper Fiber API Observing Camera Client', () => { if (!isDataResult(init)) return expect(init).toStrictEqual({ connected: true }) }) + + it('should be able to set the camera CCD temperature', async () => { + const client = setupClient(getURL('/api/v1/')) + const status = await client.camera.setCCDTemperature({ temperature: -10 }) + expect(isDataResult(status)).toBe(true) + if (!isDataResult(status)) return + expect(status).toStrictEqual({ + connected: true, + pulseGuiding: false, + coolerOn: false, + coolerPower: 0, + CCDtemperature: -10, + heatSinkTemperature: 0, + state: 'idle' + }) + }) }) }) diff --git a/tests/mocks/camera.ts b/tests/mocks/camera.ts index f92a017..5ac3ce5 100644 --- a/tests/mocks/camera.ts +++ b/tests/mocks/camera.ts @@ -6,7 +6,7 @@ /*****************************************************************************************************************/ -import { eventHandler, getMethod } from 'h3' +import { eventHandler, getMethod, readBody } from 'h3' import { type Handler } from '../shared/handler' @@ -116,5 +116,38 @@ export const cameraHandlers: Handler[] = [ return status }) + }, + { + method: ['PUT'], + url: '/api/v1/camera/temperature', + handler: eventHandler(async event => { + const method = getMethod(event) + + if (method !== 'PUT') { + return new Response('Method Not Allowed', { + status: 405, + statusText: 'Method Not Allowed' + }) + } + + const body = await readBody<{ temperature: number }>(event) + + if (!body) { + return new Response('Bad Request', { + status: 400, + statusText: 'Bad Request' + }) + } + + return { + connected: true, + pulseGuiding: false, + coolerOn: false, + coolerPower: 0, + CCDtemperature: body.temperature, + heatSinkTemperature: 0, + state: 'idle' + } + }) } ]