Skip to content

Commit

Permalink
add room management endpoints and improve room typing
Browse files Browse the repository at this point in the history
  • Loading branch information
lpgera committed Jan 28, 2024
1 parent 44d2f04 commit bc21ad6
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 27 deletions.
52 changes: 47 additions & 5 deletions src/api/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,53 @@ export default (got: Got) => {
return await got.get(`rooms/${id}`).json<Room>()
},

// TODO add room management API
// * createRoom
// * deleteRoom
// * moveRoomDevices
// * updateRoom
async createRoom({
name,
icon,
color,
}: Pick<Room, 'name' | 'icon' | 'color'>) {
return await got
.post(`rooms`, {
json: {
name,
icon,
color,
},
})
.json<Room>()
},

async deleteRoom({ id }: { id: string }) {
await got.delete(`rooms/${id}`)
},

async updateRoom({ id, name, icon, color }: Room) {
await got
.put(`rooms/${id}`, {
json: {
name,
icon,
color,
},
})
.json<Room>()
},

async moveRoomDevices({
id,
deviceIds,
}: {
id: string
deviceIds: string[]
}) {
await got
.patch(`rooms/${id}/devices`, {
json: {
deviceIds,
},
})
.json()
},

async setIsOn({
id,
Expand Down
90 changes: 88 additions & 2 deletions src/types/Room.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,92 @@
export interface Room {
id: string
name: string
color: string
icon: string
color:
| 'ikea_green_no_65'
| 'ikea_yellow_no_24'
| 'ncs_s_1020_r10b'
| 'ikea_red_no_39'
| 'ikea_blue_no_58'
| 'ikea_lilac_no_3'
| 'ikea_orange_no_11'
| 'ikea_yellow_no_31'
| 'pantone_16_0230_tcx'
| 'ikea_brown_no_41'
| 'ikea_yellow_no_28'
| 'ikea_blue_no_63'
| 'ikea_pink_no_4'
| 'ikea_beige_1'
| 'pantone_16_0940_tcx'
| 'pantone_15_0522_tcx'
| 'ikea_green_no_66'
| 'ikea_blue_no_60'
| 'ikea_pink_no_6'
| 'ncs_s_4010_g10y'
| 'ikea_turquoise_5'
| 'ikea_beige_no_3'
| 'ikea_pink_no_8'
| 'ikea_yellow_no_27'
| 'ikea_beige_no_4'
| 'ikea_blue_no_52'
| 'ikea_white_no_20'
| 'ikea_yellow_no_30'
| 'ikea_green_no_63'
icon:
| 'rooms_arm_chair'
| 'rooms_bathtub'
| 'rooms_bed'
| 'rooms_bedside_table'
| 'rooms_bike'
| 'rooms_book_case'
| 'rooms_box'
| 'rooms_bunk_bed'
| 'rooms_car'
| 'rooms_chair'
| 'rooms_clapper'
| 'rooms_coat_hanger'
| 'rooms_coat_rack'
| 'rooms_cutlery'
| 'rooms_desk'
| 'rooms_display'
| 'rooms_dog'
| 'rooms_door'
| 'rooms_drill'
| 'rooms_fence'
| 'rooms_fireplace'
| 'rooms_fish'
| 'rooms_flower'
| 'rooms_game_pad'
| 'rooms_heart'
| 'rooms_home'
| 'rooms_hot_drink'
| 'rooms_iron'
| 'rooms_kitchen'
| 'rooms_ladle'
| 'rooms_mobile'
| 'rooms_motor_bike'
| 'rooms_mower'
| 'rooms_office_chair'
| 'rooms_paper_towels'
| 'rooms_parasol'
| 'rooms_play_area'
| 'rooms_pool_ladder'
| 'rooms_pot_plant'
| 'rooms_pot_with_lid'
| 'rooms_pram'
| 'rooms_printer'
| 'rooms_restroom_baby_care'
| 'rooms_sewing_machine'
| 'rooms_shower'
| 'rooms_sideboard'
| 'rooms_sink'
| 'rooms_sofa'
| 'rooms_stairway'
| 'rooms_strainer'
| 'rooms_t_shirt'
| 'rooms_teddy'
| 'rooms_toothbrush'
| 'rooms_wardrobe'
| 'rooms_washing_machine'
| 'rooms_weights'
| 'rooms_wrench'
}
2 changes: 0 additions & 2 deletions src/types/device/AirPurifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
JoinableDeviceAttributes,
OtaUpdatableDeviceAttributes,
} from './Device'
import type { Room } from '../Room'

export interface AirPurifierAttributes
extends CommonDeviceAttributes,
Expand All @@ -28,6 +27,5 @@ export interface AirPurifier extends Device {
type: 'airPurifier'
deviceType: 'airPurifier'
attributes: AirPurifierAttributes
room: Room
isHidden: boolean
}
2 changes: 0 additions & 2 deletions src/types/device/Blinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
JoinableDeviceAttributes,
OtaUpdatableDeviceAttributes,
} from './Device'
import type { Room } from '../Room'

export interface BlindsAttributes
extends CommonDeviceAttributes,
Expand All @@ -20,6 +19,5 @@ export interface Blinds extends Device {
type: 'blinds'
deviceType: 'blinds'
attributes: BlindsAttributes
room: Room
isHidden: boolean
}
2 changes: 0 additions & 2 deletions src/types/device/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
JoinableDeviceAttributes,
OtaUpdatableDeviceAttributes,
} from './Device'
import type { Room } from '../Room'

// TODO specific attributes for each controller type
export interface ControllerAttributes
Expand All @@ -25,6 +24,5 @@ export interface Controller extends Device {
| 'soundController'
| 'blindsController'
attributes: ControllerAttributes
room: Room
isHidden: boolean
}
2 changes: 0 additions & 2 deletions src/types/device/EnvironmentSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
JoinableDeviceAttributes,
OtaUpdatableDeviceAttributes,
} from './Device'
import type { Room } from '../Room'

export interface EnvironmentSensorAttributes
extends CommonDeviceAttributes,
Expand All @@ -24,6 +23,5 @@ export interface EnvironmentSensor extends Device {
type: 'sensor'
deviceType: 'environmentSensor'
attributes: EnvironmentSensorAttributes
room: Room
isHidden: boolean
}
2 changes: 0 additions & 2 deletions src/types/device/Light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
JoinableDeviceAttributes,
OtaUpdatableDeviceAttributes,
} from './Device'
import type { Room } from '../Room'

export interface LightAttributes
extends CommonDeviceAttributes,
Expand All @@ -31,6 +30,5 @@ export interface Light extends Device {
type: 'light'
deviceType: 'light'
attributes: LightAttributes
room: Room
isHidden: boolean
}
2 changes: 0 additions & 2 deletions src/types/device/MotionSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
JoinableDeviceAttributes,
OtaUpdatableDeviceAttributes,
} from './Device'
import type { Room } from '../Room'

export interface MotionSensorAttributes
extends CommonDeviceAttributes,
Expand All @@ -30,6 +29,5 @@ export interface MotionSensor extends Device {
type: 'sensor'
deviceType: 'motionSensor'
attributes: MotionSensorAttributes
room: Room
isHidden: boolean
}
2 changes: 0 additions & 2 deletions src/types/device/OpenCloseSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
IdentifiableDeviceAttributes,
JoinableDeviceAttributes,
} from './Device'
import type { Room } from '../Room'

export interface OpenCloseSensorAttributes
extends CommonDeviceAttributes,
Expand All @@ -18,6 +17,5 @@ export interface OpenCloseSensor extends Device {
type: 'sensor'
deviceType: 'openCloseSensor'
attributes: OpenCloseSensorAttributes
room: Room
isHidden: boolean
}
2 changes: 0 additions & 2 deletions src/types/device/Outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
JoinableDeviceAttributes,
OtaUpdatableDeviceAttributes,
} from './Device'
import type { Room } from '../Room'

export interface OutletAttributes
extends CommonDeviceAttributes,
Expand All @@ -21,6 +20,5 @@ export interface Outlet extends Device {
type: 'outlet'
deviceType: 'outlet'
attributes: OutletAttributes
room: Room
isHidden: boolean
}
2 changes: 0 additions & 2 deletions src/types/device/Repeater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
JoinableDeviceAttributes,
OtaUpdatableDeviceAttributes,
} from './Device'
import type { Room } from '../Room'

export interface RepeaterAttributes
extends CommonDeviceAttributes,
Expand All @@ -17,6 +16,5 @@ export interface Repeater extends Device {
type: 'repeater'
deviceType: 'repeater'
attributes: RepeaterAttributes
room: Room
isHidden: boolean
}
2 changes: 0 additions & 2 deletions src/types/device/Speaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
IdentifiableDeviceAttributes,
} from './Device'
import type { MusicPlayItem } from '../Music'
import type { Room } from '../Room'

export interface SpeakerAttributes
extends CommonDeviceAttributes,
Expand Down Expand Up @@ -59,6 +58,5 @@ export interface Speaker extends Device {
type: 'speaker'
deviceType: 'speaker'
attributes: SpeakerAttributes
room: Room
isHidden: boolean
}
39 changes: 39 additions & 0 deletions test/responses/outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,42 @@ export const outlet: Outlet = {
remoteLinks: [],
isHidden: false,
}

const outletWithoutRoom: Outlet = {
id: '25abea0e-2353-4b5d-9226-057c32825c5c_1',
type: 'outlet',
deviceType: 'outlet',
createdAt: '2022-12-11T13:55:04.000Z',
isReachable: true,
lastSeen: '2024-01-28T10:01:33.000Z',
attributes: {
customName: 'Repeater',
model: 'TRADFRI control outlet',
manufacturer: 'IKEA of Sweden',
firmwareVersion: '2.3.089',
hardwareVersion: '1',
serialNumber: '000B3CFFFEF6CAE1',
productCode: 'E1603',
isOn: false,
startupOnOff: 'startPrevious',
lightLevel: 1,
identifyStarted: '2000-01-01T00:00:00.000Z',
identifyPeriod: 0,
permittingJoin: false,
otaStatus: 'upToDate',
otaState: 'readyToCheck',
otaProgress: 0,
otaPolicy: 'autoUpdate',
otaScheduleStart: '00:00',
otaScheduleEnd: '00:00',
},
capabilities: {
canSend: [],
canReceive: ['customName', 'isOn', 'lightLevel'],
},
deviceSet: [],
remoteLinks: [],
isHidden: false,
}

outletWithoutRoom

0 comments on commit bc21ad6

Please sign in to comment.