Added decimals to WindowCov., Plugin now verified

This commit is contained in:
Serge Wagener 2022-05-16 18:35:15 +02:00
parent 43e3fdf35f
commit d56a3a98e9
4 changed files with 1118 additions and 810 deletions

View File

@ -1,6 +1,7 @@
# homebridge-smarthomeng # homebridge-smarthomeng
[![npm](https://badgen.net/npm/v/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng) [![npm](https://badgen.net/npm/v/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng)
[![verified-by-homebridge](https://badgen.net/badge/homebridge/verified/purple)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)
[![npm](https://badgen.net/badge/homebridge/>=1.3.5/green)](https://www.npmjs.com/package/homebridge-smarthomeng) [![npm](https://badgen.net/badge/homebridge/>=1.3.5/green)](https://www.npmjs.com/package/homebridge-smarthomeng)
[![npm](https://badgen.net/npm/node/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng) [![npm](https://badgen.net/npm/node/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng)
[![npm](https://badgen.net/npm/dt/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng) [![npm](https://badgen.net/npm/dt/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 | | 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 |
| CurrentPositionMax | \<number> | No | 100 | Your device's maximum 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 | | 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 | | 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 |
| 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 | | 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 | | 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 | | TargetHorizontalTiltAngle | \<item> | No | | SHNG item to monitor and set the target horizontal tilt angle |

1879
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
"private": false, "private": false,
"displayName": "SmartHomeNG", "displayName": "SmartHomeNG",
"name": "homebridge-smarthomeng", "name": "homebridge-smarthomeng",
"version": "2.0.6", "version": "2.0.7",
"description": "SmartHomeNG plugin for Homebridge", "description": "SmartHomeNG plugin for Homebridge",
"license": "Apache-2.0", "license": "Apache-2.0",
"repository": { "repository": {
@ -27,17 +27,17 @@
"homebridge-plugin" "homebridge-plugin"
], ],
"dependencies": { "dependencies": {
"ws": "^8.4.2" "ws": "^8.6.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^16.10.9", "@types/node": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^5.0.0", "@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.0.0", "@typescript-eslint/parser": "^5.23.0",
"eslint": "^8.0.1", "eslint": "^8.15.0",
"homebridge": "^1.3.5", "homebridge": "^1.4.1",
"nodemon": "^2.0.13", "nodemon": "^2.0.16",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"ts-node": "^10.3.0", "ts-node": "^10.7.0",
"typescript": "^4.4.4" "typescript": "^4.6.4"
} }
} }

View File

@ -12,8 +12,10 @@ export class WindowCovering implements AccessoryPlugin {
private readonly informationService: Service; private readonly informationService: Service;
public name: string; public name: string;
private currentPosition = 0; private currentPositionMin = 0; private currentPositionMax = 100; private currentPositionInverted = false; private currentPosition = 0; private currentPositionMin = 0; private currentPositionMax = 100;
private targetPosition = 0; private targetPositionMin = 0; private targetPositionMax = 100; private targetPositionInverted = false; 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 positionState = this.platform.Characteristic.PositionState.STOPPED;
private currentHorizontalTiltAngle = 0; private targetHorizontalTiltAngle = 0; private currentHorizontalTiltAngle = 0; private targetHorizontalTiltAngle = 0;
private currentVerticalTiltAngle = 0; private targetVerticalTiltAngle = 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.currentPositionMax = accessory.currentpositionmax ? accessory.currentpositionmax : this.currentPositionMax;
this.currentPositionMin = accessory.currentpositionmin ? accessory.currentpositionmin : this.currentPositionMin; 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.currentPositionInverted = accessory.currentpositioninverted ? accessory.currentpositioninverted : this.currentPositionInverted;
this.targetPositionMax = accessory.targetpositionmax ? accessory.targetpositionmax : this.targetPositionMax; this.targetPositionMax = accessory.targetpositionmax ? accessory.targetpositionmax : this.targetPositionMax;
this.targetPositionMin = accessory.targetpositionmin ? accessory.targetpositionmin : this.targetPositionMin; 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.targetPositionInverted = accessory.targetpositioninverted ? accessory.targetpositioninverted : this.targetPositionInverted;
this.platform.log.info("WindowCovering '%s' created!", accessory.name); this.platform.log.info("WindowCovering '%s' created!", accessory.name);
} }
@ -107,7 +111,7 @@ export class WindowCovering implements AccessoryPlugin {
value as number, value as number,
0, 100, 0, 100,
this.targetPositionMin, this.targetPositionMax, this.targetPositionMin, this.targetPositionMax,
this.targetPositionInverted, this.targetPositionDecimals, this.targetPositionInverted,
); );
this.platform.shng.setItem(this.accessory.targetposition, transposedTarget); this.platform.shng.setItem(this.accessory.targetposition, transposedTarget);
} }
@ -152,7 +156,7 @@ export class WindowCovering implements AccessoryPlugin {
value as number, value as number,
this.currentPositionMin, this.currentPositionMax, this.currentPositionMin, this.currentPositionMax,
0, 100, 0, 100,
this.currentPositionInverted, 0, this.currentPositionInverted,
); );
this.deviceService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.currentPosition); this.deviceService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.currentPosition);
} else { } else {
@ -169,7 +173,7 @@ export class WindowCovering implements AccessoryPlugin {
value as number, value as number,
this.targetPositionMin, this.targetPositionMax, this.targetPositionMin, this.targetPositionMax,
0, 100, 0, 100,
this.targetPositionInverted, 0, this.targetPositionInverted,
); );
this.deviceService.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.targetPosition); this.deviceService.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.targetPosition);
} else { } 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; let result = (((value - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin;
if(decimals > 0) {
result = parseFloat(result.toFixed(decimals));
} else {
result = Math.round(result); result = Math.round(result);
}
if (inverted) { if (inverted) {
result = newmax - result; result = newmax - result;
} }
@ -246,6 +255,7 @@ export class WindowCovering implements AccessoryPlugin {
'from range', oldmin, '-', oldmax, 'from range', oldmin, '-', oldmax,
'to', newmin, '-', newmax, 'to', newmin, '-', newmax,
'with inverted', inverted, 'with inverted', inverted,
'and', decimals, 'decimals',
'=', result, '=', result,
); );
return result; return result;