Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Implemented configuration status handling for hue bridge. (#1819)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Kostadinov <alexander.g.kostadinov@gmail.com>
  • Loading branch information
alex-kostadinov authored and kaikreuzer committed Oct 11, 2016
1 parent 6ab0d1c commit 85a2c00
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import nl.q42.jue.exceptions.LinkButtonException
import nl.q42.jue.exceptions.UnauthorizedException

import org.eclipse.smarthome.binding.hue.handler.HueBridgeHandler
import org.eclipse.smarthome.binding.hue.internal.HueConfigStatusMessage
import org.eclipse.smarthome.config.core.Configuration
import org.eclipse.smarthome.config.core.status.ConfigStatusMessage
import org.eclipse.smarthome.core.thing.Bridge
import org.eclipse.smarthome.core.thing.ThingRegistry
import org.eclipse.smarthome.core.thing.ThingStatus
Expand Down Expand Up @@ -224,6 +226,48 @@ class HueBridgeHandlerOSGiTest extends OSGiTest {
assertThat(bridge.getStatus(), is(ThingStatus.OFFLINE))
assertThat(bridge.getStatusInfo().getStatusDetail(), is(not(ThingStatusDetail.BRIDGE_OFFLINE)))
}

@Test
void 'assert that a status configuration message for missing bridge IP is properly returned (IP is null)'() {
Configuration configuration = new Configuration().with {
put(HOST, null)
put(SERIAL_NUMBER, "testSerialNumber")
it
}
createBridgeThing(configuration)
HueBridgeHandler hueBridgeHandler = getRegisteredHueBridgeHandler()
def expected = ConfigStatusMessage.Builder.error(HOST)
.withMessageKeySuffix(HueConfigStatusMessage.IP_ADDRESS_MISSING.getMessageKey()).withArguments(HOST)
.build()
waitForAssert {
assertThat hueBridgeHandler.getConfigStatus().first(), is(expected)
}
}
@Test
void 'assert that a status configuration message for missing bridge IP is properly returned (IP is an empty string)'() {
Configuration configuration = new Configuration().with {
put(HOST, "")
put(SERIAL_NUMBER, "testSerialNumber")
it
}
createBridgeThing(configuration)
HueBridgeHandler hueBridgeHandler = getRegisteredHueBridgeHandler()
def expected = ConfigStatusMessage.Builder.error(HOST)
.withMessageKeySuffix(HueConfigStatusMessage.IP_ADDRESS_MISSING.getMessageKey()).withArguments(HOST)
.build()
waitForAssert {
assertThat hueBridgeHandler.getConfigStatus().first(), is(expected)
}
}
private Bridge createBridgeThing(Configuration configuration){
Bridge bridge = thingRegistry.createThingOfType(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config-status.error.missing-ip-address-configuration=No IP address for the hue bridge has been provided.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config-status.error.missing-ip-address-configuration=Es wurde keine IP Adresse f\u00FCr die Hue Bridge angegeben.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Import-Package: com.google.common.collect,
org.eclipse.smarthome.binding.hue,
org.eclipse.smarthome.binding.hue.handler,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.config.core.status,
org.eclipse.smarthome.config.discovery,
org.eclipse.smarthome.core.library.types,
org.eclipse.smarthome.core.thing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -21,15 +22,17 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.smarthome.binding.hue.internal.HueConfigStatusMessage;
import org.eclipse.smarthome.config.core.Configuration;
import org.eclipse.smarthome.config.core.status.ConfigStatusMessage;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.ThingStatus;
import org.eclipse.smarthome.core.thing.ThingStatusDetail;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.binding.BaseBridgeHandler;
import org.eclipse.smarthome.core.thing.binding.ConfigStatusBridgeHandler;
import org.eclipse.smarthome.core.types.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -57,7 +60,7 @@
* @author Stefan Bußweiler - Added new thing status handling
* @author Jochen Hiller - fixed status updates, use reachable=true/false for state compare
*/
public class HueBridgeHandler extends BaseBridgeHandler {
public class HueBridgeHandler extends ConfigStatusBridgeHandler {

private static final String LIGHT_STATE_ADDED = "added";

Expand Down Expand Up @@ -151,7 +154,7 @@ public void run() {
logger.error("An unexpected error occurred: {}", t.getMessage(), t);
}
}

private boolean isReachable(String ipAddress) {
try {
// note that InetAddress.isReachable is unreliable, see
Expand Down Expand Up @@ -491,4 +494,21 @@ private boolean isEqual(State state1, State state2) {
return colorModeIsEqual && effectIsEqual;
}

@Override
public Collection<ConfigStatusMessage> getConfigStatus() {
// The bridge IP address to be used for checks
final String bridgeIpAddress = (String) getThing().getConfiguration().get(HOST);
Collection<ConfigStatusMessage> configStatusMessages;

// Check whether an IP address is provided
if (bridgeIpAddress == null || bridgeIpAddress.isEmpty()) {
configStatusMessages = Collections.singletonList(ConfigStatusMessage.Builder.error(HOST)
.withMessageKeySuffix(HueConfigStatusMessage.IP_ADDRESS_MISSING.getMessageKey()).withArguments(HOST)
.build());
} else {
configStatusMessages = Collections.emptyList();
}

return configStatusMessages;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2014-2016 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.hue.internal;

import org.eclipse.smarthome.config.core.status.ConfigStatusMessage;

/**
* The {@link HueConfigStatusMessage} defines
* the keys to be used for {@link ConfigStatusMessage}s.
*
* @author Alexander Kostadinov - Initial contribution
*
*/
public enum HueConfigStatusMessage {
IP_ADDRESS_MISSING("missing-ip-address-configuration");

private String messageKey;

private HueConfigStatusMessage(String messageKey) {
this.messageKey = messageKey;
}

public String getMessageKey() {
return messageKey;
}
}

0 comments on commit 85a2c00

Please sign in to comment.