From 32aa59f7a75defed1815252a18467da58238df01 Mon Sep 17 00:00:00 2001 From: Juho Date: Wed, 8 Jul 2026 13:40:16 +0900 Subject: [PATCH] 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. --- .changeset/witty-rules-toggle.md | 5 +++++ src/endpoint/rules.ts | 20 ++++++++++++++++++++ test/unit/rules.test.ts | 22 ++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 .changeset/witty-rules-toggle.md diff --git a/.changeset/witty-rules-toggle.md b/.changeset/witty-rules-toggle.md new file mode 100644 index 0000000..336fdda --- /dev/null +++ b/.changeset/witty-rules-toggle.md @@ -0,0 +1,5 @@ +--- +'@smartthings/core-sdk': minor +--- + +Add enable and disable methods to RulesEndpoint diff --git a/src/endpoint/rules.ts b/src/endpoint/rules.ts index c7128ef..af5d862 100644 --- a/src/endpoint/rules.ts +++ b/src/endpoint/rules.ts @@ -414,4 +414,24 @@ export class RulesEndpoint extends Endpoint { public async execute(id: string, locationId?: string): Promise { 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 { + 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 { + await this.client.put(`${id}/status/disable`, undefined, { locationId: this.locationId(locationId) }) + } } diff --git a/test/unit/rules.test.ts b/test/unit/rules.test.ts index 02736d5..0e3bd39 100644 --- a/test/unit/rules.test.ts +++ b/test/unit/rules.test.ts @@ -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') + }) })