Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/witty-rules-toggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@smartthings/core-sdk': minor
---

Add enable and disable methods to RulesEndpoint
20 changes: 20 additions & 0 deletions src/endpoint/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,24 @@ export class RulesEndpoint extends Endpoint {
public async execute(id: string, locationId?: string): Promise<RuleExecutionResponse> {
return this.client.post(`execute/${id}`, undefined, { locationId: this.locationId(locationId) })
}

/**
* Enable a rule
* @param id UUID of the rule
* @param locationId UUID of the location, If the client is configured with a location ID this parameter
* can be omitted
*/
public async enable(id: string, locationId?: string): Promise<void> {
await this.client.put(`${id}/status/enable`, undefined, { locationId: this.locationId(locationId) })
}

/**
* Disable a rule
* @param id UUID of the rule
* @param locationId UUID of the location, If the client is configured with a location ID this parameter
* can be omitted
*/
public async disable(id: string, locationId?: string): Promise<void> {
await this.client.put(`${id}/status/disable`, undefined, { locationId: this.locationId(locationId) })
}
}
22 changes: 22 additions & 0 deletions test/unit/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,26 @@ describe('RulesEndpoint', () => {
expect(postSpy).toHaveBeenCalledTimes(1)
expect(postSpy).toHaveBeenCalledWith('execute/id-of-rule-to-execute', undefined, { locationId: 'final-location-id' })
})

test('enable', async () => {
putSpy.mockResolvedValueOnce(undefined)

await rulesEndpoint.enable('id-of-rule-to-enable', 'input-location-id')

expect(putSpy).toHaveBeenCalledTimes(1)
expect(putSpy).toHaveBeenCalledWith('id-of-rule-to-enable/status/enable', undefined, { locationId: 'final-location-id' })
expect(locationIdMock).toHaveBeenCalledTimes(1)
expect(locationIdMock).toHaveBeenCalledWith('input-location-id')
})

test('disable', async () => {
putSpy.mockResolvedValueOnce(undefined)

await rulesEndpoint.disable('id-of-rule-to-disable', 'input-location-id')

expect(putSpy).toHaveBeenCalledTimes(1)
expect(putSpy).toHaveBeenCalledWith('id-of-rule-to-disable/status/disable', undefined, { locationId: 'final-location-id' })
expect(locationIdMock).toHaveBeenCalledTimes(1)
expect(locationIdMock).toHaveBeenCalledWith('input-location-id')
})
})