Skip to content

Commit

Permalink
v2.14.0 (#891)
Browse files Browse the repository at this point in the history
## [2.14.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.14.0) (2024-1-6)

### What's Changed

- Added Curtain Hold Command to OpenAPI.
  - This will only Works in 3rd Party Home App, Like [Eve](https://apps.apple.com/us/app/eve-for-homekit/id917695792) or [Home+ 5](https://apps.apple.com/us/app/home-5/id995994352)

**Full Changelog**: v2.13.2...v2.14.0
  • Loading branch information
donavanbecker authored Jan 6, 2024
1 parent 8f37713 commit 34a4f63
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)

## [2.14.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.14.0) (2024-1-6)

### What's Changed

- Added Curtain Hold Command to OpenAPI.
- This will only Works in 3rd Party Home App, Like [Eve](https://apps.apple.com/us/app/eve-for-homekit/id917695792) or [Home+ 5](https://apps.apple.com/us/app/home-5/id995994352)

**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.13.2...v2.14.0

## [2.13.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.13.2) (2024-1-5)

### What's Changed
Expand Down
4 changes: 2 additions & 2 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
@@ -1,7 +1,7 @@
{
"displayName": "SwitchBot",
"name": "@switchbot/homebridge-switchbot",
"version": "2.13.2",
"version": "2.14.0",
"description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
"author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
"license": "ISC",
Expand Down
53 changes: 50 additions & 3 deletions src/device/curtain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class Curtain {

// Characteristic Values
BatteryLevel!: CharacteristicValue;
HoldPosition!: CharacteristicValue;
PositionState!: CharacteristicValue;
TargetPosition!: CharacteristicValue;
CurrentPosition!: CharacteristicValue;
Expand Down Expand Up @@ -143,6 +144,16 @@ export class Curtain {
})
.onSet(this.TargetPositionSet.bind(this));

this.windowCoveringService
.getCharacteristic(this.platform.Characteristic.HoldPosition)
.setProps({
minStep: this.minStep(device),
minValue: 0,
maxValue: 100,
validValueRanges: [0, 100],
})
.onSet(this.HoldPositionSet.bind(this));

// Light Sensor Service
if (device.curtain?.hide_lightsensor) {
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Light Sensor Service`);
Expand Down Expand Up @@ -707,6 +718,9 @@ export class Curtain {
}

async openAPIpushChanges(): Promise<void> {
let command: string;
let parameter: string;
let commandType: string;
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
if (this.TargetPosition !== this.CurrentPosition || this.device.disableCaching) {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Pushing ${this.TargetPosition}`);
Expand All @@ -725,10 +739,19 @@ export class Curtain {
}
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Mode: ${this.Mode}`);
const adjustedMode = this.setPositionMode || 'ff';
if (this.HoldPosition) {
command = 'pause';
parameter = 'default';
commandType = 'command';
} else {
command = 'setPosition';
parameter = `0,${adjustedMode},${adjustedTargetPosition}`;
commandType = 'command';
}
const bodyChange = JSON.stringify({
command: 'setPosition',
parameter: `0,${adjustedMode},${adjustedTargetPosition}`,
commandType: 'command',
command: command,
parameter: parameter,
commandType: commandType,
});
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
try {
Expand Down Expand Up @@ -776,9 +799,14 @@ export class Curtain {
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
}

// Set HoldPosition to false when TargetPosition is changed
this.HoldPosition = false;
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.HoldPosition, this.HoldPosition);

this.TargetPosition = value;
if (this.device.mqttURL) {
this.mqttPublish('TargetPosition', this.TargetPosition);
this.mqttPublish('HoldPosition', this.HoldPosition);
}

await this.setMinMax();
Expand Down Expand Up @@ -813,6 +841,15 @@ export class Curtain {
this.doCurtainUpdate.next();
}

/**
* Handle requests to set the value of the "Target Position" characteristic
*/
async HoldPositionSet(value: CharacteristicValue): Promise<void> {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} HoldPosition: ${value}`);
this.HoldPosition = value;
this.doCurtainUpdate.next();
}

async updateHomeKitCharacteristics(): Promise<void> {
await this.setMinMax();
if (this.CurrentPosition === undefined || Number.isNaN(this.CurrentPosition)) {
Expand Down Expand Up @@ -845,6 +882,16 @@ export class Curtain {
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.TargetPosition, Number(this.TargetPosition));
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: ${this.TargetPosition}`);
}
if (this.HoldPosition === undefined) {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} HoldPosition: ${this.HoldPosition}`);
} else {
if (this.device.mqttURL) {
this.mqttPublish('HoldPosition', this.HoldPosition);
}
this.accessory.context.HoldPosition = this.HoldPosition;
this.windowCoveringService.updateCharacteristic(this.platform.Characteristic.HoldPosition, this.HoldPosition);
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic HoldPosition: ${this.HoldPosition}`);
}
if (!this.device.curtain?.hide_lightsensor) {
if (this.CurrentAmbientLightLevel === undefined || Number.isNaN(this.CurrentAmbientLightLevel)) {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentAmbientLightLevel: ${this.CurrentAmbientLightLevel}`);
Expand Down

2 comments on commit 34a4f63

@beetle1967
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get errors when I updated to this new version to v2.14 on Homebridge Log.

@donavanbecker
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get errors when I updated to this new version to v2.14 on Homebridge Log.

Open an issue.

Please sign in to comment.