Skip to content

Commit

Permalink
Allow setting multiple attributes in a single API call
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTerBeke committed Apr 24, 2024
1 parent ec5582a commit af1b695
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 4 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"connectivity": [
"lan"
],
"images": {
"small": "/drivers/uponor/assets/images/small.png",
"large": "/drivers/uponor/assets/images/large.png"
},
"pair": [
{
"id": "list_devices",
Expand Down
16 changes: 5 additions & 11 deletions lib/UponorHTTPClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,20 @@ export class UponorHTTPClient {
public async setTargetTemperature(controllerID: number, thermostatID: number, value: number): Promise<void> {
const fahrenheit = (value * 9 / 5) + 32
const setPoint = round(fahrenheit * 10, 0).toString()
await this._setAttribute(`C${controllerID}_T${thermostatID}_setpoint`, setPoint)
await this._setAttributes(new Map([[`C${controllerID}_T${thermostatID}_setpoint`, setPoint]]))
}

public async setMode(controllerID: number, thermostatID: number, value: Mode): Promise<void> {
// TODO: convert value to correct heat/cool/eco/holiday/comfort attributes
// await this._setAttribute("", "")
}

private async _setAttribute(key: string, value: string): Promise<void> {
const body = JSON.stringify({
"vars": [
{ "waspVarName": key, "waspVarValue": value },
]
})
private async _setAttributes(attributes: Map<string, string>): Promise<void> {
const vars = Array.from(attributes, ([key, value]) => [{ "waspVarName": key, "waspVarValue": value }]).flat()
const request = await fetch(this._url, {
method: 'POST',
headers: {
'x-jnap-action': 'http://phyn.com/jnap/uponorsky/SetAttributes'
},
body: body,
headers: { 'x-jnap-action': 'http://phyn.com/jnap/uponorsky/SetAttributes' },
body: JSON.stringify({ "vars": vars }),
})
const data: AttributesResponse = await request.json() as AttributesResponse
if (data.result != 'OK') {
Expand Down

0 comments on commit af1b695

Please sign in to comment.