Skip to content

Commit

Permalink
fixed name of availability state and info.connection state
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Oct 28, 2021
1 parent 7363e33 commit a364898
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 37 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Adapter to connect an OCPP 1.6 supported wallbox
### **WORK IN PROGRESS**
-->

### **WORK IN PROGRESS**
* (foxriver76) we fixed name of availability state
* (foxriver76) we fixed unnecessary comma in `info.connection` state

### 0.0.5 (2021-10-28)
* (foxriver76) we added the meterValue state
* (foxriver76) we added state to control availability
Expand Down
2 changes: 1 addition & 1 deletion build/lib/states.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/lib/states.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 5 additions & 17 deletions build/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/lib/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const stateObjects: ioBroker.Object[] = [
_id: 'availability',
type: 'state',
common: {
name: 'Power meter value',
name: 'Switch availability',
type: 'boolean',
role: 'switch.power',
write: true,
Expand Down
22 changes: 6 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class Ocpp extends utils.Adapter {

this.log.info('Starting OCPP Server');

// reset connection state
await this.setStateAsync('info.connection', '', true);

const server = new CentralSystem();

const port = await this.getPortAsync(this.config.port);
Expand Down Expand Up @@ -81,10 +84,6 @@ class Ocpp extends utils.Adapter {
switch (true) {
case (command instanceof OCPPCommands.BootNotification):
this.log.info(`Received boot notification from "${connection.url}"`);
this.client.info = {
connectors: [],
...command
};

// device booted, extend native to object
await this.extendObjectAsync(connection.url, {
Expand Down Expand Up @@ -136,16 +135,6 @@ class Ocpp extends utils.Adapter {
// set status state
await this.setStateAsync(`${connection.url}.status`, command.status, true);

const connectorIndex = this.client.info.connectors.findIndex(item => command.connectorId === item.connectorId);
if (connectorIndex === -1) {
this.client.info.connectors.push({
...command
});
} else {
this.client.info.connectors[connectorIndex] = {
...command
};
}
return {};
case (command instanceof OCPPCommands.MeterValues):
this.log.info(`Received MeterValues from "${connection.url}"`);
Expand Down Expand Up @@ -216,7 +205,7 @@ class Ocpp extends utils.Adapter {

await this.setStateAsync(`${device}.connected`, false, true);
const connState = await this.getStateAsync('info.connection');
if (typeof connState?.val === 'string') {
if (connState?.val && typeof connState.val === 'string') {
// get devices and convert them to an array
const devices = connState.val.split(',');
const idx = devices.indexOf(device);
Expand All @@ -238,7 +227,8 @@ class Ocpp extends utils.Adapter {
const connState = await this.getStateAsync('info.connection');

if (typeof connState?.val === 'string') {
const devices = connState.val.split(',');
// if empty string make empty array
const devices = connState.val ? connState.val.split(',') : [];
if (devices.indexOf(device) === -1) {
// device not yet in array
devices.push(device);
Expand Down

0 comments on commit a364898

Please sign in to comment.