Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
add function to set thermostat
Browse files Browse the repository at this point in the history
  • Loading branch information
matthsc committed Nov 20, 2023
1 parent 3281574 commit 63ebac9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ Sends a command for an endNode, i.e. "on" or "off" for plugs. Throws if the comm
api.sendCommand(baseStationId: string, endNodeId: string, commandName: string): Promise<void>;
```

### setThermostat

Sets the setPoint for a thermostat. !completely untested due to lack of hardware!

```ts
api.setThermostat(baseStationId: string, endNodeId: string, setPoint: number): Promise<void>;
```

### setUserAlarm

Turn user alarm (panic button) on or off,
Expand Down
18 changes: 17 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,22 @@ export class GigasetElementsApi extends RequestBase {
await this.post(url.cmd(baseStationId, endNodeId), { body: { name } });
}

/**
* Update the thermostat set point
* @param baseStationId id of the base station
* @param mode alarm mode to set
*/
@Authorize
public async setThermostat(
baseStationId: string,
endNodeId: string,
setPoint: number,
): Promise<void> {
await this.put(url.thermostat(baseStationId, endNodeId), {
body: { setPoint },
});
}

/**
* Turn user alarm (panic button) on or off
* @param on whether to turn the alarm on or off
Expand All @@ -231,7 +247,7 @@ export class GigasetElementsApi extends RequestBase {
}

/**
*Updates the active alarm mode.
* Updates the active alarm mode.
* @param baseStationId id of the base station
* @param mode alarm mode to set
*/
Expand Down
21 changes: 20 additions & 1 deletion src/requestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const url = Object.freeze({
health: `${apiBase}/v3/me/health`,
cmd: (baseStationId: string, endNodeId: string) =>
`${apiBase}/v1/me/basestations/${baseStationId}/endnodes/${endNodeId}/cmd`,
thermostat: (baseStationId: string, endNodeId: string) =>
`${apiBase}/v2/me/elements/bs01.ts01/${baseStationId}.${endNodeId}/runtime-configuration`,
});

/** GE api url query parameter */
Expand Down Expand Up @@ -73,7 +75,7 @@ export class RequestBase {
* @param options request options
*/
private async makeRequest<T>(
method: "get" | "post" | "delete",
method: "get" | "post" | "put" | "delete",
uri: string,
options?: requestPromise.RequestPromiseOptions,
) {
Expand Down Expand Up @@ -126,6 +128,23 @@ export class RequestBase {
return this.makeRequest<T>("post", uri, options);
}

/**
* Helper function to perform PUT requests
* @param uri uri to request
* @param options request options
*/
public async put<T = unknown>(
uri: string,
options?: requestPromise.RequestPromiseOptions,
) {
return this.makeRequest<T>("put", uri, options);
}

/**
* Helper function to perform DELETE requests
* @param uri uri to request
* @param options request options
*/
public async delete<T = unknown>(
uri: string,
options?: requestPromise.RequestPromiseOptions,
Expand Down

0 comments on commit 63ebac9

Please sign in to comment.