Skip to content

Commit a8af498

Browse files
committed
feat: added endpoint for hub characteristics
1 parent d81ff56 commit a8af498

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/endpoint/hubdevices.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,44 @@ export interface InstalledDriver {
4646
permissions: { [name: string]: any }
4747
}
4848

49+
export interface Hub {
50+
id: string
51+
name: string
52+
eui: string
53+
owner: string
54+
serialNumber: string
55+
firmwareVersion: string
56+
}
57+
58+
export interface HubCharacteristics {
59+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
60+
[key: string]: any
61+
}
62+
4963
export class HubdevicesEndpoint extends Endpoint {
5064
constructor(config: EndpointClientConfig) {
5165
super(new EndpointClient('hubdevices', config))
5266
}
5367

5468
/**
55-
* Install driver on a hub. The primary use case of this functionality is to install a self
56-
* published driver to be included in generic discovery (e.g. scanning).
69+
* Get a hub record
70+
* @param hubId
71+
*/
72+
public async get(hubId: string): Promise<Hub> {
73+
return this.client.get(`${hubId}`)
74+
}
75+
76+
/**
77+
* Get the characteristics of a hub
78+
* @param hubId
79+
*/
80+
public async getCharacteristics(hubId: string): Promise<HubCharacteristics> {
81+
return this.client.get(`${hubId}/characteristics`)
82+
}
83+
84+
/**
85+
* Install driver on a hub. The primary use case of this functionality is to install a
86+
* self-published driver to be included in generic discovery (e.g. scanning).
5787
*/
5888
public async installDriver(driverId: string, hubId: string, channelId: string): Promise<void> {
5989
return this.client.put(`${hubId}/drivers/${driverId}`, { channelId })

test/unit/hubdevices.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ describe('HubdevicesEndpoint', () => {
1717
const authenticator = new NoOpAuthenticator()
1818
const hubdevicesEndpoint = new HubdevicesEndpoint({ authenticator })
1919

20+
test('get', async () => {
21+
putSpy.mockImplementationOnce(() => Promise.resolve())
22+
23+
await expect(hubdevicesEndpoint.get('hub-id')).resolves.not.toThrow()
24+
25+
expect(getSpy).toHaveBeenCalledTimes(1)
26+
expect(getSpy).toHaveBeenCalledWith('hub-id')
27+
})
28+
29+
test('getCharacteristics', async () => {
30+
putSpy.mockImplementationOnce(() => Promise.resolve())
31+
32+
await expect(hubdevicesEndpoint.getCharacteristics('hub-id')).resolves.not.toThrow()
33+
34+
expect(getSpy).toHaveBeenCalledTimes(1)
35+
expect(getSpy).toHaveBeenCalledWith('hub-id/characteristics')
36+
})
37+
2038
test('installDriver', async () => {
2139
putSpy.mockImplementationOnce(() => Promise.resolve())
2240

0 commit comments

Comments
 (0)