dirigera
Version:
A TypeScript client for IKEA's DIRIGERA smart home hub
87 lines (86 loc) • 2.57 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 === 'light');
},
async get({ id }) {
const device = await got.get(`devices/${id}`).json();
if (device.type !== 'light') {
throw new Error('The requested device is not a light');
}
return device;
},
async setIsOn({ id, isOn }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
isOn,
},
},
],
})
.json();
},
async setLightLevel({ id, lightLevel, transitionTime, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
lightLevel,
},
transitionTime,
},
],
})
.json();
},
async setLightTemperature({ id, colorTemperature, transitionTime, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
colorTemperature,
},
transitionTime,
},
],
})
.json();
},
async setLightColor({ id, colorHue, colorSaturation, transitionTime, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
colorHue,
colorSaturation,
},
transitionTime,
},
],
})
.json();
},
async setStartupOnOff({ id, startupOnOff, }) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
startupOnOff,
},
},
],
})
.json();
},
};
};