Skip to content

Commit

Permalink
see issue #208: timeframe can be disabled by user (optionally)
Browse files Browse the repository at this point in the history
  • Loading branch information
rg-engineering committed Feb 12, 2024
1 parent eb10fa6 commit b46429c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ An description about general usage of energy requests see [SMA docu](docu/SMA/SS
### **WORK IN PROGRESS**
* (René) bug fix: see issue #206 - wallbox OID's selectable
* (René) bug fix: see issue #207 - wallbox maximum charge time adjustable
* (René) see issue #208: timeframe can be disabled by user (optionally)

### 1.3.15 (2024-02-03)
* (René) bug fix: wallbox counter and status are not handled
Expand Down
4 changes: 2 additions & 2 deletions lib/semp/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class Gateway {
return this.devices.get(id);
}

getAllDevices() {
async getAllDevices() {
const ds = [];
try {
this.parentAdapter.log.debug("get all devices ");
Expand All @@ -304,7 +304,7 @@ class Gateway {
let requests = [];

if (dev.planningrequest != null) {
requests = dev.planningrequest.getPlanningrequestData();
requests = await dev.planningrequest.getPlanningrequestData();

for (let r = 0; r < requests.length; r++) {
requests[r].DeviceId = d.deviceInfo.Identification.DeviceId;
Expand Down
4 changes: 2 additions & 2 deletions lib/semp/Planningrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ class Planningrequest {
}


getPlanningrequestData() {
async getPlanningrequestData() {

const PlanningrequestData = [];

if (this.WallboxPlugConnected || this.settings.DeviceType != "EVCharger") {
for (let t = 0; t < this.timeframes.length; t++) {
const timeframeData = this.timeframes[t].getTimeframeData();
const timeframeData = await this.timeframes[t].getTimeframeData();
if (timeframeData != null) {
PlanningrequestData.push(timeframeData);
}
Expand Down
73 changes: 56 additions & 17 deletions lib/semp/Timeframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,41 @@ class Timeframe {
}
}

getTimeframeData() {
async getTimeframeData() {

let timeframeData = null;
if (this.EarliestStart > 0 || this.LatestEnd > 0) {
timeframeData = {

TimeframeId: this.settings.ID,
DeviceId: "", //to be filled later
EarliestStart: this.EarliestStart,
LatestEnd: this.LatestEnd,
MinRunningTime: this.MinRunningTime,
MaxRunningTime: this.MaxRunningTime,
};
}

this.parentAdapter.log.debug(this.deviceName + " ( " + this.settings.ID + ") timeframe data " + JSON.stringify(timeframeData));
const key = "Devices." + this.deviceName + ".TimeFrames." + this.settings.ID + ".active";

const current = await this.parentAdapter.getStateAsync(key);

if (current != null) {
if (current.val == true) {
if (this.EarliestStart > 0 || this.LatestEnd > 0) {
timeframeData = {

const key = "Devices." + this.deviceName + ".TimeFrames." + this.settings.ID + ".LastSent";
TimeframeId: this.settings.ID,
DeviceId: "", //to be filled later
EarliestStart: this.EarliestStart,
LatestEnd: this.LatestEnd,
MinRunningTime: this.MinRunningTime,
MaxRunningTime: this.MaxRunningTime,
};
}

this.parentAdapter.setState(key, { ack: true, val: JSON.stringify(timeframeData) });
this.parentAdapter.log.debug(this.deviceName + " ( " + this.settings.ID + ") timeframe data " + JSON.stringify(timeframeData));

const key = "Devices." + this.deviceName + ".TimeFrames." + this.settings.ID + ".LastSent";

await this.parentAdapter.setStateAsync(key, { ack: true, val: JSON.stringify(timeframeData) });
}
else {
this.parentAdapter.log.debug(this.deviceName + " ( " + this.settings.ID + ") timeframe disabled by user ");
}
}
else {
this.parentAdapter.log.error(this.deviceName + " ( " + this.settings.ID + ") timeframe active not readable ");
}


return timeframeData;
Expand Down Expand Up @@ -298,8 +313,6 @@ class Timeframe {
const now = new Date();
const dayOfWeek = now.getDay();
this.CanceledOnDay = dayOfWeek;


}
}

Expand Down Expand Up @@ -367,6 +380,22 @@ class Timeframe {
};
await this.CreateObject(key, obj);

key = "Devices." + this.deviceName + ".TimeFrames." + this.settings.ID + ".active";
obj = {
type: "state",
common: {
name: "timeframe is active",
type: "boolean",
role: "value",
unit: "",
read: true,
write: true,
desc: "switch to enable / disable timeframe"
}
};
await this.CreateObject(key, obj);
this.SetDefault(key, "true");

}

async CreateObject(key, obj) {
Expand Down Expand Up @@ -404,6 +433,16 @@ class Timeframe {
}
}

async SetDefault(key, value) {
const current = await this.parentAdapter.getStateAsync(key);
//set default only if nothing was set before
if (current === null || current === undefined || current.val === undefined) {
this.parentAdapter.log.info("set default " + key + " to " + value);
await this.parentAdapter.setStateAsync(key, { ack: true, val: value });
}
}


UpdateObjects() {
let Hour = Math.floor(this.CurrentOnTime / 60 / 60);
let Minutes = Math.floor((this.CurrentOnTime - (Hour * 60 * 60)) / 60);
Expand Down
4 changes: 2 additions & 2 deletions lib/semp/TimeframeWallbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class TimeframeWallbox {
}
}

getTimeframeData() {
async getTimeframeData() {

let timeframeData = null;
if (this.EarliestStart > 0 || this.LatestEnd > 0) {
Expand All @@ -176,7 +176,7 @@ class TimeframeWallbox {

const key = "Devices." + this.deviceName + ".TimeFrames." + this.ID + ".LastSent";

this.parentAdapter.setState(key, { ack: true, val: JSON.stringify(timeframeData) });
await this.parentAdapter.setStateAsync(key, { ack: true, val: JSON.stringify(timeframeData) });

return timeframeData;
}
Expand Down

0 comments on commit b46429c

Please sign in to comment.