This repository has been archived by the owner on May 7, 2020. It is now read-only.
[Tradfri] Support for new RGB bulbs #4251 #4271
Merged
kaikreuzer
merged 2 commits into
eclipse-archived:master
from
hreichert:tradfri-color-support-4251
Sep 19, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
...i.test/src/test/java/org/eclipse/smarthome/binding/tradfri/internal/TradfriColorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/** | ||
* Copyright (c) 2014-2017 by the respective copyright holders. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.eclipse.smarthome.binding.tradfri.internal; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.eclipse.smarthome.core.library.types.HSBType; | ||
import org.eclipse.smarthome.core.library.types.PercentType; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests for {@link TradfriColor}. | ||
* | ||
* @author Holger Reichert - Initial contribution | ||
*/ | ||
public class TradfriColorTest { | ||
|
||
@Test | ||
public void testFromCieKnownGood1() { | ||
TradfriColor color = TradfriColor.fromCie(29577, 12294, 254); | ||
assertNotNull(color); | ||
assertEquals(254, (int) color.rgbR); | ||
assertEquals(2, (int) color.rgbG); | ||
assertEquals(158, (int) color.rgbB); | ||
assertEquals(29577, (int) color.xyX); | ||
assertEquals(12294, (int) color.xyY); | ||
assertEquals(254, (int) color.brightness); | ||
assertNotNull(color.hsbType); | ||
assertEquals(323, color.hsbType.getHue().intValue()); | ||
assertEquals(99, color.hsbType.getSaturation().intValue()); | ||
assertEquals(100, color.hsbType.getBrightness().intValue()); | ||
} | ||
|
||
@Test | ||
public void testFromCieKnownGood2() { | ||
TradfriColor color = TradfriColor.fromCie(19983, 37417, 84); | ||
assertNotNull(color); | ||
assertEquals(30, (int) color.rgbR); | ||
assertEquals(84, (int) color.rgbG); | ||
assertEquals(7, (int) color.rgbB); | ||
assertEquals(19983, (int) color.xyX); | ||
assertEquals(37417, (int) color.xyY); | ||
assertEquals(84, (int) color.brightness); | ||
assertNotNull(color.hsbType); | ||
assertEquals(102, color.hsbType.getHue().intValue()); | ||
assertEquals(89, color.hsbType.getSaturation().intValue()); | ||
assertEquals(33, color.hsbType.getBrightness().intValue()); | ||
} | ||
|
||
@Test | ||
public void testFromHSBTypeKnownGood1() { | ||
TradfriColor color = TradfriColor.fromHSBType(HSBType.RED); | ||
assertNotNull(color); | ||
assertEquals(254, (int) color.rgbR); | ||
assertEquals(0, (int) color.rgbG); | ||
assertEquals(0, (int) color.rgbB); | ||
assertEquals(45914, (int) color.xyX); | ||
assertEquals(19615, (int) color.xyY); | ||
assertEquals(254, (int) color.brightness); | ||
assertNotNull(color.hsbType); | ||
assertEquals(0, color.hsbType.getHue().intValue()); | ||
assertEquals(100, color.hsbType.getSaturation().intValue()); | ||
assertEquals(100, color.hsbType.getBrightness().intValue()); | ||
} | ||
|
||
@Test | ||
public void testConversionReverse() { | ||
// convert from HSBType | ||
TradfriColor color = TradfriColor.fromHSBType(HSBType.GREEN); | ||
assertNotNull(color); | ||
assertEquals(0, (int) color.rgbR); | ||
assertEquals(254, (int) color.rgbG); // 254 instead of 255 - only approximated calculation | ||
assertEquals(0, (int) color.rgbB); | ||
assertEquals(11299, (int) color.xyX); | ||
assertEquals(48941, (int) color.xyY); | ||
assertEquals(254, (int) color.brightness); | ||
assertNotNull(color.hsbType); | ||
assertEquals(120, color.hsbType.getHue().intValue()); | ||
assertEquals(100, color.hsbType.getSaturation().intValue()); | ||
assertEquals(100, color.hsbType.getBrightness().intValue()); | ||
// convert the result again based on the XY values | ||
TradfriColor reverse = TradfriColor.fromCie(color.xyX, color.xyY, color.brightness); | ||
assertNotNull(reverse); | ||
assertEquals(0, (int) reverse.rgbR); | ||
assertEquals(254, (int) reverse.rgbG); | ||
assertEquals(0, (int) reverse.rgbB); | ||
assertEquals(11299, (int) reverse.xyX); | ||
assertEquals(48941, (int) reverse.xyY); | ||
assertEquals(254, (int) reverse.brightness); | ||
assertNotNull(reverse.hsbType); | ||
assertEquals(120, reverse.hsbType.getHue().intValue()); | ||
assertEquals(100, reverse.hsbType.getSaturation().intValue()); | ||
assertEquals(100, reverse.hsbType.getBrightness().intValue()); | ||
} | ||
|
||
@Test | ||
public void testFromColorTemperatureMinMiddleMax() { | ||
// coldest color temperature -> preset 1 | ||
TradfriColor colorMin = TradfriColor.fromColorTemperature(PercentType.ZERO); | ||
assertNotNull(colorMin); | ||
assertEquals(24933, (int) colorMin.xyX); | ||
assertEquals(24691, (int) colorMin.xyY); | ||
// middle color temperature -> preset 2 | ||
TradfriColor colorMiddle = TradfriColor.fromColorTemperature(new PercentType(50)); | ||
assertNotNull(colorMiddle); | ||
assertEquals(30138, (int) colorMiddle.xyX); | ||
assertEquals(26909, (int) colorMiddle.xyY); | ||
// warmest color temperature -> preset 3 | ||
TradfriColor colorMax = TradfriColor.fromColorTemperature(PercentType.HUNDRED); | ||
assertNotNull(colorMax); | ||
assertEquals(33137, (int) colorMax.xyX); | ||
assertEquals(27211, (int) colorMax.xyY); | ||
} | ||
|
||
@Test | ||
public void testFromColorTemperatureInbetween() { | ||
// 30 percent must be between preset 1 and 2 | ||
TradfriColor color2 = TradfriColor.fromColorTemperature(new PercentType(30)); | ||
assertNotNull(color2); | ||
assertEquals(28056, (int) color2.xyX); | ||
assertEquals(26022, (int) color2.xyY); | ||
// 70 percent must be between preset 2 and 3 | ||
TradfriColor color3 = TradfriColor.fromColorTemperature(new PercentType(70)); | ||
assertNotNull(color3); | ||
assertEquals(31338, (int) color3.xyX); | ||
assertEquals(27030, (int) color3.xyY); | ||
} | ||
|
||
@Test | ||
public void testCalculateColorTemperature() { | ||
// preset 1 -> coldest -> 0 percent | ||
PercentType preset1 = TradfriColor.calculateColorTemperature(24933, 24691); | ||
assertEquals(0, preset1.intValue()); | ||
// preset 2 -> middle -> 50 percent | ||
PercentType preset2 = TradfriColor.calculateColorTemperature(30138, 26909); | ||
assertEquals(50, preset2.intValue()); | ||
// preset 3 -> warmest -> 100 percent | ||
PercentType preset3 = TradfriColor.calculateColorTemperature(33137, 27211); | ||
assertEquals(100, preset3.intValue()); | ||
// preset 3 -> warmest -> 100 percent | ||
PercentType colder = TradfriColor.calculateColorTemperature(22222, 23333); | ||
assertEquals(0, colder.intValue()); | ||
// preset 3 -> warmest -> 100 percent | ||
PercentType temp3 = TradfriColor.calculateColorTemperature(34000, 34000); | ||
assertEquals(100, temp3.intValue()); | ||
// mixed case 1 | ||
PercentType mixed1 = TradfriColor.calculateColorTemperature(0, 1000000); | ||
assertEquals(0, mixed1.intValue()); | ||
// mixed case 1 | ||
PercentType mixed2 = TradfriColor.calculateColorTemperature(1000000, 0); | ||
assertEquals(100, mixed2.intValue()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am noticing that this table was already incorrect - neither 0100 nor 0220 nor 0210 should have an X for On/Off... - so we could actually remove the whole column...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good point, as there is no "onoff" channel. Should I open a new issue for this? I want to extend the documentation anyway with more examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simply remove the column as part of this PR - or we first merge and you can come up with a new PR that enhances the documentation in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for option 2 - new PR when the enhancements are done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok!