2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.milight.internal.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.milight.internal.MilightThingState;
17 import org.openhab.binding.milight.internal.protocol.ProtocolConstants;
18 import org.openhab.binding.milight.internal.protocol.QueuedSend;
19 import org.openhab.core.thing.Thing;
22 * Implements the RGB cold white / warm white bulb. It is the most feature rich bulb.
24 * @author David Graeff - Initial contribution
27 public class MilightV6RGBCWWWHandler extends AbstractLedV6Handler {
28 private static final int ADDR = 0x08;
30 public MilightV6RGBCWWWHandler(Thing thing, QueuedSend sendQueue) {
31 super(thing, sendQueue, 10);
35 protected byte getAddr() {
40 public void setPower(boolean on, MilightThingState state) {
41 sendRepeatableCat(ProtocolConstants.CAT_POWER_MODE, 4, on ? 1 : 2);
45 public void whiteMode(MilightThingState state) {
46 sendRepeatableCat(ProtocolConstants.CAT_WHITEMODE, 5, state.colorTemperature);
50 public void nightMode(MilightThingState state) {
51 sendRepeatableCat(ProtocolConstants.CAT_POWER_MODE, 4, 5);
55 public void setColorTemperature(int colorTemp, MilightThingState state) {
56 int ct = (colorTemp * MAX_TEMP) / 100;
57 ct = Math.min(ct, MAX_TEMP);
59 sendRepeatableCat(ProtocolConstants.CAT_TEMPERATURE_SET, 5, ct);
60 state.colorTemperature = colorTemp;
64 protected byte getBrCmd() {
69 public void setSaturation(int value, MilightThingState state) {
70 int br = (value * MAX_SAT) / 100; // map value from [0,100] -> [0,MAX_SAT]
71 br = MAX_SAT - br; // inverse value
72 br = Math.min(br, MAX_SAT); // force maximum value
73 br = Math.max(br, 0); // force minimum value
74 sendRepeatableCat(ProtocolConstants.CAT_SATURATION_SET, 2, br);
75 state.saturation = value;
79 public void setLedMode(int newmode, MilightThingState state) {
80 int mode = Math.max(Math.min(newmode, 9), 1);
81 sendRepeatableCat(ProtocolConstants.CAT_MODE_SET, 6, mode);
82 state.animationMode = mode;
86 public void changeSpeed(int relativeSpeed, MilightThingState state) {
87 sendNonRepeatable(4, relativeSpeed > 1 ? 3 : 4);