Skip to content

Commit 32aa59f

Browse files
committed
feat: add enable and disable methods to RulesEndpoint
Adds support for the rule status endpoints (PUT /rules/{id}/status/enable and PUT /rules/{id}/status/disable). These endpoints are available in the SmartThings public Postman workspace but were not previously exposed in this SDK. Verified against the live API: both calls return 204 and toggle the rule's status field between Enabled and Disabled. First step toward SmartThingsCommunity/smartthings-cli#500.
1 parent f42c4cc commit 32aa59f

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

.changeset/witty-rules-toggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@smartthings/core-sdk': minor
3+
---
4+
5+
Add enable and disable methods to RulesEndpoint

src/endpoint/rules.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,24 @@ export class RulesEndpoint extends Endpoint {
414414
public async execute(id: string, locationId?: string): Promise<RuleExecutionResponse> {
415415
return this.client.post(`execute/${id}`, undefined, { locationId: this.locationId(locationId) })
416416
}
417+
418+
/**
419+
* Enable a rule
420+
* @param id UUID of the rule
421+
* @param locationId UUID of the location, If the client is configured with a location ID this parameter
422+
* can be omitted
423+
*/
424+
public async enable(id: string, locationId?: string): Promise<void> {
425+
await this.client.put(`${id}/status/enable`, undefined, { locationId: this.locationId(locationId) })
426+
}
427+
428+
/**
429+
* Disable a rule
430+
* @param id UUID of the rule
431+
* @param locationId UUID of the location, If the client is configured with a location ID this parameter
432+
* can be omitted
433+
*/
434+
public async disable(id: string, locationId?: string): Promise<void> {
435+
await this.client.put(`${id}/status/disable`, undefined, { locationId: this.locationId(locationId) })
436+
}
417437
}

test/unit/rules.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,26 @@ describe('RulesEndpoint', () => {
8686
expect(postSpy).toHaveBeenCalledTimes(1)
8787
expect(postSpy).toHaveBeenCalledWith('execute/id-of-rule-to-execute', undefined, { locationId: 'final-location-id' })
8888
})
89+
90+
test('enable', async () => {
91+
putSpy.mockResolvedValueOnce(undefined)
92+
93+
await rulesEndpoint.enable('id-of-rule-to-enable', 'input-location-id')
94+
95+
expect(putSpy).toHaveBeenCalledTimes(1)
96+
expect(putSpy).toHaveBeenCalledWith('id-of-rule-to-enable/status/enable', undefined, { locationId: 'final-location-id' })
97+
expect(locationIdMock).toHaveBeenCalledTimes(1)
98+
expect(locationIdMock).toHaveBeenCalledWith('input-location-id')
99+
})
100+
101+
test('disable', async () => {
102+
putSpy.mockResolvedValueOnce(undefined)
103+
104+
await rulesEndpoint.disable('id-of-rule-to-disable', 'input-location-id')
105+
106+
expect(putSpy).toHaveBeenCalledTimes(1)
107+
expect(putSpy).toHaveBeenCalledWith('id-of-rule-to-disable/status/disable', undefined, { locationId: 'final-location-id' })
108+
expect(locationIdMock).toHaveBeenCalledTimes(1)
109+
expect(locationIdMock).toHaveBeenCalledWith('input-location-id')
110+
})
89111
})

0 commit comments

Comments
 (0)