Skip to content

Commit

Permalink
api: support mobile device geo-location config
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Nov 1, 2024
1 parent 5333787 commit b53b5c6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
IQUnit,
Me,
MobileDevice,
MobileDeviceGeoLocationConfig,
MobileDeviceSettings,
Power,
PushNotificationRegistration,
Expand Down Expand Up @@ -457,6 +458,22 @@ export class Tado {
);
}

/**
* Fetches the geo-location configuration for a specific mobile device in a home.
*
* @param home_id - The unique identifier of the home.
* @param mobile_device_id - The unique identifier of the mobile device.
* @returns A promise that resolves to the mobile device's geo-location configuration.
*/
getMobileDeviceGeoLocationConfig(
home_id: number,
mobile_device_id: number,
): Promise<MobileDeviceGeoLocationConfig> {
return this.apiCall(
`/api/v2/homes/${home_id}/mobileDevices/${mobile_device_id}/geoLocationConfig`,
);
}

/**
* Fetches the zones for a given home.
*
Expand Down
17 changes: 17 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ export type MobileDevice = {
deviceMetadata: MobileDeviceMetadata;
};

export type MobileDeviceGeoLocationConfig = {
home: {
geolocation: Geolocation;
region: number;
wifiRegion: number;
};
regions: number[];
desiredAccuracy: number;
maxAccuracy: number;
distanceFilter: number;
maxAge: number;
providerUpdateInterval: number;
minIntervalBetweenSentUpdates: number;
minIntervalBetweenBackgroundUpdates: number;
wakeupInterval: number;
};

export type Me = {
name: string;
email: string;
Expand Down
24 changes: 24 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import installations_response from "./response.installations.json";
import me_response from "./response.me.json";
import mobileDevice_response from "./response.mobileDevice.json";
import mobileDevice_settings_response from "./response.mobileDevice.settings.json";
import mobileDevice_geoLocation_config_response from "./response.mobileDeviceGeoLocationConfig.json";
import mobileDevices_response from "./response.mobileDevices.json";
import mobileDevice_push_notification_registration_response from "./response.pushNotificationRegistration.json";
import state_response from "./response.state.json";
Expand Down Expand Up @@ -408,6 +409,29 @@ describe("High-level API tests", () => {
.catch(done);
});

it("Should get a mobile device geo-location config", (done) => {
nock("https://my.tado.com")
.get("/api/v2/homes/1907/mobileDevices/644583/geoLocationConfig")
.reply(200, mobileDevice_geoLocation_config_response);

tado
.getMobileDeviceGeoLocationConfig(1907, 644583)
.then((response) => {
expect(typeof response).to.equal("object");
expect(response.home).to.deep.equal({
geolocation: {
latitude: 51.2993,
longitude: 9.491,
},
region: 100,
wifiRegion: 1900,
});

done();
})
.catch(done);
});

it("Should register push notification endpoints", (done) => {
const token = "5ad64f2d-b9a2-47ff-be65-3f3f9327a775";

Expand Down
19 changes: 19 additions & 0 deletions test/response.mobileDeviceGeoLocationConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"home": {
"geolocation": {
"latitude": 51.2993,
"longitude": 9.491
},
"region": 100,
"wifiRegion": 1900
},
"regions": [124, 301, 1933, 2801, 4410],
"desiredAccuracy": 200,
"maxAccuracy": 2500,
"distanceFilter": 200,
"maxAge": 60,
"providerUpdateInterval": 300,
"minIntervalBetweenSentUpdates": 60,
"minIntervalBetweenBackgroundUpdates": 1800,
"wakeupInterval": 14400
}

0 comments on commit b53b5c6

Please sign in to comment.