Skip to content

Commit

Permalink
api: add support for retrieving boiler system information
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Oct 31, 2024
1 parent 8bc23a3 commit 998dd31
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
AirComfort,
AirComfortDetailed,
AwayConfiguration,
BoilerSystemInformation,
Country,
DeepPartial,
DefaultOverlay,
Expand Down Expand Up @@ -1317,4 +1318,21 @@ export class Tado {
getHomeHeatingSystem(home_id: number): Promise<HeatingSystem> {
return this.apiCall(`/api/v2/homes/${home_id}/heatingSystem`);
}

async getBoilerSystemInformation(system_id: number): Promise<BoilerSystemInformation> {
type getBoilerSystemInformationResponse = {
data: {
system: BoilerSystemInformation;
};
};

const response = await this.apiCall<getBoilerSystemInformationResponse>(
`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;
}
}
15 changes: 15 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
};
23 changes: 23 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
});
});
18 changes: 18 additions & 0 deletions test/response.boilerInformation.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
}

0 comments on commit 998dd31

Please sign in to comment.