dirigera
Version:
A TypeScript client for IKEA's DIRIGERA smart home hub
97 lines (89 loc) • 1.97 kB
text/typescript
import type { Got } from 'got'
import type { Device } from '../types/device/Device.ts'
import type { Home } from '../types/Home.ts'
import type { DeviceSet } from '../types/DeviceSet.ts'
export default (got: Got) => {
return {
async list() {
const home = await got.get(`home`).json<Home>()
return home.deviceSets
},
async create({ name, icon }: Pick<DeviceSet, 'name' | 'icon'>) {
return await got
.post(`device-set`, {
json: {
name,
icon,
},
})
.json<{ id: string }>()
},
async delete({ id }: { id: string }) {
await got.delete(`device-set/${id}`)
},
async update({ id, name, icon }: DeviceSet) {
await got
.put(`device-set/${id}`, {
json: {
name,
icon,
},
})
.json()
},
async updateConfiguration({
id,
deviceIds,
roomId,
remoteLinkIds,
}: {
id: string
deviceIds: string[]
roomId?: string
remoteLinkIds?: string[]
}) {
await got
.patch(`device-set/${id}/configuration`, {
json: {
deviceIds,
roomId,
remoteLinkIds,
},
})
.json()
},
async setIsOn({ id, isOn }: { id: string; isOn: boolean }) {
await got
.patch(`devices/set/${id}`, {
json: [
{
attributes: {
isOn,
},
},
],
})
.json()
},
async setAttributes({
id,
attributes,
transitionTime,
}: {
id: string
attributes: Partial<Device['attributes']>
transitionTime?: number
}) {
await got
.patch(`devices/set/${id}`, {
json: [
{
attributes,
transitionTime,
},
],
})
.json()
},
}
}