Skip to content

Commit 5670838

Browse files
committed
Finalize Wallbox step 1
1 parent d1141bd commit 5670838

3 files changed

Lines changed: 51 additions & 10 deletions

File tree

admin/jsonConfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@
155155
"disabled": "!data.enableSummarydata",
156156
"hidden": "data.apiType == 1 || data.apiType == 3"
157157
},
158+
"enableWallbox": {
159+
"type": "checkbox",
160+
"newLine": true,
161+
"hidden": "true"
162+
},
163+
"intervalWallboxMins": {
164+
"sm": 5,
165+
"min": 1,
166+
"type": "number",
167+
"label": "Interval to read wallbox data",
168+
"newLine": false,
169+
"disabled": "!data.oAEnableWallbox",
170+
"hidden": "true"
171+
},
158172
"oAEnableRealtime": {
159173
"type": "checkbox",
160174
"newLine": true,

io-package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@
182182
"intervalStatisticalTodaydataMins": 5,
183183
"enableSummarydata": false,
184184
"intervalSummarydataMins": 5,
185+
"enableWallbox": false,
186+
"intervalWallboxMins": 5,
185187
"updateUnchangedStates": false,
186188
"appID": "",
187189
"appSecret": "",

main.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -828,18 +828,15 @@ class OpenAPI {
828828
let snState = await this.adapter.getStateAsync(`${group}.SN`);
829829
if (!snState || typeof snState.val === 'string' && snState.val.length == 0) {
830830
await this.getWallboxSn(group);
831-
this.adapter.log.info('###' + `${group}.SN`);
832831
snState = await this.adapter.getStateAsync(`${group}.SN`);
833-
this.adapter.log.info('###' + `${group}.SN`);
834-
// In this special case we reset the creaton indicator because more states must be created for this group in the next step
832+
// In this special case we reset the created indicator because more states must be created for this group in the next step
835833
this.adapter.createdStates[group] = false;
836834
}
837835

838836
if (snState && typeof snState.val === 'string' && snState.val.length > 0) {
839837
this.adapter.log.debug(`Using Wallbox SN: ${snState.val}`);
840838
const res = await this.getRequest(`getEvChargerStatusBySn?sysSn=${this.adapter.config.systemId}&evchargerSn=${snState.val}`, {});
841-
if (true || res && res['status'] == 200 && res.data && res.data.data) {
842-
res.data.data = JSON.parse('{"evchargerStatus":1}');
839+
if (res && res['status'] == 200 && res.data && res.data.data) {
843840
await this.adapter.createAndUpdateStates(group, res.data.data);
844841
}
845842
else {
@@ -867,7 +864,9 @@ class OpenAPI {
867864
const res = await this.getRequest(`getEvChargerConfigList?sysSn=${this.adapter.config.systemId}`, {});
868865
if (res && res['status'] == 200 && res.data && res.data.data) {
869866

870-
res.data.data = JSON.parse('[{"evchargerSn":"ALP2021082015071x","evchargerModel":"SMILE-EVCT11"}]');
867+
if (res.data.data.length > 1) {
868+
this.adapter.log.warn('More than one wallbox found! Only the first wallbox is currently supported by this adapter!');
869+
}
871870
await this.adapter.createAndUpdateStates(group, res.data.data[0]);
872871
}
873872
else {
@@ -1637,6 +1636,15 @@ class ClosedAPI {
16371636
, unit: ''
16381637
, dayIndex: false
16391638
}]
1639+
},
1640+
{
1641+
// Just a dummy to ensure that this group is deleted
1642+
Group: 'Wallbox'
1643+
, fnct: this.fetchWallboxDataDummy.bind(this)
1644+
, enabledName: 'enableWallbox'
1645+
, intervalName: 'intervalWallboxMins'
1646+
, intervalFactor: 60
1647+
, states: []
16401648
}];
16411649

16421650
this.Auth =
@@ -1912,6 +1920,13 @@ class ClosedAPI {
19121920
this.adapter.log.warn(`Internal error (group ${group}): function fetchSettingsDischargeDataDummy should never be called.`);
19131921
}
19141922

1923+
/**
1924+
* @param {string} group
1925+
*/
1926+
async fetchWallboxDataDummy(group) {
1927+
this.adapter.log.warn(`Internal error (group ${group}): function fetchWallboxDataDummy should never be called.`);
1928+
}
1929+
19151930
/**
19161931
* Get realtime data from alpha-ess and start timer for next execution
19171932
* @param {string} group
@@ -2741,13 +2756,18 @@ class AlphaEss extends utils.Adapter {
27412756
if (!groupStates[i].isStatic) {
27422757
const newState = await this.getStateAsync(`${groupInfo.Group}.${groupStates[i].id}`);
27432758
if (newState) {
2744-
if (newState.ack) {
2759+
if (newState.q != q && newState.ack) {
27452760
newState.q = q;
27462761
this.log.debug(`Set state ${groupInfo.Group}.${groupStates[i].id} to val: ${newState.val}; q: ${newState.q}; ack: ${newState.ack}`);
27472762
await this.setStateAsync(`${groupInfo.Group}.${groupStates[i].id}`, newState, true);
27482763
}
27492764
else {
2750-
this.log.debug(`Set state ${groupInfo.Group}.${groupStates[i].id} NOT to val: ${newState.val}; q: ${newState.q} because ack of this state is ${newState.ack}`);
2765+
if (!newState.ack) {
2766+
this.log.silly(`Set state ${groupInfo.Group}.${groupStates[i].id} NOT to val: ${newState.val}; q: ${newState.q} because ack of this state is ${newState.ack}`);
2767+
}
2768+
else {
2769+
this.log.silly(`Set state ${groupInfo.Group}.${groupStates[i].id} NOT to val: ${newState.val}; q: ${newState.q} because quality is unchanged ${newState.q}`);
2770+
}
27512771
}
27522772
}
27532773
}
@@ -2775,15 +2795,20 @@ class AlphaEss extends utils.Adapter {
27752795
if (Date.now() - groupStates[i].lastUpdateTs > (groupInfo.interval * 1000 + REQUEST_TIMEOUT)) {
27762796
const newState = await this.getStateAsync(`${groupInfo.Group}.${groupStates[i].id}`);
27772797
if (newState) {
2778-
if (newState.q != 0 && newState.ack) {
2798+
if (newState.q == 0 && newState.ack) {
27792799
// Change quality only if it was OK before
27802800
newState.q = 0x01;
27812801
this.log.warn(`Watchdog: State ${groupInfo.Group}.${groupStates[i].id} not updated for ${Date.now() - groupStates[i].lastUpdateTs} ms`);
27822802
this.log.debug(`Watchdog: Set state ${groupInfo.Group}.${groupStates[i].id} to val: ${newState.val}; q: ${newState.q}`);
27832803
await this.setStateAsync(`${groupInfo.Group}.${groupStates[i].id}`, newState, true);
27842804
}
27852805
else {
2786-
this.log.silly(`Watchdog: Quality of state ${groupInfo.Group}.${groupStates[i].id} not changed, was already set to ${newState.q} and ack is ${newState.ack}!`);
2806+
if (!newState.ack) {
2807+
this.log.silly(`Set state ${groupInfo.Group}.${groupStates[i].id} NOT to val: ${newState.val}; q: ${newState.q} because ack of this state is ${newState.ack}`);
2808+
}
2809+
else {
2810+
this.log.silly(`Set state ${groupInfo.Group}.${groupStates[i].id} NOT to val: ${newState.val}; q: ${newState.q} because quality is already not OK: ${newState.q}`);
2811+
}
27872812
}
27882813
}
27892814
else {

0 commit comments

Comments
 (0)