Skip to content

Commit

Permalink
Fetch parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
zapccu committed May 9, 2023
1 parent 1c325a5 commit 9980db4
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 7 deletions.
60 changes: 58 additions & 2 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,66 @@
"native": {}
},
{
"_id": "parameters",
"_id": "measurement.MeteringGridMsTotWInChaSta",
"type": "state",
"common": {
"role": "value",
"name": "Leistung Ladestation",
"type": "number",
"unit": "W",
"read": true,
"write": false,
"def": 0
},
"native": {}
},
{
"_id": "measurement.MeteringGridMsTotWhInChaSta",
"type": "state",
"common": {
"role": "value",
"name": "Zähler Ladestation",
"type": "number",
"unit": "Wh",
"read": true,
"write": false,
"def": 0
},
"native": {}
},
{
"_id": "measurement.MeteringPCCMsPlntCsmpW",
"type": "state",
"common": {
"role": "value",
"name": "Leistung Netzbezug",
"type": "number",
"unit": "W",
"read": true,
"write": false,
"def": 0
},
"native": {}
},
{
"_id": "measurement.MeteringPCCMsPlntW",
"type": "state",
"common": {
"role": "value",
"name": "Leistung Netzeinspeisung",
"type": "number",
"unit": "W",
"read": true,
"write": false,
"def": 0
},
"native": {}
},
{
"_id": "parameter",
"type": "channel",
"common": {
"name": "Parameters"
"name": "Parameter"
},
"native": {}
}
Expand Down
54 changes: 49 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ class SmaEvCharger extends utils.Adapter {
}, this.config.paramInterval * 1000);
}
}

}

//
Expand Down Expand Up @@ -232,7 +231,7 @@ class SmaEvCharger extends utils.Adapter {
this.log.info("Updating charger information");

const smaUrl = "https://" + this.config.host + "/api/v1/measurements/live";
this.log.info("Fetch Info URL = "+smaUrl);
// this.log.info("Fetch Info URL = "+smaUrl);

const body = [ {"componentId": "IGULD:SELF"} ];

Expand All @@ -247,14 +246,14 @@ class SmaEvCharger extends utils.Adapter {
data: JSON.stringify(body)
})
.then((response) => {
this.log.info(JSON.stringify(response.data));
// this.log.info(JSON.stringify(response.data));
this.setState("info.connection", true, true);

response.data.forEach(async(element) => {
const ts = Date.parse(element.values[0].time);
const val = element.values[0].value;
const elementObjects = element.channelId.split(".");
const channel = elementObjects.shift();
const channel = elementObjects.shift().toLowerCase();
const datapoint = elementObjects.join("");
const objPath = channel + "." + datapoint;
await this.setObjectNotExistsAsync(objPath, {
Expand All @@ -268,7 +267,6 @@ class SmaEvCharger extends utils.Adapter {
},
native: {},
});
// this.log.info(element.channelId + " at " + ts + " = " + val);
this.setState(channel + "." + datapoint, val, true);
});
})
Expand All @@ -284,6 +282,52 @@ class SmaEvCharger extends utils.Adapter {
async updateChargerParameters() {
this.log.info("Updating charger parameters");

const smaUrl = "https://" + this.config.host + "/api/v1/parameters/search/";
this.log.info("Fetch Parameters URL = "+smaUrl);

const body = {
"queryItems": [ { "componentId": "IGULD:SELF" } ]
}

await this.requestClient({
url: smaUrl,
method: "POST",
headers: {
"Authorization": "Bearer " + this.session.access_token,
"Accept": "*/*",
"Content-Type": "application/json"
},
data: JSON.stringify(body)
})
.then((response) => {
this.log.info(JSON.stringify(response.data));
this.setState("info.connection", true, true);

response.data[0].values.forEach(async(element) => {
const ts = Date.parse(element.timestamp);
const val = element.value;
const elementObjects = element.channelId.split(".");
const channel = elementObjects.shift().toLowerCase();
const datapoint = elementObjects.join("");
const objPath = channel + "." + datapoint;
await this.setObjectNotExistsAsync(objPath, {
type: "state",
common: {
name: datapoint,
type: "string",
role: "text",
read: true,
write: element.editable,
},
native: {},
});
this.setState(channel + "." + datapoint, val, true);
});
})
.catch((error) => {
this.log.error(error);
error.response && this.log.error(JSON.stringify(error.response.data));
});
}

/**
Expand Down

0 comments on commit 9980db4

Please sign in to comment.