dirigera
Version:
A TypeScript client for IKEA's DIRIGERA smart home hub
83 lines (82 loc) • 2.35 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.type === 'outlet');
},
async get({ id }) {
const device = await got.get(`devices/${id}`).json();
if (device.type !== 'outlet') {
throw new Error('The requested device is not an outlet');
}
return device;
},
async setIsOn({ id, isOn }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
isOn,
},
},
],
})
.json();
},
async setStartupOnOff({ id, startupOnOff, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
startupOnOff,
},
},
],
})
.json();
},
async setStatusLight({ id, statusLight, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
statusLight,
},
},
],
})
.json();
},
async setChildLock({ id, childLock, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
childLock,
},
},
],
})
.json();
},
async resetEnergyConsumption({ id }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
energyConsumedAtLastReset: 0,
},
},
],
})
.json();
},
};
};