Compare commits

..

No commits in common. "master" and "v2.0.6" have entirely different histories.

4 changed files with 2597 additions and 1501 deletions

View File

@ -1,12 +1,14 @@
# 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/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/dm/homebridge-smarthomeng)](https://www.npmjs.com/package/homebridge-smarthomeng)
**Version v2 is a complete rewrite from scratch and a breaking update.**
You need to adapt your [`config.json`](#example-configuration-file) !
## Currently supported accessories
This plugin currently supports the following services (and characteristics):
@ -404,11 +406,9 @@ 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 |

4040
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
"private": false,
"displayName": "SmartHomeNG",
"name": "homebridge-smarthomeng",
"version": "2.0.8",
"version": "2.0.6",
"description": "SmartHomeNG plugin for Homebridge",
"license": "Apache-2.0",
"repository": {
@ -27,17 +27,17 @@
"homebridge-plugin"
],
"dependencies": {
"ws": "^8.12.1"
"ws": "^8.4.2"
},
"devDependencies": {
"@types/node": "^18.13.0",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"eslint": "^8.34.0",
"homebridge": "^1.6.0",
"nodemon": "^2.0.20",
"rimraf": "^4.1.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"@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",
"rimraf": "^3.0.2",
"ts-node": "^10.3.0",
"typescript": "^4.4.4"
}
}

View File

@ -12,10 +12,8 @@ export class WindowCovering implements AccessoryPlugin {
private readonly informationService: Service;
public name: string;
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 currentPosition = 0; private currentPositionMin = 0; private currentPositionMax = 100; private currentPositionInverted = false;
private targetPosition = 0; private targetPositionMin = 0; private targetPositionMax = 100; private targetPositionInverted = false;
private positionState = this.platform.Characteristic.PositionState.STOPPED;
private currentHorizontalTiltAngle = 0; private targetHorizontalTiltAngle = 0;
private currentVerticalTiltAngle = 0; private targetVerticalTiltAngle = 0;
@ -72,11 +70,9 @@ 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);
}
@ -111,7 +107,7 @@ export class WindowCovering implements AccessoryPlugin {
value as number,
0, 100,
this.targetPositionMin, this.targetPositionMax,
this.targetPositionDecimals, this.targetPositionInverted,
this.targetPositionInverted,
);
this.platform.shng.setItem(this.accessory.targetposition, transposedTarget);
}
@ -156,7 +152,7 @@ export class WindowCovering implements AccessoryPlugin {
value as number,
this.currentPositionMin, this.currentPositionMax,
0, 100,
0, this.currentPositionInverted,
this.currentPositionInverted,
);
this.deviceService.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.currentPosition);
} else {
@ -173,7 +169,7 @@ export class WindowCovering implements AccessoryPlugin {
value as number,
this.targetPositionMin, this.targetPositionMax,
0, 100,
0, this.targetPositionInverted,
this.targetPositionInverted,
);
this.deviceService.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.targetPosition);
} else {
@ -239,14 +235,9 @@ export class WindowCovering implements AccessoryPlugin {
);
}
// eslint-disable-next-line max-len
convertRange(value: number, oldmin: number, oldmax: number, newmin: number, newmax: number, decimals: number, inverted: boolean): number {
convertRange(value: number, oldmin: number, oldmax: number, newmin: number, newmax: number, inverted: boolean): number {
let result = (((value - oldmin) * (newmax - newmin)) / (oldmax - oldmin)) + newmin;
if(decimals > 0) {
result = parseFloat(result.toFixed(decimals));
} else {
result = Math.round(result);
}
if (inverted) {
result = newmax - result;
}
@ -255,7 +246,6 @@ export class WindowCovering implements AccessoryPlugin {
'from range', oldmin, '-', oldmax,
'to', newmin, '-', newmax,
'with inverted', inverted,
'and', decimals, 'decimals',
'=', result,
);
return result;