dirigera
Version:
A TypeScript client for IKEA's DIRIGERA smart home hub
23 lines (20 loc) • 669 B
text/typescript
import type { Got } from 'got'
import type { Device } from '../types/device/Device.ts'
import type { LightSensor } from '../types/device/LightSensor.ts'
export default (got: Got) => {
return {
async list() {
const devices = await got.get(`devices`).json<Device[]>()
return devices.filter(
(d): d is LightSensor => d.deviceType === 'lightSensor'
)
},
async get({ id }: { id: string }) {
const device = await got.get(`devices/${id}`).json<Device>()
if (device.deviceType !== 'lightSensor') {
throw new Error('The requested device is not a lightSensor')
}
return device as LightSensor
},
}
}