if (micro != other.micro) {
return false;
}
- if (minor != other.minor) {
- return false;
- }
- return true;
+ return minor == other.minor;
}
@Override
* @return ip address of proxy or null
*/
public String getProxyAddress() {
- return proxyaddress.equals("none") ? null : proxyaddress;
+ return "none".equals(proxyaddress) ? null : proxyaddress;
}
/**
* @return port of proxy or null
*/
public Integer getProxyPort() {
- return proxyaddress.equals("none") ? null : proxyport;
+ return "none".equals(proxyaddress) ? null : proxyport;
}
/**
* @return modifiability of group
*/
public boolean isModifiable() {
- return !id.equals("0");
+ return !"0".equals(id);
}
/**
@Override
protected Result doNetwork(String address, String requestMethod, @Nullable String body) throws IOException {
// GET requests cannot be scheduled, so will continue working normally for convenience
- if (requestMethod.equals("GET")) {
+ if ("GET".equals(requestMethod)) {
return super.doNetwork(address, requestMethod, body);
} else {
String extractedAddress = Util.quickMatch("^http://[^/]+(.+)$", address);
HS,
/**
- * Color temperature in mirek
+ * Color temperature in mired
*/
CT
}
if (sat != other.sat) {
return false;
}
- if (!Arrays.equals(xy, other.xy)) {
- return false;
- }
- return true;
+ return Arrays.equals(xy, other.xy);
}
}
} catch (IOException e) {
return false;
} catch (ApiException e) {
- if (e.getMessage().contains("SocketTimeout") || e.getMessage().contains("ConnectException")
- || e.getMessage().contains("SocketException")
- || e.getMessage().contains("NoRouteToHostException")) {
- return false;
- } else {
- // this seems to be only an authentication issue
- return true;
- }
+ String message = e.getMessage();
+ return message != null && //
+ !message.contains("SocketTimeout") && //
+ !message.contains("ConnectException") && //
+ !message.contains("SocketException") && //
+ !message.contains("NoRouteToHostException");
}
return true;
}
import org.openhab.binding.hue.internal.FullGroup;
import org.openhab.binding.hue.internal.Scene;
import org.openhab.binding.hue.internal.State;
-import org.openhab.binding.hue.internal.State.ColorMode;
import org.openhab.binding.hue.internal.StateUpdate;
import org.openhab.binding.hue.internal.dto.ColorTemperature;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.types.Command;
import org.openhab.core.types.StateOption;
-import org.openhab.core.types.UnDefType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private @Nullable Integer getCurrentColorTemp(@Nullable State groupState) {
Integer colorTemp = lastSentColorTemp;
if (colorTemp == null && groupState != null) {
- colorTemp = groupState.getColorTemperature();
+ return groupState.getColorTemperature();
}
return colorTemp;
}
private @Nullable StateUpdate convertBrightnessChangeToStateUpdate(IncreaseDecreaseType command, FullGroup group) {
- Integer currentBrightness = getCurrentBrightness(group);
+ Integer currentBrightness = getCurrentBrightness(group.getState());
if (currentBrightness == null) {
return null;
}
return createBrightnessStateUpdate(currentBrightness, newBrightness);
}
- private @Nullable Integer getCurrentBrightness(FullGroup group) {
- if (lastSentBrightness != null) {
- return lastSentBrightness;
+ private @Nullable Integer getCurrentBrightness(@Nullable State groupState) {
+ if (lastSentBrightness == null && groupState != null) {
+ return groupState.isOn() ? groupState.getBrightness() : 0;
}
- State currentState = group.getState();
- if (currentState == null) {
- return null;
- }
- return currentState.isOn() ? currentState.getBrightness() : 0;
+ return lastSentBrightness;
}
private StateUpdate createBrightnessStateUpdate(int currentBrightness, int newBrightness) {
}
updateState(CHANNEL_COLOR, hsbType);
- ColorMode colorMode = state.getColorMode();
- if (ColorMode.CT.equals(colorMode)) {
- updateState(CHANNEL_COLORTEMPERATURE,
- LightStateConverter.toColorTemperaturePercentType(state, colorTemperatureCapabilties));
- updateState(CHANNEL_COLORTEMPERATURE_ABS, LightStateConverter.toColorTemperature(state));
- } else {
- updateState(CHANNEL_COLORTEMPERATURE, UnDefType.UNDEF);
- updateState(CHANNEL_COLORTEMPERATURE_ABS, UnDefType.UNDEF);
- }
-
- PercentType brightnessPercentType = LightStateConverter.toBrightnessPercentType(state);
- if (!state.isOn()) {
- brightnessPercentType = PercentType.ZERO;
- }
+ PercentType brightnessPercentType = state.isOn() ? LightStateConverter.toBrightnessPercentType(state)
+ : PercentType.ZERO;
updateState(CHANNEL_BRIGHTNESS, brightnessPercentType);
updateState(CHANNEL_SWITCH, OnOffType.from(state.isOn()));
+ updateState(CHANNEL_COLORTEMPERATURE,
+ LightStateConverter.toColorTemperaturePercentType(state, colorTemperatureCapabilties));
+ updateState(CHANNEL_COLORTEMPERATURE_ABS, LightStateConverter.toColorTemperature(state));
+
return true;
}
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.hue.internal.FullLight;
import org.openhab.binding.hue.internal.State;
-import org.openhab.binding.hue.internal.State.ColorMode;
import org.openhab.binding.hue.internal.StateUpdate;
import org.openhab.binding.hue.internal.action.LightActions;
import org.openhab.binding.hue.internal.dto.Capabilities;
import org.openhab.core.types.Command;
import org.openhab.core.types.StateDescription;
import org.openhab.core.types.StateDescriptionFragmentBuilder;
-import org.openhab.core.types.UnDefType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
break;
case CHANNEL_SWITCH:
- logger.trace("CHANNEL_SWITCH handling command {}", command);
if (command instanceof OnOffType) {
lightState = LightStateConverter.toOnOffLightState((OnOffType) command);
if (isOsramPar16) {
private @Nullable Integer getCurrentColorTemp(@Nullable State lightState) {
Integer colorTemp = lastSentColorTemp;
if (colorTemp == null && lightState != null) {
- colorTemp = lightState.getColorTemperature();
+ return lightState.getColorTemperature();
}
return colorTemp;
}
private @Nullable StateUpdate convertBrightnessChangeToStateUpdate(IncreaseDecreaseType command, FullLight light) {
- StateUpdate stateUpdate = null;
Integer currentBrightness = getCurrentBrightness(light.getState());
- if (currentBrightness != null) {
- int newBrightness = LightStateConverter.toAdjustedBrightness(command, currentBrightness);
- stateUpdate = createBrightnessStateUpdate(currentBrightness, newBrightness);
+ if (currentBrightness == null) {
+ return null;
}
- return stateUpdate;
+ int newBrightness = LightStateConverter.toAdjustedBrightness(command, currentBrightness);
+ return createBrightnessStateUpdate(currentBrightness, newBrightness);
}
private @Nullable Integer getCurrentBrightness(@Nullable State lightState) {
- Integer brightness = lastSentBrightness;
- if (brightness == null && lightState != null) {
- if (!lightState.isOn()) {
- brightness = 0;
- } else {
- brightness = lightState.getBrightness();
- }
+ if (lastSentBrightness == null && lightState != null) {
+ return lightState.isOn() ? lightState.getBrightness() : 0;
}
- return brightness;
+ return lastSentBrightness;
}
private StateUpdate createBrightnessStateUpdate(int currentBrightness, int newBrightness) {
}
updateState(CHANNEL_COLOR, hsbType);
- ColorMode colorMode = state.getColorMode();
- if (ColorMode.CT.equals(colorMode)) {
- updateState(CHANNEL_COLORTEMPERATURE,
- LightStateConverter.toColorTemperaturePercentType(state, colorTemperatureCapabilties));
- updateState(CHANNEL_COLORTEMPERATURE_ABS, LightStateConverter.toColorTemperature(state));
- } else {
- updateState(CHANNEL_COLORTEMPERATURE, UnDefType.UNDEF);
- updateState(CHANNEL_COLORTEMPERATURE_ABS, UnDefType.UNDEF);
- }
-
- PercentType brightnessPercentType = LightStateConverter.toBrightnessPercentType(state);
- if (!state.isOn()) {
- brightnessPercentType = PercentType.ZERO;
- }
+ PercentType brightnessPercentType = state.isOn() ? LightStateConverter.toBrightnessPercentType(state)
+ : PercentType.ZERO;
updateState(CHANNEL_BRIGHTNESS, brightnessPercentType);
updateState(CHANNEL_SWITCH, OnOffType.from(state.isOn()));
+ updateState(CHANNEL_COLORTEMPERATURE,
+ LightStateConverter.toColorTemperaturePercentType(state, colorTemperatureCapabilties));
+ updateState(CHANNEL_COLORTEMPERATURE_ABS, LightStateConverter.toColorTemperature(state));
+
StringType stringType = LightStateConverter.toAlertStringType(state);
if (!"NULL".equals(stringType.toString())) {
updateState(CHANNEL_ALERT, stringType);
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingUID;
+import org.openhab.core.thing.binding.ThingHandlerCallback;
import org.openhab.core.thing.i18n.ChannelTypeI18nLocalizationService;
import org.openhab.core.types.Command;
return mockBridge;
}
};
+ hueLightHandler.setCallback(mock(ThingHandlerCallback.class));
hueLightHandler.initialize();
verify(mockThing).setProperty(eq(Thing.PROPERTY_MODEL_ID), eq(expectedModel));