Skip to content

Commit

Permalink
add initial inspelning support
Browse files Browse the repository at this point in the history
  • Loading branch information
lpgera committed Sep 28, 2024
1 parent c8c53b1 commit 667ede0
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ await client.outlets.setStartupOnOff({
id: 'YOUR_DEVICE_ID',
startupOnOff: 'startOn', // 'startOn' | 'startPrevious'
})

await client.outlet.setStatusLight({
id: 'YOUR_DEVICE_ID',
statusLight: false,
})

await client.outlet.setChildLock({
id: 'YOUR_DEVICE_ID',
childLock: true,
})
```

#### [Open/close sensors](./src/api/openCloseSensors.ts)
Expand Down
40 changes: 40 additions & 0 deletions src/api/outlets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,45 @@ export default (got: Got) => {
})
.json()
},

async setStatusLight({
id,
statusLight,
}: {
id: string
statusLight: Outlet['attributes']['statusLight']
}) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
statusLight,
},
},
],
})
.json()
},

async setChildLock({
id,
childLock,
}: {
id: string
childLock: Outlet['attributes']['childLock']
}) {
await got
.patch(`devices/${id}`, {
json: [
{
attributes: {
childLock,
},
},
],
})
.json()
},
}
}
10 changes: 10 additions & 0 deletions src/types/device/Outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ export interface OutletAttributes
isOn: boolean
startupOnOff: 'startOn' | 'startPrevious'
lightLevel: number
startUpCurrentLevel?: number
currentActivePower?: number
energyConsumedAtLastReset?: number
currentAmps?: number
currentVoltage?: number
timeOfLastEnergyReset?: string
totalEnergyConsumed?: number
totalEnergyConsumedLastUpdated?: string
childLock?: boolean
statusLight?: boolean
}

export interface Outlet extends Device {
Expand Down
5 changes: 3 additions & 2 deletions test/responses/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { environmentSensor } from './environmentSensor'
import { colorTemperatureLight, dimmableLight, rgbLight } from './light'
import { motionSensor1, motionSensor2 } from './motionSensor'
import { outlet } from './outlet'
import { outlet1, outlet2 } from './outlet'
import { repeater } from './repeater'
import { speaker } from './speaker'
import { hostUser, memberUser } from './user'
Expand All @@ -33,7 +33,8 @@ const home: Home = {
dimmableLight,
motionSensor1,
motionSensor2,
outlet,
outlet1,
outlet2,
repeater,
speaker,
],
Expand Down
66 changes: 63 additions & 3 deletions test/responses/outlet.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Outlet } from '../../src'

export const outlet: Outlet = {
export const outlet1: Outlet = {
id: '00000000-0000-0000-0000-000000000000',
type: 'outlet',
deviceType: 'outlet',
createdAt: '2000-01-01T00:00:00.000Z',
isReachable: true,
lastSeen: '2000-01-01T00:00:00.000Z',
attributes: {
customName: 'Christmas lights',
customName: 'Custom name',
model: 'TRADFRI control outlet',
manufacturer: 'IKEA of Sweden',
firmwareVersion: '2.3.089',
Expand Down Expand Up @@ -43,6 +43,66 @@ export const outlet: Outlet = {
isHidden: false,
}

export const outlet2: Outlet = {
id: '00000000-0000-0000-0000-000000000000',
type: 'outlet',
deviceType: 'outlet',
createdAt: '2000-01-01T00:00:00.000Z',
isReachable: true,
lastSeen: '2000-01-01T00:00:00.000Z',
attributes: {
customName: 'Custom name',
firmwareVersion: '2.4.45',
hardwareVersion: '1',
manufacturer: 'IKEA of Sweden',
model: 'INSPELNING Smart plug',
productCode: 'E2206',
serialNumber: '00000000-0000-0000-0000-000000000000',
isOn: false,
startupOnOff: 'startPrevious',
lightLevel: 41,
startUpCurrentLevel: -1,
currentActivePower: 0,
energyConsumedAtLastReset: 0,
currentAmps: 0.1,
currentVoltage: 230,
timeOfLastEnergyReset: '2000-01-01T00:00:00.000Z',
totalEnergyConsumed: 0.5,
totalEnergyConsumedLastUpdated: '2000-01-01T00:00:00.000Z',
childLock: false,
statusLight: false,
identifyPeriod: 0,
identifyStarted: '2000-01-01T00:00:00.000Z',
permittingJoin: false,
otaPolicy: 'autoUpdate',
otaProgress: 0,
otaScheduleEnd: '00:00',
otaScheduleStart: '00:00',
otaState: 'readyToCheck',
otaStatus: 'upToDate',
},
capabilities: {
canSend: [],
canReceive: [
'customName',
'isOn',
'lightLevel',
'energyConsumedAtLastReset',
'childLock',
'statusLight',
],
},
room: {
id: '00000000-0000-0000-0000-000000000000',
name: 'Room',
color: 'ikea_green_no_65',
icon: 'rooms_arm_chair',
},
deviceSet: [],
remoteLinks: [],
isHidden: false,
}

const outletWithoutRoom: Outlet = {
id: '00000000-0000-0000-0000-000000000000',
type: 'outlet',
Expand All @@ -51,7 +111,7 @@ const outletWithoutRoom: Outlet = {
isReachable: true,
lastSeen: '2000-01-01T00:00:00.000Z',
attributes: {
customName: 'Christmas lights',
customName: 'Custom name',
model: 'TRADFRI control outlet',
manufacturer: 'IKEA of Sweden',
firmwareVersion: '2.3.089',
Expand Down

0 comments on commit 667ede0

Please sign in to comment.