-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a max brightness field for each dimmer in config file #149 #200
Changes from 19 commits
08f2236
2e92194
eac49b0
9c88c38
0675f75
52c2b14
58487c3
dc89a94
1559b0b
66c18fe
a271ede
1f4b415
f81a8b4
cdd44db
8065695
d729345
f591f0b
418c2d1
df1f3ba
e986fef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { inspect } from "util"; | |
import { TuyaWebCharacteristic } from "./base"; | ||
import { BaseAccessory } from "../BaseAccessory"; | ||
import { DeviceState } from "../../api/response"; | ||
import { DimmerAccessory } from "../DimmerAccessory"; | ||
|
||
export class BrightnessCharacteristic extends TuyaWebCharacteristic { | ||
public static Title = "Characteristic.Brightness"; | ||
|
@@ -41,7 +42,13 @@ export class BrightnessCharacteristic extends TuyaWebCharacteristic { | |
callback: CharacteristicSetCallback | ||
): void { | ||
// Set device state in Tuya Web API | ||
const value = ((homekitValue as number) / 10) * 9 + 10; | ||
const dimmerPercentage = (homekitValue as number) / 100; | ||
const correctionFactor = 10; | ||
const value = Math.round( | ||
(100 - correctionFactor) * dimmerPercentage + | ||
correctionFactor + | ||
Number.EPSILON | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you opt to add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The decimal number is very large, I wanted to be sure as much as possible the round will be correct |
||
); | ||
|
||
this.accessory | ||
.setDeviceState("brightnessSet", { value }, { brightness: homekitValue }) | ||
|
@@ -63,7 +70,11 @@ export class BrightnessCharacteristic extends TuyaWebCharacteristic { | |
) { | ||
stateValue = Number(data.color.brightness); | ||
} else if (data?.brightness) { | ||
stateValue = Math.round((Number(data.brightness) / 255) * 100); | ||
const maxBrightness = (this.accessory as DimmerAccessory).maxBrightness; | ||
const brightness = Number(data.brightness); | ||
stateValue = Math.round( | ||
(brightness / maxBrightness) * 100 + Number.EPSILON | ||
); | ||
} | ||
|
||
if (stateValue) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some warnings here, could you please take a look at those.