]> git.basschouten.com Git - openhab-addons.git/blob
c2e1c50dd37d69b094e44f7ddca1eeb0ddc1de93
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.milight.internal.handler;
14
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;
20
21 /**
22  * Implements the RGB cold white / warm white bulb. It is the most feature rich bulb.
23  *
24  * @author David Graeff - Initial contribution
25  */
26 @NonNullByDefault
27 public class MilightV6RGBCWWWHandler extends AbstractLedV6Handler {
28     private static final int ADDR = 0x08;
29
30     public MilightV6RGBCWWWHandler(Thing thing, QueuedSend sendQueue) {
31         super(thing, sendQueue, 10);
32     }
33
34     @Override
35     protected byte getAddr() {
36         return ADDR;
37     }
38
39     @Override
40     public void setPower(boolean on, MilightThingState state) {
41         sendRepeatableCat(ProtocolConstants.CAT_POWER_MODE, 4, on ? 1 : 2);
42     }
43
44     @Override
45     public void whiteMode(MilightThingState state) {
46         sendRepeatableCat(ProtocolConstants.CAT_WHITEMODE, 5, state.colorTemperature);
47     }
48
49     @Override
50     public void nightMode(MilightThingState state) {
51         sendRepeatableCat(ProtocolConstants.CAT_POWER_MODE, 4, 5);
52     }
53
54     @Override
55     public void setColorTemperature(int colorTemp, MilightThingState state) {
56         int ct = (colorTemp * MAX_TEMP) / 100;
57         ct = Math.min(ct, MAX_TEMP);
58         ct = Math.max(ct, 0);
59         sendRepeatableCat(ProtocolConstants.CAT_TEMPERATURE_SET, 5, ct);
60         state.colorTemperature = colorTemp;
61     }
62
63     @Override
64     protected byte getBrCmd() {
65         return 3;
66     }
67
68     @Override
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;
76     }
77
78     @Override
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;
83     }
84
85     @Override
86     public void changeSpeed(int relativeSpeed, MilightThingState state) {
87         sendNonRepeatable(4, relativeSpeed > 1 ? 3 : 4);
88     }
89 }