dirigera
Version:
A TypeScript client for IKEA's DIRIGERA smart home hub
63 lines (62 loc) • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = (got) => {
return {
async list() {
const devices = await got.get(`devices`).json();
return devices.filter((d) => d.deviceType === 'motionSensor');
},
async get({ id }) {
const device = await got.get(`devices/${id}`).json();
if (device.deviceType !== 'motionSensor') {
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();
},
};
};