Skip to content

Commit

Permalink
[lifx] Handle and provide QuantityType for color-temperature-abs chan…
Browse files Browse the repository at this point in the history
…nel (openhab#14025)

See openhab/openhab-core#3129

Signed-off-by: Cody Cutrer <[email protected]>
Signed-off-by: Andras Uhrin <[email protected]>
  • Loading branch information
ccutrer authored and andrasU committed Jan 6, 2024
1 parent 63e96b8 commit 901346b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 67 deletions.
42 changes: 21 additions & 21 deletions bundles/org.openhab.binding.lifx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ Thing lifx:colorirlight:porch [ host="10.120.130.4", fadetime=0 ]

All devices support some of the following channels:

| Channel Type ID | Item Type | Description | Thing Types |
|--------------------|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| abstemperature | Number | This channel supports adjusting the color temperature in Kelvin. | colorlight, colorhevlight, colorirlight, colormzlight, tilelight, whitelight |
| abstemperaturezone | Number | This channel supports adjusting the zone color temperature in Kelvin. | colormzlight |
| brightness | Dimmer | This channel supports adjusting the brightness value. | whitelight |
| color | Color | This channel supports full color control with hue, saturation and brightness values. | colorlight, colorhevlight, colorirlight, colormzlight, tilelight |
| colorzone | Color | This channel supports full zone color control with hue, saturation and brightness values. | colormzlight |
| effect | String | This channel represents a type of light effect (e.g. for tile light: off, morph, flame) | tilelight |
| hevcycle | Switch | This channel supports starting and stopping the HEV clean cycle. | colorhevlight |
| infrared | Dimmer | This channel supports adjusting the infrared value. _Note:_ IR capable lights only activate their infrared LEDs when the brightness drops below a certain level. | colorirlight |
| signalstrength | Number | This channel represents signal strength with values 0, 1, 2, 3 or 4; 0 being worst strength and 4 being best strength. | colorlight, colorhevlight, colorirlight, colormzlight, tilelight, whitelight |
| temperature | Dimmer | This channel supports adjusting the color temperature from cold (0%) to warm (100%). | colorlight, colorhevlight, colorirlight, colormzlight, tilelight, whitelight |
| temperaturezone | Dimmer | This channel supports adjusting the zone color temperature from cold (0%) to warm (100%). | colormzlight |
| Channel Type ID | Item Type | Description | Thing Types |
|--------------------|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| abstemperature | Number:Temperature | This channel supports adjusting the color temperature in Kelvin. | colorlight, colorhevlight, colorirlight, colormzlight, tilelight, whitelight |
| abstemperaturezone | Number:Temperature | This channel supports adjusting the zone color temperature in Kelvin. | colormzlight |
| brightness | Dimmer | This channel supports adjusting the brightness value. | whitelight |
| color | Color | This channel supports full color control with hue, saturation and brightness values. | colorlight, colorhevlight, colorirlight, colormzlight, tilelight |
| colorzone | Color | This channel supports full zone color control with hue, saturation and brightness values. | colormzlight |
| effect | String | This channel represents a type of light effect (e.g. for tile light: off, morph, flame) | tilelight |
| hevcycle | Switch | This channel supports starting and stopping the HEV clean cycle. | colorhevlight |
| infrared | Dimmer | This channel supports adjusting the infrared value. _Note:_ IR capable lights only activate their infrared LEDs when the brightness drops below a certain level. | colorirlight |
| signalstrength | Number | This channel represents signal strength with values 0, 1, 2, 3 or 4; 0 being worst strength and 4 being best strength. | colorlight, colorhevlight, colorirlight, colormzlight, tilelight, whitelight |
| temperature | Dimmer | This channel supports adjusting the color temperature from cold (0%) to warm (100%). | colorlight, colorhevlight, colorirlight, colormzlight, tilelight, whitelight |
| temperaturezone | Dimmer | This channel supports adjusting the zone color temperature from cold (0%) to warm (100%). | colormzlight |

The _color_ and _brightness_ channels have a "Power On Brightness" configuration option that is used to determine the brightness when a light is switched on.
When it is left empty, the brightness of a light remains unchanged when a light is switched on or off.
Expand Down Expand Up @@ -175,44 +175,44 @@ Thing lifx:whitelight:kitchen [ deviceId="D073D5D4D4D4", fadetime=150 ]
// Living
Color Living_Color { channel="lifx:colorlight:living:color" }
Dimmer Living_Temperature { channel="lifx:colorlight:living:temperature" }
Number Living_Abs_Temperature { channel="lifx:colorlight:living:abstemperature" }
Number:Temperature Living_Abs_Temperature "Living Room Lights Color Temperature [%d K]" { channel="lifx:colorlight:living:abstemperature" }

// Living2 (alternative approach)
Color Living2_Color { channel="lifx:colorlight:living2:color" }
Switch Living2_Switch { channel="lifx:colorlight:living2:color" }
Dimmer Living2_Dimmer { channel="lifx:colorlight:living2:color" }
Dimmer Living2_Temperature { channel="lifx:colorlight:living2:temperature" }
Number Living2_Abs_Temperature { channel="lifx:colorlight:living2:abstemperature" }
Number:Temperature Living2_Abs_Temperature "Living Room Lights Color Temperature [%d K]" { channel="lifx:colorlight:living2:abstemperature" }

// Desk
Color Desk_Color { channel="lifx:colorhevlight:desk:color" }
Dimmer Desk_Temperature { channel="lifx:colorhevlight:desk:temperature" }
Number Desk_Abs_Temperature { channel="lifx:colorhevlight:desk:abstemperature" }
Number:Temperature Desk_Abs_Temperature "Desk Lamp Color Temperature [%d K]" { channel="lifx:colorhevlight:desk:abstemperature" }
Switch Desk_HEV_Cycle { channel="lifx:colorhevlight:desk:hevcycle" }

// Porch
Color Porch_Color { channel="lifx:colorirlight:porch:color" }
Dimmer Porch_Infrared { channel="lifx:colorirlight:porch:infrared" }
Dimmer Porch_Temperature { channel="lifx:colorirlight:porch:temperature" }
Number Porch_Abs_Temperature { channel="lifx:colorirlight:porch:abstemperature" }
Number:Temperature Porch_Abs_Temperature "Porch Light Color Temperature [%d K]" { channel="lifx:colorirlight:porch:abstemperature" }
Number Porch_Signal_Strength { channel="lifx:colorirlight:porch:signalstrength" }

// Ceiling
Color Ceiling_Color { channel="lifx:colormzlight:ceiling:color" }
Dimmer Ceiling_Temperature { channel="lifx:colormzlight:ceiling:temperature" }
Number Ceiling_Abs_Temperature { channel="lifx:colormzlight:ceiling:abstemperature" }
Number:Temperature Ceiling_Abs_Temperature "Ceiling Light Color Temperature [%d K]" { channel="lifx:colormzlight:ceiling:abstemperature" }
Color Ceiling_Color_Zone_0 { channel="lifx:colormzlight:ceiling:colorzone0" }
Dimmer Ceiling_Temperature_Zone_0 { channel="lifx:colormzlight:ceiling:temperaturezone0" }
Number Ceiling_Abs_Temperature_Zone_0 { channel="lifx:colormzlight:ceiling:abstemperaturezone0" }
Number:Temperature Ceiling_Abs_Temperature_Zone_0 "Ceiling Light 0 Color Temperature [%d K]" { channel="lifx:colormzlight:ceiling:abstemperaturezone0" }
Color Ceiling_Color_Zone_15 { channel="lifx:colormzlight:ceiling:colorzone15" }
Dimmer Ceiling_Temperature_Zone_15 { channel="lifx:colormzlight:ceiling:temperaturezone15" }
Number Ceiling_Abs_Temperature_Zone_15 { channel="lifx:colormzlight:ceiling:abstemperaturezone15" }
Number:Temperature Ceiling_Abs_Temperature_Zone_15 "Ceiling Light 15 Color Temperature [%d K]" { channel="lifx:colormzlight:ceiling:abstemperaturezone15" }

// Kitchen
Switch Kitchen_Toggle { channel="lifx:whitelight:kichen:brightness" }
Dimmer Kitchen_Brightness { channel="lifx:whitelight:kitchen:brightness" }
Dimmer Kitchen_Temperature { channel="lifx:whitelight:kitchen:temperature" }
Number Kitchen_Abs_Temperature { channel="lifx:whitelight:kitchen:abstemperature" }
Number:Temperature Kitchen_Abs_Temperature "Kitchen Light Color Temperature [%d K]" { channel="lifx:whitelight:kitchen:abstemperature" }
```

### demo.sitemap:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2023 Contributors to the openHAB project
* Copyright (c) 2010-2022 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
Expand Down Expand Up @@ -561,67 +561,68 @@ public void handleCommand(ChannelUID channelUID, Command command) {
switch (channelUID.getId()) {
case CHANNEL_ABS_TEMPERATURE:
case CHANNEL_TEMPERATURE:
if (command instanceof DecimalType || (command instanceof QuantityType quantityCommand
&& quantityCommand.toInvertibleUnit(Units.KELVIN) != null)) {
if (command instanceof DecimalType || (command instanceof QuantityType
&& ((QuantityType) command).toInvertibleUnit(Units.KELVIN) != null)) {
return () -> handleTemperatureCommand(command);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
return () -> handleIncreaseDecreaseTemperatureCommand(increaseDecreaseCommand);
} else if (command instanceof IncreaseDecreaseType) {
return () -> handleIncreaseDecreaseTemperatureCommand((IncreaseDecreaseType) command);
}
case CHANNEL_BRIGHTNESS:
if (command instanceof PercentType percentCommand) {
return () -> handlePercentCommand(percentCommand);
} else if (command instanceof OnOffType onOffCommand) {
return () -> handleOnOffCommand(onOffCommand);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
return () -> handleIncreaseDecreaseCommand(increaseDecreaseCommand);
if (command instanceof PercentType) {
return () -> handlePercentCommand((PercentType) command);
} else if (command instanceof OnOffType) {
return () -> handleOnOffCommand((OnOffType) command);
} else if (command instanceof IncreaseDecreaseType) {
return () -> handleIncreaseDecreaseCommand((IncreaseDecreaseType) command);
}
case CHANNEL_COLOR:
if (command instanceof HSBType hsbCommand) {
return () -> handleHSBCommand(hsbCommand);
} else if (command instanceof PercentType percentCommand) {
return () -> handlePercentCommand(percentCommand);
} else if (command instanceof OnOffType onOffCommand) {
return () -> handleOnOffCommand(onOffCommand);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
return () -> handleIncreaseDecreaseCommand(increaseDecreaseCommand);
if (command instanceof HSBType) {
return () -> handleHSBCommand((HSBType) command);
} else if (command instanceof PercentType) {
return () -> handlePercentCommand((PercentType) command);
} else if (command instanceof OnOffType) {
return () -> handleOnOffCommand((OnOffType) command);
} else if (command instanceof IncreaseDecreaseType) {
return () -> handleIncreaseDecreaseCommand((IncreaseDecreaseType) command);
}
case CHANNEL_EFFECT:
if (command instanceof StringType stringCommand && features.hasFeature(TILE_EFFECT)) {
return () -> handleTileEffectCommand(stringCommand);
if (command instanceof StringType && features.hasFeature(TILE_EFFECT)) {
return () -> handleTileEffectCommand((StringType) command);
}
case CHANNEL_HEV_CYCLE:
if (command instanceof OnOffType onOffCommand) {
return () -> handleHevCycleCommand(onOffCommand);
if (command instanceof OnOffType) {
return () -> handleHevCycleCommand((OnOffType) command);
}
case CHANNEL_INFRARED:
if (command instanceof PercentType percentCommand) {
return () -> handleInfraredCommand(percentCommand);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
return () -> handleIncreaseDecreaseInfraredCommand(increaseDecreaseCommand);
if (command instanceof PercentType) {
return () -> handleInfraredCommand((PercentType) command);
} else if (command instanceof IncreaseDecreaseType) {
return () -> handleIncreaseDecreaseInfraredCommand((IncreaseDecreaseType) command);
}
default:
try {
if (channelUID.getId().startsWith(CHANNEL_ABS_TEMPERATURE_ZONE)) {
int zoneIndex = Integer.parseInt(channelUID.getId().replace(CHANNEL_ABS_TEMPERATURE_ZONE, ""));
if (command instanceof DecimalType || (command instanceof QuantityType quantityCommand
&& quantityCommand.toInvertibleUnit(Units.KELVIN) != null)) {
if (command instanceof DecimalType || (command instanceof QuantityType
&& ((QuantityType) command).toInvertibleUnit(Units.KELVIN) != null)) {
return () -> handleTemperatureCommand(command, zoneIndex);
}
} else if (channelUID.getId().startsWith(CHANNEL_COLOR_ZONE)) {
int zoneIndex = Integer.parseInt(channelUID.getId().replace(CHANNEL_COLOR_ZONE, ""));
if (command instanceof HSBType hsbCommand) {
return () -> handleHSBCommand(hsbCommand, zoneIndex);
} else if (command instanceof PercentType percentCommand) {
return () -> handlePercentCommand(percentCommand, zoneIndex);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
return () -> handleIncreaseDecreaseCommand(increaseDecreaseCommand, zoneIndex);
if (command instanceof HSBType) {
return () -> handleHSBCommand((HSBType) command, zoneIndex);
} else if (command instanceof PercentType) {
return () -> handlePercentCommand((PercentType) command, zoneIndex);
} else if (command instanceof IncreaseDecreaseType) {
return () -> handleIncreaseDecreaseCommand((IncreaseDecreaseType) command, zoneIndex);
}
} else if (channelUID.getId().startsWith(CHANNEL_TEMPERATURE_ZONE)) {
int zoneIndex = Integer.parseInt(channelUID.getId().replace(CHANNEL_TEMPERATURE_ZONE, ""));
if (command instanceof PercentType percentCommand) {
return () -> handleTemperatureCommand(percentCommand, zoneIndex);
} else if (command instanceof IncreaseDecreaseType increaseDecreaseCommand) {
return () -> handleIncreaseDecreaseTemperatureCommand(increaseDecreaseCommand, zoneIndex);
if (command instanceof PercentType) {
return () -> handleTemperatureCommand((PercentType) command, zoneIndex);
} else if (command instanceof IncreaseDecreaseType) {
return () -> handleIncreaseDecreaseTemperatureCommand((IncreaseDecreaseType) command,
zoneIndex);
}
}
} catch (NumberFormatException e) {
Expand Down
Loading

0 comments on commit 901346b

Please sign in to comment.