forked from basdelfos/homebridge-tuya-web
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improves handling of brightness.
This features allows more granular control over how this plugin perceives the brightness that it gets reported from Tuya.
- Loading branch information
Showing
9 changed files
with
146 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
export class MapRange { | ||
private constructor( | ||
private fromStart, | ||
private fromEnd, | ||
private toStart, | ||
private toEnd | ||
public readonly tuyaStart: number, | ||
public readonly tuyaEnd: number, | ||
public readonly homekitStart: number, | ||
public readonly homekitEnd: number | ||
) {} | ||
|
||
static from(start, end): { to: (start: number, end: number) => MapRange } { | ||
static tuya( | ||
start, | ||
end | ||
): { homeKit: (start: number, end: number) => MapRange } { | ||
return { | ||
to: (toStart, toEnd) => { | ||
homeKit: (toStart, toEnd) => { | ||
return new MapRange(start, end, toStart, toEnd); | ||
}, | ||
}; | ||
} | ||
|
||
public map(input: number): number { | ||
public tuyaToHomekit(tuyaValue: number): number { | ||
return ( | ||
((input - this.fromStart) * (this.toEnd - this.toStart)) / | ||
(this.fromEnd - this.fromStart) + | ||
this.toStart | ||
((tuyaValue - this.tuyaStart) * (this.homekitEnd - this.homekitStart)) / | ||
(this.tuyaEnd - this.tuyaStart) + | ||
this.homekitStart | ||
); | ||
} | ||
|
||
public inverseMap(input: number): number { | ||
public homekitToTuya(homeKitValue: number): number { | ||
return ( | ||
((input - this.toStart) * (this.fromEnd - this.fromStart)) / | ||
(this.toEnd - this.toStart) + | ||
this.fromStart | ||
((homeKitValue - this.homekitStart) * (this.tuyaEnd - this.tuyaStart)) / | ||
(this.homekitEnd - this.homekitStart) + | ||
this.tuyaStart | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters