diff --git a/src/routes/camera.ts b/src/routes/camera.ts index b99a053..079f2af 100644 --- a/src/routes/camera.ts +++ b/src/routes/camera.ts @@ -36,6 +36,24 @@ export const camera = (base: URL, init?: RequestInit, headers?: () => Promise(url, init, headers) } }, + { + name: 'shutdown', + action: < + T = { + connected: boolean + pulseGuiding: boolean + coolerOn: boolean + coolerPower: number + CCDtemperature: number + heatSinkTemperature: number + state: string + } + >() => { + const url = new URL('camera/shutdown', base) + + return dispatchRequest(url, { ...init, method: 'PUT' }, headers) + } + }, { name: 'getConfiguration', action: < diff --git a/tests/camera.spec.ts b/tests/camera.spec.ts index ea2c03d..b08582a 100644 --- a/tests/camera.spec.ts +++ b/tests/camera.spec.ts @@ -140,5 +140,21 @@ suite('@observerly/hyper Fiber API Observing Camera Client', () => { state: 'idle' }) }) + + it('should be able to shutdown the camera', async () => { + const client = setupClient(getURL('/api/v1/')) + const status = await client.camera.shutdown() + expect(isDataResult(status)).toBe(true) + if (!isDataResult(status)) return + expect(status).toStrictEqual({ + connected: false, + pulseGuiding: false, + coolerOn: false, + coolerPower: 0, + CCDtemperature: 0, + heatSinkTemperature: 0, + state: 'idle' + }) + }) }) }) diff --git a/tests/mocks/camera.ts b/tests/mocks/camera.ts index 5ac3ce5..2e33e0c 100644 --- a/tests/mocks/camera.ts +++ b/tests/mocks/camera.ts @@ -22,6 +22,30 @@ export const cameraHandlers: Handler[] = [ } }) }, + { + method: 'PUT', + url: '/api/v1/camera/shutdown', + handler: eventHandler(event => { + const method = getMethod(event) + + if (method !== 'PUT') { + return new Response('Method Not Allowed', { + status: 405, + statusText: 'Method Not Allowed' + }) + } + + return { + connected: false, + pulseGuiding: false, + coolerOn: false, + coolerPower: 0, + CCDtemperature: 0, + heatSinkTemperature: 0, + state: 'idle' + } + }) + }, { method: 'GET', url: '/api/v1/camera/config',