[hue] Add workaround for LK Wiser products (#11572)
* Add workaround for LK Wiser products. Fixes #11571 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk> * Optimize vendor check. Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
40d8e1c175
commit
afdbd09eb3
|
@ -67,6 +67,7 @@ import org.slf4j.LoggerFactory;
|
||||||
* @author Denis Dudnik - switched to internally integrated source of Jue library
|
* @author Denis Dudnik - switched to internally integrated source of Jue library
|
||||||
* @author Christoph Weitkamp - Added support for bulbs using CIE XY colormode only
|
* @author Christoph Weitkamp - Added support for bulbs using CIE XY colormode only
|
||||||
* @author Jochen Leopold - Added support for custom fade times
|
* @author Jochen Leopold - Added support for custom fade times
|
||||||
|
* @author Jacob Laursen - Add workaround for LK Wiser products
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class HueLightHandler extends BaseThingHandler implements HueLightActionsHandler, LightStatusListener {
|
public class HueLightHandler extends BaseThingHandler implements HueLightActionsHandler, LightStatusListener {
|
||||||
|
@ -76,6 +77,7 @@ public class HueLightHandler extends BaseThingHandler implements HueLightActions
|
||||||
THING_TYPE_ON_OFF_LIGHT, THING_TYPE_ON_OFF_PLUG, THING_TYPE_DIMMABLE_PLUG);
|
THING_TYPE_ON_OFF_LIGHT, THING_TYPE_ON_OFF_PLUG, THING_TYPE_DIMMABLE_PLUG);
|
||||||
|
|
||||||
public static final String OSRAM_PAR16_50_TW_MODEL_ID = "PAR16_50_TW";
|
public static final String OSRAM_PAR16_50_TW_MODEL_ID = "PAR16_50_TW";
|
||||||
|
public static final String LK_WISER_MODEL_ID = "LK_Dimmer";
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(HueLightHandler.class);
|
private final Logger logger = LoggerFactory.getLogger(HueLightHandler.class);
|
||||||
|
|
||||||
|
@ -89,8 +91,14 @@ public class HueLightHandler extends BaseThingHandler implements HueLightActions
|
||||||
private @Nullable Integer lastSentColorTemp;
|
private @Nullable Integer lastSentColorTemp;
|
||||||
private @Nullable Integer lastSentBrightness;
|
private @Nullable Integer lastSentBrightness;
|
||||||
|
|
||||||
// Flag to indicate whether the bulb is of type Osram par16 50 TW or not
|
/**
|
||||||
|
* Flag to indicate whether the bulb is of type Osram par16 50 TW
|
||||||
|
*/
|
||||||
private boolean isOsramPar16 = false;
|
private boolean isOsramPar16 = false;
|
||||||
|
/**
|
||||||
|
* Flag to indicate whether the dimmer/relay is of type LK Wiser by Schneider Electric
|
||||||
|
*/
|
||||||
|
private boolean isLkWiser = false;
|
||||||
|
|
||||||
private boolean propertiesInitializedSuccessfully = false;
|
private boolean propertiesInitializedSuccessfully = false;
|
||||||
private boolean capabilitiesInitializedSuccessfully = false;
|
private boolean capabilitiesInitializedSuccessfully = false;
|
||||||
|
@ -159,6 +167,15 @@ public class HueLightHandler extends BaseThingHandler implements HueLightActions
|
||||||
String modelId = fullLight.getNormalizedModelID();
|
String modelId = fullLight.getNormalizedModelID();
|
||||||
if (modelId != null) {
|
if (modelId != null) {
|
||||||
properties.put(PROPERTY_MODEL_ID, modelId);
|
properties.put(PROPERTY_MODEL_ID, modelId);
|
||||||
|
|
||||||
|
switch (modelId) {
|
||||||
|
case OSRAM_PAR16_50_TW_MODEL_ID:
|
||||||
|
isOsramPar16 = true;
|
||||||
|
break;
|
||||||
|
case LK_WISER_MODEL_ID:
|
||||||
|
isLkWiser = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
properties.put(PROPERTY_VENDOR, fullLight.getManufacturerName());
|
properties.put(PROPERTY_VENDOR, fullLight.getManufacturerName());
|
||||||
properties.put(PRODUCT_NAME, fullLight.getProductName());
|
properties.put(PRODUCT_NAME, fullLight.getProductName());
|
||||||
|
@ -167,7 +184,6 @@ public class HueLightHandler extends BaseThingHandler implements HueLightActions
|
||||||
properties.put(UNIQUE_ID, uniqueID);
|
properties.put(UNIQUE_ID, uniqueID);
|
||||||
}
|
}
|
||||||
updateProperties(properties);
|
updateProperties(properties);
|
||||||
isOsramPar16 = OSRAM_PAR16_50_TW_MODEL_ID.equals(modelId);
|
|
||||||
propertiesInitializedSuccessfully = true;
|
propertiesInitializedSuccessfully = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,6 +281,8 @@ public class HueLightHandler extends BaseThingHandler implements HueLightActions
|
||||||
newState = LightStateConverter.toOnOffLightState((OnOffType) command);
|
newState = LightStateConverter.toOnOffLightState((OnOffType) command);
|
||||||
if (isOsramPar16) {
|
if (isOsramPar16) {
|
||||||
newState = addOsramSpecificCommands(newState, (OnOffType) command);
|
newState = addOsramSpecificCommands(newState, (OnOffType) command);
|
||||||
|
} else if (isLkWiser) {
|
||||||
|
newState = addLkWiserSpecificCommands(newState, (OnOffType) command);
|
||||||
}
|
}
|
||||||
} else if (command instanceof IncreaseDecreaseType) {
|
} else if (command instanceof IncreaseDecreaseType) {
|
||||||
newState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
|
newState = convertBrightnessChangeToStateUpdate((IncreaseDecreaseType) command, light);
|
||||||
|
@ -285,6 +303,8 @@ public class HueLightHandler extends BaseThingHandler implements HueLightActions
|
||||||
newState = LightStateConverter.toOnOffLightState((OnOffType) command);
|
newState = LightStateConverter.toOnOffLightState((OnOffType) command);
|
||||||
if (isOsramPar16) {
|
if (isOsramPar16) {
|
||||||
newState = addOsramSpecificCommands(newState, (OnOffType) command);
|
newState = addOsramSpecificCommands(newState, (OnOffType) command);
|
||||||
|
} else if (isLkWiser) {
|
||||||
|
newState = addLkWiserSpecificCommands(newState, (OnOffType) command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastColorTemp = lastSentColorTemp;
|
lastColorTemp = lastSentColorTemp;
|
||||||
|
@ -353,7 +373,7 @@ public class HueLightHandler extends BaseThingHandler implements HueLightActions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Applies additional {@link StateUpdate} commands as a workaround for Osram
|
* Applies additional {@link StateUpdate} commands as a workaround for Osram
|
||||||
* Lightify PAR16 TW firmware bug. Also see
|
* Lightify PAR16 TW firmware bug. Also see
|
||||||
* http://www.everyhue.com/vanilla/discussion/1756/solved-lightify-turning-off
|
* http://www.everyhue.com/vanilla/discussion/1756/solved-lightify-turning-off
|
||||||
|
@ -367,6 +387,18 @@ public class HueLightHandler extends BaseThingHandler implements HueLightActions
|
||||||
return lightState;
|
return lightState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies additional {@link StateUpdate} commands as a workaround for LK Wiser
|
||||||
|
* Dimmer/Relay firmware bug. Additional details here:
|
||||||
|
* https://techblog.vindvejr.dk/?p=455
|
||||||
|
*/
|
||||||
|
private StateUpdate addLkWiserSpecificCommands(StateUpdate lightState, OnOffType actionType) {
|
||||||
|
if (actionType.equals(OnOffType.OFF)) {
|
||||||
|
lightState.setTransitionTime(0);
|
||||||
|
}
|
||||||
|
return lightState;
|
||||||
|
}
|
||||||
|
|
||||||
private @Nullable StateUpdate convertColorTempChangeToStateUpdate(IncreaseDecreaseType command, FullLight light) {
|
private @Nullable StateUpdate convertColorTempChangeToStateUpdate(IncreaseDecreaseType command, FullLight light) {
|
||||||
StateUpdate stateUpdate = null;
|
StateUpdate stateUpdate = null;
|
||||||
Integer currentColorTemp = getCurrentColorTemp(light.getState());
|
Integer currentColorTemp = getCurrentColorTemp(light.getState());
|
||||||
|
|
|
@ -56,6 +56,7 @@ import com.google.gson.JsonParser;
|
||||||
* @author Denis Dudnik - switched to internally integrated source of Jue library
|
* @author Denis Dudnik - switched to internally integrated source of Jue library
|
||||||
* @author Simon Kaufmann - migrated to plain Java test
|
* @author Simon Kaufmann - migrated to plain Java test
|
||||||
* @author Christoph Weitkamp - Added support for bulbs using CIE XY colormode only
|
* @author Christoph Weitkamp - Added support for bulbs using CIE XY colormode only
|
||||||
|
* @author Jacob Laursen - Add workaround for LK Wiser products
|
||||||
*/
|
*/
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class HueLightHandlerTest {
|
public class HueLightHandlerTest {
|
||||||
|
@ -95,6 +96,15 @@ public class HueLightHandlerTest {
|
||||||
expectedReply);
|
expectedReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void assertCommandForLkWiserForBrightnessChannelOff() {
|
||||||
|
final String expectedReply = "{\"on\" : false, \"transitiontime\" : 0}";
|
||||||
|
final String vendor = "Schneider Electric";
|
||||||
|
assertSendCommand(CHANNEL_BRIGHTNESS, OnOffType.OFF,
|
||||||
|
new HueLightState(HueLightHandler.LK_WISER_MODEL_ID, vendor), expectedReply,
|
||||||
|
HueLightHandler.LK_WISER_MODEL_ID, vendor);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void assertCommandForColorChannelOn() {
|
public void assertCommandForColorChannelOn() {
|
||||||
String expectedReply = "{\"on\" : true}";
|
String expectedReply = "{\"on\" : true}";
|
||||||
|
|
Loading…
Reference in New Issue