diff --git a/src/index.ts b/src/index.ts index f47dba1..a49cec9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { AirComfort, AirComfortDetailed, AwayConfiguration, + BoilerSystemInformation, Country, DeepPartial, DefaultOverlay, @@ -1317,4 +1318,21 @@ export class Tado { getHomeHeatingSystem(home_id: number): Promise { return this.apiCall(`/api/v2/homes/${home_id}/heatingSystem`); } + + async getBoilerSystemInformation(system_id: number): Promise { + type getBoilerSystemInformationResponse = { + data: { + system: BoilerSystemInformation; + }; + }; + + const response = await this.apiCall( + `https://ivar.tado.com/graphql`, + "POST", + { + query: `{ system(id: ${system_id}) { modelName shortModelName: modelName(type: SHORT) thumbnail { schematic { url } } manufacturers { name } } }`, + }, + ); + return response.data.system; + } } diff --git a/src/types/index.ts b/src/types/index.ts index fcb77db..3d70204 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -902,3 +902,18 @@ export type HeatingSystem = { boiler: BoilerAvailability; underfloorHeating: UnderfloorHeatingAvailability; }; + +export type Manufacturer = { + name: string; +}; + +export type BoilerSystemInformation = { + modelName: string; + shortModelName: string; + thumbnail: { + schematic: { + url: string; + }; + }; + manufacturers: Manufacturer[]; +}; diff --git a/test/index.ts b/test/index.ts index dbce587..10dfc9c 100644 --- a/test/index.ts +++ b/test/index.ts @@ -5,6 +5,7 @@ import nock from "nock"; import { Tado } from "../src"; import auth_response from "./response.auth.json"; import away_configuration_response from "./response.away.json"; +import boiler_information_response from "./response.boilerInformation.json"; import devices_response from "./response.devices.json"; import devices_offset_response from "./response.devices.offset.json"; import eneryIQConsumptionDetails_response from "./response.energyIQConsumptionDetails.json"; @@ -831,4 +832,26 @@ describe("High-level API tests", () => { }) .catch(done); }); + + it("should get boiler system information", (done) => { + nock("https://ivar.tado.com") + .post("/graphql", (body): boolean => { + expect(body.query).to.equal( + "{ system(id: 2017) { modelName shortModelName: modelName(type: SHORT) thumbnail { schematic { url } } manufacturers { name } } }", + ); + return true; + }) + .reply(200, boiler_information_response); + + tado + .getBoilerSystemInformation(2017) + .then((response) => { + expect(typeof response).to.equal("object"); + expect(response.modelName).to.equal("ZR/ZSR/ZWR ..-2"); + expect(response.manufacturers.length).to.equal(1); + expect(response.manufacturers[0].name).to.equal("Junkers"); + done(); + }) + .catch(done); + }); }); diff --git a/test/response.boilerInformation.json b/test/response.boilerInformation.json new file mode 100644 index 0000000..92f6d81 --- /dev/null +++ b/test/response.boilerInformation.json @@ -0,0 +1,18 @@ +{ + "data": { + "system": { + "modelName": "ZR/ZSR/ZWR ..-2", + "shortModelName": "ZR/ZSR/ZWR ..-2", + "thumbnail": { + "schematic": { + "url": "https://s3-eu-west-1.amazonaws.com/hvac-files/14c1af6673c7639bbfd17ffc5fb4336dfb5e0326" + } + }, + "manufacturers": [ + { + "name": "Junkers" + } + ] + } + } +}