dirigera
Version:
A TypeScript client for IKEA's DIRIGERA smart home hub
61 lines (60 loc) • 1.81 kB
JavaScript
export default (got) => {
return {
async list() {
const devices = await got.get(`devices`).json();
return devices.filter((d) => d.deviceType === 'occupancySensor');
},
async get({ id }) {
const device = await got.get(`devices/${id}`).json();
if (device.deviceType !== 'occupancySensor') {
throw new Error('The requested device is not a motionSensor');
}
return device;
},
async setOnDuration({ id, onDuration, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
sensorConfig: {
onDuration,
},
},
},
],
})
.json();
},
async setScheduleOn({ id, scheduleOn, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
sensorConfig: {
scheduleOn,
},
},
},
],
})
.json();
},
async setSchedule({ id, schedule, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
sensorConfig: {
schedule,
},
},
},
],
})
.json();
},
};
};