Skip to content

Commit

Permalink
Fix BLE curtain mode (#908)
Browse files Browse the repository at this point in the history
## ♻️ Current situation

If the curtain mode was not defined in the settings the following error
would occur:
```
Curtain: Curtain failed BLEpushChanges with BLE Connection, Error Message: "The type of running mode is incorrect: object"
```

## 💡 Proposed solution

- Set position mode to strings 
- Remove redundant code
- Set proper values for node-switchbot

Co-authored-by: Donavan Becker <[email protected]>
  • Loading branch information
dnicolson and donavanbecker authored Feb 4, 2024
1 parent 8fda94b commit 1071eea
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/device/curtain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class Curtain {
OpenAPI_CurrentPosition: deviceStatus['slidePosition'];
OpenAPI_CurrentAmbientLightLevel: deviceStatus['brightness'];

// OpenAPI Others
// Others
Mode!: string;
setPositionMode?: string | number;
setPositionMode?: string;

// BLE Status
BLE_InMotion: serviceData['inMotion'];
Expand Down Expand Up @@ -662,10 +662,7 @@ export class Curtain {
.toLowerCase();
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
this.SilentPerformance();
const adjustedMode = this.setPositionMode || null;
if (adjustedMode === null) {
this.Mode = 'Default Mode';
}
const adjustedMode = this.setPositionMode == '1' ? 0x01 : 0xff;
this.debugLog(`${this.accessory.displayName} Mode: ${this.Mode}`);
if (switchbot !== false) {
try {
Expand Down Expand Up @@ -1016,18 +1013,18 @@ export class Curtain {
async SilentPerformance() {
if (Number(this.TargetPosition) > 50) {
if (this.device.curtain?.setOpenMode === '1') {
this.setPositionMode = 1;
this.setPositionMode = '1';
this.Mode = 'Silent Mode';
} else {
this.setPositionMode = 0;
this.setPositionMode = '0';
this.Mode = 'Performance Mode';
}
} else {
if (this.device.curtain?.setCloseMode === '1') {
this.setPositionMode = 1;
this.setPositionMode = '1';
this.Mode = 'Silent Mode';
} else {
this.setPositionMode = 0;
this.setPositionMode = '0';
this.Mode = 'Performance Mode';
}
}
Expand Down

0 comments on commit 1071eea

Please sign in to comment.