Added tilt angle support

This commit is contained in:
Serge Wagener 2022-02-15 13:44:20 +01:00
parent f7947cdc2a
commit ff5b1f37b9
2 changed files with 113 additions and 11 deletions

View File

@ -318,7 +318,7 @@ This accessory type can be used for shutters or blinds. Because the differnce be
#### Characteristics in addition to [common characteristics](#common-accessories-characteristics) #### Characteristics in addition to [common characteristics](#common-accessories-characteristics)
| Parameter | Possible values | Mandatory | Default | Description | | Parameter | Possible values | Mandatory | Default | Description |
|:------------------------|:----------------|:----------|:--------|:------------------------------------------------------------------| |:---------------------------|:----------------|:----------|:--------|:------------------------------------------------------------------|
| CurrentPosition | \<item> | Yes | | SHNG item to monitor thecurrent position | | CurrentPosition | \<item> | Yes | | SHNG item to monitor thecurrent position |
| TargetPosition | \<item> | Yes | | SHNG item to monitor and set the target position | | TargetPosition | \<item> | Yes | | SHNG item to monitor and set the target position |
| CurrentPositionMin | \<number> | No | 0 | Your device's minimum value for current position | | CurrentPositionMin | \<number> | No | 0 | Your device's minimum value for current position |
@ -327,6 +327,10 @@ This accessory type can be used for shutters or blinds. Because the differnce be
| TargetPositionMin | \<number> | No | 0 | Your device's minimum value for target position | | TargetPositionMin | \<number> | No | 0 | Your device's minimum value for target position |
| TargetPositionMax | \<number> | No | 100 | Your device's maximum value for target position | | TargetPositionMax | \<number> | No | 100 | Your device's maximum value for target position |
| TargetPositionInverted | \<boolean> | No | false | Should the values be inverted, ex: 0 for Homekit = 100 for device | | TargetPositionInverted | \<boolean> | No | false | Should the values be inverted, ex: 0 for Homekit = 100 for device |
| CurrentHorizontalTiltAngle | \<item> | No | | SHNG item to monitor current horizontal tilt angle |
| TargetHorizontalTiltAngle | \<item> | No | | SHNG item to monitor and set the target horizontal tilt angle |
| CurrentVerticalTiltAngle | \<item> | No | | SHNG item to monitor current vertical tilt angle |
| TargetVerticalTiltAngle | \<item> | No | | SHNG item to monitor and set the target vertical tilt angle |
#### Additional comments #### Additional comments

View File

@ -15,6 +15,8 @@ export class WindowCovering implements AccessoryPlugin {
private currentPosition = 0; private currentPositionMin = 0; private currentPositionMax = 100; private currentPositionInverted = false; private currentPosition = 0; private currentPositionMin = 0; private currentPositionMax = 100; private currentPositionInverted = false;
private targetPosition = 0; private targetPositionMin = 0; private targetPositionMax = 100; private targetPositionInverted = false; private targetPosition = 0; private targetPositionMin = 0; private targetPositionMax = 100; private targetPositionInverted = false;
private positionState = this.platform.Characteristic.PositionState.STOPPED; private positionState = this.platform.Characteristic.PositionState.STOPPED;
private currentHorizontalTiltAngle = 0; private targetHorizontalTiltAngle = 0;
private currentVerticalTiltAngle = 0; private targetVerticalTiltAngle = 0;
constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory) { constructor(private readonly platform: SmartHomeNGPlatform, private readonly accessory) {
this.name = accessory.name; this.name = accessory.name;
@ -28,6 +30,20 @@ export class WindowCovering implements AccessoryPlugin {
.onGet(this.getTargetPosition.bind(this)) .onGet(this.getTargetPosition.bind(this))
.onSet(this.setTargetPosition.bind(this)); .onSet(this.setTargetPosition.bind(this));
this.deviceService.getCharacteristic(this.platform.Characteristic.CurrentHorizontalTiltAngle)
.onGet(this.getCurrentHorizontalTiltAngle.bind(this));
this.deviceService.getCharacteristic(this.platform.Characteristic.TargetHorizontalTiltAngle)
.onGet(this.getTargetHorizontalTiltAngle.bind(this))
.onSet(this.setTargetHorizontalTiltAngle.bind(this));
this.deviceService.getCharacteristic(this.platform.Characteristic.CurrentVerticalTiltAngle)
.onGet(this.getCurrentVerticalTiltAngle.bind(this));
this.deviceService.getCharacteristic(this.platform.Characteristic.TargetVerticalTiltAngle)
.onGet(this.getTargetVerticalTiltAngle.bind(this))
.onSet(this.setTargetVerticalTiltAngle.bind(this));
this.deviceService.getCharacteristic(this.platform.Characteristic.PositionState) this.deviceService.getCharacteristic(this.platform.Characteristic.PositionState)
.onGet(this.getPositionState.bind(this)); .onGet(this.getPositionState.bind(this));
@ -39,6 +55,18 @@ export class WindowCovering implements AccessoryPlugin {
this.platform.shng.addMonitor(accessory.currentposition, this.shngCurrentPositionCallback.bind(this)); this.platform.shng.addMonitor(accessory.currentposition, this.shngCurrentPositionCallback.bind(this));
this.platform.shng.addMonitor(accessory.targetposition, this.shngTargetPositionCallback.bind(this)); this.platform.shng.addMonitor(accessory.targetposition, this.shngTargetPositionCallback.bind(this));
if (accessory.currenthorizontaltiltangle) {
this.platform.shng.addMonitor(accessory.currenthorizontaltiltangle, this.shngCurrentHorizontalTiltAngleCallback.bind(this));
}
if (accessory.targethorizontaltiltangle) {
this.platform.shng.addMonitor(accessory.targethorizontaltiltangle, this.shngTargetHorizontalTiltAngleCallback.bind(this));
}
if (accessory.currentverticaltiltangle) {
this.platform.shng.addMonitor(accessory.currentverticaltiltangle, this.shngCurrentVerticalTiltAngleCallback.bind(this));
}
if (accessory.targetverticaltiltangle) {
this.platform.shng.addMonitor(accessory.targetverticaltiltangle, this.shngTargetVerticalTiltAngleCallback.bind(this));
}
this.currentPositionMax = accessory.currentpositionmax ? accessory.currentpositionmax : this.currentPositionMax; this.currentPositionMax = accessory.currentpositionmax ? accessory.currentpositionmax : this.currentPositionMax;
this.currentPositionMin = accessory.currentpositionmin ? accessory.currentpositionmin : this.currentPositionMin; this.currentPositionMin = accessory.currentpositionmin ? accessory.currentpositionmin : this.currentPositionMin;
@ -74,7 +102,7 @@ export class WindowCovering implements AccessoryPlugin {
setTargetPosition(value: CharacteristicValue) { setTargetPosition(value: CharacteristicValue) {
this.targetPosition = value as number; this.targetPosition = value as number;
this.platform.log.info('SetOn:', this.accessory.name, 'was set to', this.targetPosition); this.platform.log.info('setTargetPosition:', this.accessory.name, 'was set to', this.targetPosition);
const transposedTarget = this.convertRange( const transposedTarget = this.convertRange(
value as number, value as number,
0, 100, 0, 100,
@ -84,6 +112,39 @@ export class WindowCovering implements AccessoryPlugin {
this.platform.shng.setItem(this.accessory.targetposition, transposedTarget); this.platform.shng.setItem(this.accessory.targetposition, transposedTarget);
} }
getCurrentHorizontalTiltAngle(): Nullable<CharacteristicValue> {
this.platform.log.info('getCurrentHorizontalTiltAngle:', this.accessory.name, 'is currently', this.currentHorizontalTiltAngle);
return this.currentHorizontalTiltAngle;
}
getTargetHorizontalTiltAngle(): Nullable<CharacteristicValue> {
this.platform.log.info('getTargetHorizontalTiltAngle:', this.accessory.name, 'is currently', this.targetHorizontalTiltAngle);
return this.targetHorizontalTiltAngle;
}
setTargetHorizontalTiltAngle(value: CharacteristicValue) {
this.targetHorizontalTiltAngle = value as number;
this.platform.log.info('setTargetHorizontalTiltAngle:', this.accessory.name, 'was set to', this.targetHorizontalTiltAngle);
this.platform.shng.setItem(this.accessory.targethorizontaltiltangle, this.targetHorizontalTiltAngle);
}
getCurrentVerticalTiltAngle(): Nullable<CharacteristicValue> {
this.platform.log.info('getCurrentVerticalTiltAngle:', this.accessory.name, 'is currently', this.currentVerticalTiltAngle);
return this.currentVerticalTiltAngle;
}
getTargetVerticalTiltAngle(): Nullable<CharacteristicValue> {
this.platform.log.info('getTargetVerticalTiltAngle:', this.accessory.name, 'is currently', this.targetVerticalTiltAngle);
return this.targetVerticalTiltAngle;
}
setTargetVerticalTiltAngle(value: CharacteristicValue) {
this.targetVerticalTiltAngle = value as number;
this.platform.log.info('setTargetVerticalTiltAngle:', this.accessory.name, 'was set to', this.targetVerticalTiltAngle);
this.platform.shng.setItem(this.accessory.targetverticaltiltangle, this.targetVerticalTiltAngle);
}
shngCurrentPositionCallback(value: unknown): void { shngCurrentPositionCallback(value: unknown): void {
this.platform.log.debug('shngCurrentPositionCallback:', this.accessory.name, '=', value, '(' + typeof value + ')'); this.platform.log.debug('shngCurrentPositionCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
if (typeof value === 'number') { if (typeof value === 'number') {
@ -117,6 +178,43 @@ export class WindowCovering implements AccessoryPlugin {
this.updateDirection(); this.updateDirection();
} }
shngCurrentHorizontalTiltAngleCallback(value: unknown): void {
this.platform.log.debug('shngCurrentHorizontalTiltAngleCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
if (typeof value === 'number') {
this.currentHorizontalTiltAngle = value;
} else {
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
}
}
shngTargetHorizontalTiltAngleCallback(value: unknown): void {
this.platform.log.debug('shngTargetHorizontalTiltAngleCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
if (typeof value === 'number') {
this.targetHorizontalTiltAngle = value;
} else {
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
}
}
shngCurrentVerticalTiltAngleCallback(value: unknown): void {
this.platform.log.debug('shngCurrentVerticalTiltAngleCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
if (typeof value === 'number') {
this.currentVerticalTiltAngle = value;
} else {
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
}
}
shngTargetVerticalTiltAngleCallback(value: unknown): void {
this.platform.log.debug('shngTargetVerticalTiltAngleCallback:', this.accessory.name, '=', value, '(' + typeof value + ')');
if (typeof value === 'number') {
this.targetVerticalTiltAngle = value;
} else {
this.platform.log.warn('Unknown type ', typeof value, 'received for', this.accessory.name + ':', value);
}
}
updateDirection() { updateDirection() {
let direction; let direction;
if (this.targetPosition < this.currentPosition) { if (this.targetPosition < this.currentPosition) {