mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[nanoleaf] Handle and provide QuantityType for color-temperature-abs channel (#14026)
* [nanoleaf] handle and provide QuantityType for color-temperature-abs channel see https://github.com/openhab/openhab-core/pull/3129 Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
parent
df8e0bb15b
commit
672b60b1d9
@ -139,19 +139,19 @@ This discovers all connected panels with their IDs.
|
|||||||
|
|
||||||
The controller bridge has the following channels:
|
The controller bridge has the following channels:
|
||||||
|
|
||||||
| Channel | Item Type | Description | Read Only |
|
| Channel | Item Type | Description | Read Only |
|
||||||
|---------------------|-----------|-----------------------------------------------------------------------------------------------------------|-----------|
|
|---------------------|--------------------|-----------------------------------------------------------------------------------------------------------|-----------|
|
||||||
| color | Color | Color, power and brightness of all light panels | No |
|
| color | Color | Color, power and brightness of all light panels | No |
|
||||||
| colorTemperature | Dimmer | Color temperature (in percent) of all light panels | No |
|
| colorTemperature | Dimmer | Color temperature (in percent) of all light panels | No |
|
||||||
| colorTemperatureAbs | Number | Color temperature (in Kelvin, 1200 to 6500) of all light panels | No |
|
| colorTemperatureAbs | Number:Temperature | Color temperature (in Kelvin, 1200 to 6500) of all light panels | No |
|
||||||
| colorMode | String | Color mode of the light panels | Yes |
|
| colorMode | String | Color mode of the light panels | Yes |
|
||||||
| effect | String | Selected effect of the light panels | No |
|
| effect | String | Selected effect of the light panels | No |
|
||||||
| layout | Image | Shows the layout of your panels with IDs. | Yes |
|
| layout | Image | Shows the layout of your panels with IDs. | Yes |
|
||||||
| rhythmState | Switch | Connection state of the rhythm module | Yes |
|
| rhythmState | Switch | Connection state of the rhythm module | Yes |
|
||||||
| rhythmActive | Switch | Activity state of the rhythm module | Yes |
|
| rhythmActive | Switch | Activity state of the rhythm module | Yes |
|
||||||
| rhythmMode | Number | Sound source for the rhythm module. 0=Microphone, 1=Aux cable | No |
|
| rhythmMode | Number | Sound source for the rhythm module. 0=Microphone, 1=Aux cable | No |
|
||||||
| state | Image | Shows the current state of your panels with colors. | Yes |
|
| state | Image | Shows the current state of your panels with colors. | Yes |
|
||||||
| swipe | Trigger | [Canvas / Shapes Only] Detects Swipes over the panel.LEFT, RIGHT, UP, DOWN events are supported. | Yes |
|
| swipe | Trigger | [Canvas / Shapes Only] Detects Swipes over the panel.LEFT, RIGHT, UP, DOWN events are supported. | Yes |
|
||||||
|
|
||||||
A lightpanel thing has the following channels:
|
A lightpanel thing has the following channels:
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ Dimmer NanoleafBrightness "Brightness [%.0f]" { channel="nanoleaf:controller:MyL
|
|||||||
String NanoleafHue "Hue [%s]"
|
String NanoleafHue "Hue [%s]"
|
||||||
String NanoleafSaturation "Saturation [%s]"
|
String NanoleafSaturation "Saturation [%s]"
|
||||||
Dimmer NanoleafColorTemp "Color temperature [%.0f]" { channel="nanoleaf:controller:MyLightPanels:colorTemperature" }
|
Dimmer NanoleafColorTemp "Color temperature [%.0f]" { channel="nanoleaf:controller:MyLightPanels:colorTemperature" }
|
||||||
Number NanoleafColorTempAbs "Color temperature [%.000f]" { channel="nanoleaf:controller:MyLightPanels:colorTemperatureAbs" }
|
Number:Temperature NanoleafColorTempAbs "Color temperature [%d K]" { channel="nanoleaf:controller:MyLightPanels:colorTemperatureAbs" }
|
||||||
String NanoleafColorMode "Color mode [%s]" { channel="nanoleaf:controller:MyLightPanels:colorMode" }
|
String NanoleafColorMode "Color mode [%s]" { channel="nanoleaf:controller:MyLightPanels:colorMode" }
|
||||||
String NanoleafEffect "Effect" { channel="nanoleaf:controller:MyLightPanels:effect" }
|
String NanoleafEffect "Effect" { channel="nanoleaf:controller:MyLightPanels:effect" }
|
||||||
Switch NanoleafRhythmState "Rhythm connected [MAP(nanoleaf.map):%s]" { channel="nanoleaf:controller:MyLightPanels:rhythmState" }
|
Switch NanoleafRhythmState "Rhythm connected [MAP(nanoleaf.map):%s]" { channel="nanoleaf:controller:MyLightPanels:rhythmState" }
|
||||||
|
@ -79,8 +79,10 @@ import org.openhab.core.library.types.HSBType;
|
|||||||
import org.openhab.core.library.types.IncreaseDecreaseType;
|
import org.openhab.core.library.types.IncreaseDecreaseType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
import org.openhab.core.library.types.PercentType;
|
import org.openhab.core.library.types.PercentType;
|
||||||
|
import org.openhab.core.library.types.QuantityType;
|
||||||
import org.openhab.core.library.types.RawType;
|
import org.openhab.core.library.types.RawType;
|
||||||
import org.openhab.core.library.types.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
|
import org.openhab.core.library.unit.Units;
|
||||||
import org.openhab.core.thing.Bridge;
|
import org.openhab.core.thing.Bridge;
|
||||||
import org.openhab.core.thing.ChannelUID;
|
import org.openhab.core.thing.ChannelUID;
|
||||||
import org.openhab.core.thing.Thing;
|
import org.openhab.core.thing.Thing;
|
||||||
@ -641,7 +643,7 @@ public class NanoleafControllerHandler extends BaseBridgeHandler implements Nano
|
|||||||
int hue;
|
int hue;
|
||||||
int saturation;
|
int saturation;
|
||||||
if (colorTemperature != null) {
|
if (colorTemperature != null) {
|
||||||
updateState(CHANNEL_COLOR_TEMPERATURE_ABS, new DecimalType(colorTemperature.getValue()));
|
updateState(CHANNEL_COLOR_TEMPERATURE_ABS, new QuantityType(colorTemperature.getValue(), Units.KELVIN));
|
||||||
Integer min = colorTemperature.getMin();
|
Integer min = colorTemperature.getMin();
|
||||||
hue = min == null ? 0 : min;
|
hue = min == null ? 0 : min;
|
||||||
Integer max = colorTemperature.getMax();
|
Integer max = colorTemperature.getMax();
|
||||||
@ -899,15 +901,25 @@ public class NanoleafControllerHandler extends BaseBridgeHandler implements Nano
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CHANNEL_COLOR_TEMPERATURE_ABS:
|
case CHANNEL_COLOR_TEMPERATURE_ABS:
|
||||||
|
// Color temperature (absolute)
|
||||||
|
int colorTempKelvin;
|
||||||
|
|
||||||
|
IntegerState state = new Ct();
|
||||||
if (command instanceof DecimalType) {
|
if (command instanceof DecimalType) {
|
||||||
// Color temperature (absolute)
|
|
||||||
IntegerState state = new Ct();
|
|
||||||
state.setValue(((DecimalType) command).intValue());
|
state.setValue(((DecimalType) command).intValue());
|
||||||
stateObject.setState(state);
|
} else if (command instanceof QuantityType) {
|
||||||
|
QuantityType<?> tempKelvin = ((QuantityType) command).toInvertibleUnit(Units.KELVIN);
|
||||||
|
if (tempKelvin == null) {
|
||||||
|
logger.warn("Cannot convert color temperature {} to Kelvin.", command);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.setValue(tempKelvin.intValue());
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Unhandled command type: {}", command.getClass().getName());
|
logger.warn("Unhandled command type: {}", command.getClass().getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stateObject.setState(state);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logger.warn("Unhandled command type: {}", command.getClass().getName());
|
logger.warn("Unhandled command type: {}", command.getClass().getName());
|
||||||
|
Loading…
Reference in New Issue
Block a user