Added decimals to WindowCov., Plugin now verified
This commit is contained in:
parent
43e3fdf35f
commit
d56a3a98e9
@ -1,6 +1,7 @@
|
||||
# homebridge-smarthomeng
|
||||
|
||||
[](https://www.npmjs.com/package/homebridge-smarthomeng)
|
||||
[](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)
|
||||
[](https://www.npmjs.com/package/homebridge-smarthomeng)
|
||||
[](https://www.npmjs.com/package/homebridge-smarthomeng)
|
||||
[](https://www.npmjs.com/package/homebridge-smarthomeng)
|
||||
@ -406,9 +407,11 @@ This accessory type can be used for shutters or blinds. Because the differnce be
|
||||
| TargetPosition | \<item> | Yes | | SHNG item to monitor and set the target position |
|
||||
| CurrentPositionMin | \<number> | No | 0 | Your device's minimum value for current position |
|
||||
| CurrentPositionMax | \<number> | No | 100 | Your device's maximum value for current position |
|
||||
| CurrentPositionDecimals | \<number> | No | 0 | Number of decimals to round to |
|
||||
| CurrentPositionInverted | \<boolean> | No | false | Should the values be inverted, ex: 0 for Homekit = 100 for device |
|
||||
| TargetPositionMin | \<number> | No | 0 | Your device's minimum value for target position |
|
||||
| TargetPositionMax | \<number> | No | 100 | Your device's maximum value for target position |
|
||||
| TargetPositionDecimals | \<number> | No | 0 | Number of decimals to round to |
|
||||
| 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 |
|
||||
|
||||
1881
package-lock.json
generated
1881
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -2,7 +2,7 @@
|
||||
"private": false,
|
||||
"displayName": "SmartHomeNG",
|
||||
"name": "homebridge-smarthomeng",
|
||||
"version": "2.0.6",
|
||||
"version": "2.0.7",
|
||||
"description": "SmartHomeNG plugin for Homebridge",
|
||||
"license": "Apache-2.0",
|
||||
"repository": {
|
||||
@ -27,17 +27,17 @@
|
||||
"homebridge-plugin"
|
||||
],
|
||||
"dependencies": {
|
||||
"ws": "^8.4.2"
|
||||
"ws": "^8.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.10.9",
|
||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||
"@typescript-eslint/parser": "^5.0.0",
|
||||
"eslint": "^8.0.1",
|
||||
"homebridge": "^1.3.5",
|
||||
"nodemon": "^2.0.13",
|
||||
"@types/node": "^17.0.33",
|
||||
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
||||
"@typescript-eslint/parser": "^5.23.0",
|
||||
"eslint": "^8.15.0",
|
||||
"homebridge": "^1.4.1",
|
||||
"nodemon": "^2.0.16",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-node": "^10.3.0",
|
||||
"typescript": "^4.4.4"
|
||||
"ts-node": "^10.7.0",
|
||||
"typescript": "^4.6.4"
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,8 +12,10 @@ export class WindowCovering implements AccessoryPlugin {
|
||||
private readonly informationService: Service;
|
||||
|
||||
public name: string;
|
||||
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 currentPosition = 0; private currentPositionMin = 0; private currentPositionMax = 100;
|
||||
private currentPositionDecimals = 0; private currentPositionInverted = false;
|
||||
private targetPosition = 0; private targetPositionMin = 0; private targetPositionMax = 100;
|
||||
private targetPositionDecimals = 0; private targetPositionInverted = false;
|
||||
private positionState = this.platform.Characteristic.PositionState.STOPPED;
|
||||
private currentHorizontalTiltAngle = 0; private targetHorizontalTiltAngle = 0;
|
||||
private currentVerticalTiltAngle = 0; private targetVerticalTiltAngle = 0;
|
||||
@ -70,9 +72,11 @@ export class WindowCovering implements AccessoryPlugin {
|
||||
|
||||
this.currentPositionMax = accessory.currentpositionmax ? accessory.currentpositionmax : this.currentPositionMax;
|
||||
this.currentPositionMin = accessory.currentpositionmin ? accessory.currentpositionmin : this.currentPositionMin;
|
||||
this.currentPositionDecimals = accessory.currentpositiondecimals ? accessory.currentpositiondecimals : this.currentPositionDecimals;
|
||||
this.currentPositionInverted = accessory.currentpositioninverted ? accessory.currentpositioninverted : this.currentPositionInverted;
|
||||
this.targetPositionMax = accessory.targetpositionmax ? accessory.targetpositionmax : this.targetPositionMax;
|
||||
this.targetPositionMin = accessory.targetpositionmin ? accessory.targetpositionmin : this.targetPositionMin;
|
||||
this.targetPositionDecimals = accessory.targetpositiondecimals ? accessory.targetpositiondecimals : this.targetPositionDecimals;
|
||||
this.targetPositionInverted = accessory.targetpositioninverted ? accessory.targetpositioninverted : this.targetPositionInverted;
|
||||
this.platform.log.info("WindowCovering '%s' created!", accessory.name);
|
||||
}
|
||||
@ -107,7 +111,7 @@ export class WindowCovering implements AccessoryPlugin {
|
||||
value as number,
|
||||
0, 100,
|
||||
this.targetPositionMin, this.targetPositionMax,
|
||||
this.targetPositionInverted,
|
||||
this.targetPositionDecimals, this.targetPositionInverted,
|
||||
);
|
||||
this.platform.shng.setItem(this.accessory.targetposition, transposedTarget);
|
||||
}
|
||||
@ -152,7 +156,7 @@ export class WindowCovering implements AccessoryPlugin {
|
||||
value as number,
|
||||
this.currentPositionMin, this.currentPositionMax,
|
||||
0, 100,
|
||||
this.currentPositionInverted,
|
||||
0, this.currentPositionInverted,
|
||||
);
|
||||
this.deviceService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.currentPosition);
|
||||
} else {
|
||||
@ -169,7 +173,7 @@ export class WindowCovering implements AccessoryPlugin {
|
||||
value as number,
|
||||
this.targetPositionMin, this.targetPositionMax,
|
||||
0, 100,
|
||||
this.targetPositionInverted,
|
||||
0, this.targetPositionInverted,
|
||||
);
|
||||
this.deviceService.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.targetPosition);
|
||||
} else {
|
||||
@ -235,9 +239,14 @@ export class WindowCovering implements AccessoryPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
convertRange(value: number, oldmin: number, oldmax: number, newmin: number, newmax: number, inverted: boolean): number {
|
||||
// eslint-disable-next-line max-len
|
||||
convertRange(value: number, oldmin: number, oldmax: number, newmin: number, newmax: number, decimals: number, inverted: boolean): number {
|
||||
let result = (((value - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin;
|
||||
result = Math.round(result);
|
||||
if(decimals > 0) {
|
||||
result = parseFloat(result.toFixed(decimals));
|
||||
} else {
|
||||
result = Math.round(result);
|
||||
}
|
||||
if (inverted) {
|
||||
result = newmax - result;
|
||||
}
|
||||
@ -246,6 +255,7 @@ export class WindowCovering implements AccessoryPlugin {
|
||||
'from range', oldmin, '-', oldmax,
|
||||
'to', newmin, '-', newmax,
|
||||
'with inverted', inverted,
|
||||
'and', decimals, 'decimals',
|
||||
'=', result,
|
||||
);
|
||||
return result;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user