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

Support for mode

The color/white mode was missing. All should be fine now
parent 93caf40e
No related branches found
No related tags found
No related merge requests found
......@@ -51,11 +51,6 @@ type Lamp struct {
Z2MDevice Z2MDevice
}
type LampDimmer struct {
XAALDevice
Z2MDevice Z2MDevice
}
type ButtonRemote struct {
XAALDevice
Z2MDevice Z2MDevice
......@@ -282,6 +277,20 @@ func (dev *Lamp) update(payload map[string]interface{}) {
brightness = brightness / 255 * 100
dev.GetAttribute("brightness").SetValue(int(brightness))
}
color_mode, exists := payload["color_mode"].(string)
if exists {
mode := dev.GetAttribute("mode")
// only color lamp have a mode
if mode != nil {
switch color_mode {
case "xy":
mode.SetValue("color")
case "color_temp":
mode.SetValue("white")
}
}
}
// color
color, exists := payload["color"].(map[string]interface{})
if exists {
......@@ -292,13 +301,10 @@ func (dev *Lamp) update(payload map[string]interface{}) {
slog.Warn("color", "color", value.Hex(), "x", x, "y", y, "tmp", brigthness)
hue, sat, val := value.Hsv()
hue = roundToDecimal(hue, 1)
sat = roundToDecimal(sat, 2)
val = roundToDecimal(val, 2)
slog.Warn("color", "hue", hue, "sat", sat, "val", val)
sat = roundToDecimal(sat, 3)
val = roundToDecimal(val, 3)
dev.GetAttribute("hsv").SetValue([]float64{hue, sat, val})
return
}
// color_temp
color_temp, exists := payload["color_temp"].(float64)
if exists {
......@@ -336,7 +342,7 @@ func (dev *Lamp) setWhiteTemperature(body xaal.MessageBody) *xaal.MessageBody {
value, exists := body["white_temperature"].(uint64)
if exists {
value = 1000000 / value
dev.Z2MDevice.Set(fmt.Sprintf(`{"color_temp": %d}`, value))
dev.Z2MDevice.Set(fmt.Sprintf(`{"color_temp": %d}`, int(value)))
}
return nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment