diff --git a/xaal.go b/xaal.go index 3dd55b178ea76196b467d2165cda63f41b167774..83dd7f0c021e88e443287c726becc3a10accd598 100644 --- a/xaal.go +++ b/xaal.go @@ -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 }