Skip to content

Commit

Permalink
refactor: amend client.camera.turnCoolerOn() and turnCoolerOff() in @…
Browse files Browse the repository at this point in the history
…observerly/hyper.

refactor: amend client.camera.turnCoolerOn() and turnCoolerOff() in @observerly/hyper.
  • Loading branch information
michealroberts committed Apr 13, 2024
1 parent 42b1246 commit d99c909
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
20 changes: 18 additions & 2 deletions src/routes/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,15 @@ export const camera = (base: URL, init?: RequestInit, headers?: () => Promise<He
}
>() => {
const url = new URL('camera/cooler', base)
return dispatchRequest<T>(url, { ...init, method: 'PUT' }, headers)

const data = JSON.stringify({ on: true })

return dispatchRequest<T>(
url,
{ ...init, method: 'PUT', body: JSON.stringify({ on: true }) },
headers,
data
)
}
},
{
Expand All @@ -214,7 +222,15 @@ export const camera = (base: URL, init?: RequestInit, headers?: () => Promise<He
}
>() => {
const url = new URL('camera/cooler', base)
return dispatchRequest<T>(url, { ...init, method: 'DELETE' }, headers)

const data = JSON.stringify({ on: false })

return dispatchRequest<T>(
url,
{ ...init, method: 'PUT', body: JSON.stringify({ on: false }) },
headers,
data
)
}
},
{
Expand Down
15 changes: 6 additions & 9 deletions tests/mocks/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,30 @@ export const cameraHandlers: Handler[] = [
})
},
{
method: ['PUT', 'DELETE'],
method: ['PUT'],
url: '/api/v1/camera/cooler',
handler: eventHandler(event => {
handler: eventHandler(async event => {
const method = getMethod(event)

if (!['PUT', 'DELETE'].includes(method)) {
if (!['PUT'].includes(method)) {
return new Response('Method Not Allowed', {
status: 405,
statusText: 'Method Not Allowed'
})
}

const body = await readBody<{ on: boolean }>(event)

const status = {
connected: true,
pulseGuiding: false,
coolerOn: false,
coolerOn: body.on,
coolerPower: 0,
CCDtemperature: 0,
heatSinkTemperature: 0,
state: 'idle'
}

if (method === 'PUT') {
status.coolerOn = true
return status
}

return status
})
},
Expand Down

0 comments on commit d99c909

Please sign in to comment.