From df80e246349551f35eff9d28fb54756589afcf57 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Wed, 20 Nov 2024 23:32:29 +0100 Subject: [PATCH] api: fix early start endpoints Homes do not support early start endpoints, this is only available for rooms/zones. --- src/index.ts | 49 +++++++++++++++++++++++++++++++++++++------------ test/index.ts | 8 ++++---- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/index.ts b/src/index.ts index c1c232e..b34e201 100644 --- a/src/index.ts +++ b/src/index.ts @@ -275,27 +275,24 @@ export class Tado { /** * Checks if the early start feature is enabled for a given home. * - * @param home_id - The unique identifier of the home. + * @param _home_id - The unique identifier of the home. * @returns A promise that resolves to a boolean indicating whether the early start feature is enabled. + * @deprecated This method will always return false. Use {@link isZoneEarlyStartEnabled} instead. */ - async isEarlyStartEnabled(home_id: number): Promise { - const { enabled } = await this.apiCall<{ enabled: boolean }>( - `/api/v2/homes/${home_id}/earlyStart`, - ); - return enabled; + async isEarlyStartEnabled(_home_id: number): Promise { + return false; } /** * Sets the early start feature for a specified home. * - * @param home_id - The unique identifier of the home. - * @param enabled - A boolean indicating whether the early start feature should be enabled or disabled. + * @param _home_id - The unique identifier of the home. + * @param _enabled - A boolean indicating whether the early start feature should be enabled or disabled. * @returns A promise that resolves when the early start setting has been successfully updated. + * @deprecated This method will do nothing. Use {@link setZoneEarlyStart} instead. */ - setEarlyStart(home_id: number, enabled: boolean): Promise { - return this.apiCall(`/api/v2/homes/${home_id}/earlyStart`, "PUT", { - enabled: enabled, - }); + setEarlyStart(_home_id: number, _enabled: boolean): Promise { + return Promise.resolve(); } /** @@ -578,6 +575,34 @@ export class Tado { return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/capabilities`); } + /** + * Checks if the early start feature is enabled for a given zone. + * + * @param home_id - The unique identifier of the home. + * @param zone_id - The ID of the zone whose early start feature status is to be checked. + * @returns A promise that resolves to a boolean indicating whether the early start feature is enabled. + */ + async isZoneEarlyStartEnabled(home_id: number, zone_id: number): Promise { + const { enabled } = await this.apiCall<{ enabled: boolean }>( + `/api/v2/homes/${home_id}/zones/${zone_id}/earlyStart`, + ); + return enabled; + } + + /** + * Sets the early start feature for a specified zone. + * + * @param home_id - The unique identifier of the home. + * @param zone_id - The ID of the zone whose early start feature status is to be set. + * @param enabled - A boolean indicating whether the early start feature should be enabled or disabled. + * @returns A promise that resolves when the early start setting has been successfully updated. + */ + setZoneEarlyStart(home_id: number, zone_id: number, enabled: boolean): Promise { + return this.apiCall(`/api/v2/homes/${home_id}/zones/${zone_id}/earlyStart`, "PUT", { + enabled: enabled, + }); + } + /** * Retrieves the overlay information for a specific zone within a home. * diff --git a/test/index.ts b/test/index.ts index f68725e..d24fcf0 100644 --- a/test/index.ts +++ b/test/index.ts @@ -179,24 +179,24 @@ describe("High-level API tests", () => { it("Should get early start enabled value", async () => { nock("https://my.tado.com") - .get("/api/v2/homes/1907/earlyStart") + .get("/api/v2/homes/1907/zones/1/earlyStart") .reply(200, early_start_response); - const response = await tado.isEarlyStartEnabled(1907); + const response = await tado.isZoneEarlyStartEnabled(1907, 1); expect(response).to.equal(true); }); it("Should set early state enabled value", async () => { nock("https://my.tado.com") - .put("/api/v2/homes/1907/earlyStart", (body) => { + .put("/api/v2/homes/1907/zones/1/earlyStart", (body) => { expect(Object.keys(body)).to.deep.equal(["enabled"]); expect(body.enabled).to.equal(false); return true; }) .reply(204, ""); - const response = await tado.setEarlyStart(1907, false); + const response = await tado.setZoneEarlyStart(1907, 1, false); expect(response).to.equal(""); });