Skip to content

Commit

Permalink
Update main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
kodibrain authored Dec 26, 2024
1 parent e53b4e9 commit b462d7a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,23 @@ class Bambulab extends utils.Adapter {
}
}

// Translate home_flag to door state
if (message.print.home_flag === 14796168) {
message.print.doorOpen = true;
} else if (message.print.home_flag === 6407560) {
message.print.doorOpen = false;
}
// Translate home_flag to door state based on the difference with previous value
if (this.previousHomeFlag === null) {
this.previousHomeFlag = message.print.home_flag;
} else {
// Calculate the difference between current and previous home_flag
const difference = message.print.home_flag - this.previousHomeFlag;

// Check if the door is open or closed based on the difference
if (difference === 8388608) {
message.print.doorOpen = true;
} else if (difference === -8388608) {
message.print.doorOpen = false;
}

// Update the previousHomeFlag
this.previousHomeFlag = message.print.home_flag;
}

// Explore JSON & create states
const returnJONexplorer = await jsonExplorer.traverseJson(message.print, this.config.serial, false, false, 0);
Expand Down

0 comments on commit b462d7a

Please sign in to comment.