Skip to content
Snippets Groups Projects
Commit fb3d44f6 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Fix brightness / white_temperature

brightness and white_temperature are sometimes binded to Float64 (don't
ask why). So I used convertToInt()
parent 9db5b1d7
No related branches found
No related tags found
No related merge requests found
...@@ -297,10 +297,10 @@ func (dev *Lamp) update(payload map[string]interface{}) { ...@@ -297,10 +297,10 @@ func (dev *Lamp) update(payload map[string]interface{}) {
} }
// brightness // brightness
brightness, exists := payload["brightness"].(int) brightness, err := convertToInt(payload["brightness"])
if exists { if err == nil {
brightness = brightness / 255 * 100 brightness = brightness * 100 / 255
dev.GetAttribute("brightness").SetValue(brightness) dev.GetAttribute("brightness").SetValue(int(brightness))
} }
// color_temp // color_temp
...@@ -308,10 +308,9 @@ func (dev *Lamp) update(payload map[string]interface{}) { ...@@ -308,10 +308,9 @@ func (dev *Lamp) update(payload map[string]interface{}) {
// color_temp change when we are in color mode (looks like a z2m bug) // color_temp change when we are in color mode (looks like a z2m bug)
// so we have to only update when we are in white mode. Without this check // so we have to only update when we are in white mode. Without this check
// the color_temp is wrong when you change the mode w/ setMode // the color_temp is wrong when you change the mode w/ setMode
color_temp, exists := payload["color_temp"].(int) color_temp, err := convertToInt(payload["color_temp"])
if exists { if err == nil {
color_temp = convertMired(color_temp) dev.GetAttribute("white_temperature").SetValue(convertMired(color_temp))
dev.GetAttribute("white_temperature").SetValue(color_temp)
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment