Skip to content

Commit

Permalink
control: started even if errors occur
Browse files Browse the repository at this point in the history
  • Loading branch information
bolliy committed Jan 7, 2025
1 parent 61baf72 commit 1c5016d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 31 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ browse in the [wiki](https://github.com/bolliy/ioBroker.sun2000/wiki)
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**
* dependency and configuration updates
* control: if the battery is not running, events related to the battery are discarded
* modbus-proxy: adjusted advanced logging

### 0.18.0 (2024-12-11)
* dependency and configuration updates
Expand Down
34 changes: 21 additions & 13 deletions lib/controls/service_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ class ServiceQueueMap {
return await this._writeRegisters(47249,dataType.numToArray(event.value,dataType.uint32));
}
},
/*
{
state: { id: 'battery.targetSOC ', name: 'Target SOC', type: 'number', unit: '%', role: 'level', desc: 'reg: 47101 , len: 1'},
type : deviceType.gridPowerControl
},
*/
{
state: { id: 'battery.targetSOC', name: 'Target SOC', type: 'number', unit: '%', role: 'level', desc: 'reg: 47101 , len: 1'},
type : deviceType.battery,
Expand Down Expand Up @@ -242,7 +236,7 @@ class ServiceQueueMap {
if (this.inverterInfo.instance) {
for (const item of this.serviceFields) {
//no battery - no controls
if (item.type == deviceType.battery && this.inverterInfo.instance.numberBatteryUnits() === 0) continue;
//if (item.type == deviceType.battery && this.inverterInfo.instance.numberBatteryUnits() === 0) continue;
if (item.type == deviceType.meter && !this.inverterInfo?.meter) continue;
if (item.type == deviceType.gridPowerControl && !this.inverterInfo?.meter) continue;
if (item?.state) {
Expand All @@ -259,7 +253,7 @@ class ServiceQueueMap {
this.set(entry.state.id,state);
}
}

//upgrade
const tSOC = await this.adapter.getState(this.inverterInfo.path+'.control.battery.targetSOC ');
if (tSOC) {
await this.adapter.delObject(this.inverterInfo.path+'.control.battery.targetSOC ',{ recursive: false });
Expand Down Expand Up @@ -291,7 +285,9 @@ class ServiceQueueMap {
}
}

if (this._initialized) this.log.info('Control: Service queue initialized');
if (this._initialized) {
this.log.info('Control: Service queue initialized');
}
}

get(id) {
Expand All @@ -318,8 +314,12 @@ class ServiceQueueMap {
return this._map.values();
}

/**
* Processes the events in the eventMap. For each event, it calls the associated function in the serviceMap.
* @param {ModbusClient} modbusClient - The modbus client to use for writing the states.
*/
async process(modbusClient) {
if (!this.inverterInfo.instance.modbusAllowed) return;
//if (!this.inverterInfo.instance.modbusAllowed) return;
this._modbusClient = modbusClient;

if (this._initialized) {
Expand All @@ -329,10 +329,17 @@ class ServiceQueueMap {
const service = this._serviceMap.get(event.id);
if(!service.errorCount) service.errorCount = 0;
if (event.value !== null && service.fn) {
//check if battery is running
//check if battery is present and running
if (service.type == deviceType.battery) {
if (this.inverterInfo.instance.numberBatteryUnits() === 0) {
this.log.warn(`Control: Event is discarded because no battery has been detected. `);
if (!this.adapter.isReady) {
this.log.warn('Control: The Adapter is not ready! Please check the value in the state sun2000.x.info.JSONhealth and the Log output.');
}
this._eventMap.delete(event.id); //forget the event
continue;
}
const BatStatus = this.inverterInfo.instance.stateCache.get(this.inverterInfo.path+'.battery.runningStatus')?.value;
//
if (BatStatus !== 'RUNNING' && BatStatus !== 'STANDBY' && BatStatus !== '') {
this.log.warn(`Control: Event is discarded because battery is not running. State: ${this.inverterInfo.path}.battery.runningStatus = ${BatStatus}. `);
this._eventMap.delete(event.id); //forget the event
Expand Down Expand Up @@ -361,7 +368,8 @@ class ServiceQueueMap {
if (count > 1) break; //max 2 Events
}
}
if (!this._initialized && this.adapter.isReady) await this._init();
//if (!this._initialized && this.adapter.isReady) await this._init();
if (!this._initialized && this.adapter.isConnected) await this._init();
}

async _writeRegisters(address,data) {
Expand Down
7 changes: 6 additions & 1 deletion lib/drivers/driver_inverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,14 @@ class InverterSun2000 extends DriverBase{
}
}

//overload
/**
* #overload#
* Get the number of battery units.
* @returns {number} The number of battery units
*/
numberBatteryUnits() {
let units = 0;
//Check if the first battery unit exists
const state1 = this.stateCache.get(`${this.deviceInfo.path}.battery.unit.1.SN`);
if (state1 && state1.value) units = 1;
const state2 = this.stateCache.get(`${this.deviceInfo.path}.battery.unit.2.SN`);
Expand Down
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class Sun2000 extends utils.Adapter {
this.settings.highInterval = 10000*this.settings.modbusIds.length;
} else {
let minInterval = this.settings.modbusIds.length*this.settings.modbusDelay*2.5; //len*5*delay/2
if (this.settings.integration > 0) { //SmartLogger
if (this.settings.integration > 0) { //SmartLogger, Emma
minInterval += 5000;
} else {
for (const device of this.devices) {
Expand Down
46 changes: 31 additions & 15 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@types/chai": "^4.3.20",
"@types/chai-as-promised": "^7.1.8",
"@types/mocha": "^10.0.10",
"@types/node": "^22.10.2",
"@types/node": "^22.10.3",
"@types/proxyquire": "^1.3.31",
"@types/sinon": "^17.0.3",
"@types/sinon-chai": "^3.2.12",
Expand Down

0 comments on commit 1c5016d

Please sign in to comment.