]> git.basschouten.com Git - openhab-addons.git/blob
2ceac4ef54d3cae35026048b8176d1231269089d
[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 white bulb. Both leds cannot be on at the same time, so no saturation or colour temperature
23  * control. It still allows more colours than the old v3 rgbw bulb (16320 (255*64) vs 4080 (255*16) colors).
24  *
25  * @author David Graeff - Initial contribution
26  */
27 @NonNullByDefault
28 public class MilightV6RGBWHandler extends AbstractLedV6Handler {
29     private static final int ADDR = 0x07;
30
31     public MilightV6RGBWHandler(Thing thing, QueuedSend sendQueue) {
32         super(thing, sendQueue, 20);
33     }
34
35     @Override
36     protected byte getAddr() {
37         return ADDR;
38     }
39
40     @Override
41     public void setPower(boolean on, MilightThingState state) {
42         sendNonRepeatable(3, on ? 1 : 2);
43     }
44
45     @Override
46     public void whiteMode(MilightThingState state) {
47         sendRepeatableCat(ProtocolConstants.CAT_WHITEMODE, 3, 5);
48     }
49
50     @Override
51     public void nightMode(MilightThingState state) {
52         setPower(true, state);
53         sendRepeatableCat(ProtocolConstants.CAT_POWER_MODE, 3, 6);
54     }
55
56     @Override
57     public void setColorTemperature(int colorTemp, MilightThingState state) {
58         logger.info("Color temperature not supported by RGBW led!");
59     }
60
61     @Override
62     protected byte getBrCmd() {
63         return 2;
64     }
65
66     @Override
67     public void setSaturation(int value, MilightThingState state) {
68         logger.info("Saturation not supported by RGBW led!");
69     }
70
71     @Override
72     public void setLedMode(int newmode, MilightThingState state) {
73         int mode = Math.max(Math.min(newmode, 9), 1);
74         sendRepeatableCat(ProtocolConstants.CAT_MODE_SET, 6, mode);
75         state.animationMode = mode;
76     }
77
78     @Override
79     public void changeSpeed(int relativeSpeed, MilightThingState state) {
80         sendNonRepeatable(4, relativeSpeed == 1 ? 3 : 4);
81     }
82 }