Skip to content

Commit

Permalink
Extend hue bridge with scene channel
Browse files Browse the repository at this point in the history
Signed-off-by: leluna <[email protected]>
  • Loading branch information
leluna committed Mar 22, 2020
1 parent 5200d19 commit 7e2a3bd
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* @author Samuel Leisering - added API-Version
*/
public class Config {
private String bridgeid;
private String name;
private String swversion;
private String apiversion;
Expand All @@ -46,15 +45,6 @@ public class Config {
Config() {
}

/**
* Returns the bridge ID.
*
* @return unique ID of the bridge
*/
public String getBridgeId() {
return bridgeid;
}

/**
* Returns the name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class HueBindingConstants {

// bridge
public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "bridge");
public static final ThingTypeUID THING_TYPE_GATEWAY = new ThingTypeUID(BINDING_ID, "gateway");

// generic thing types
public static final ThingTypeUID THING_TYPE_ON_OFF_LIGHT = new ThingTypeUID(BINDING_ID, "0000");
Expand Down Expand Up @@ -91,8 +90,5 @@ public class HueBindingConstants {
public static final String UNIQUE_ID = "uniqueId";
public static final String FADETIME = "fadetime";

// Gateway config properties
public static final String BRIDGE_ID = "bridgeId";

public static final String NORMALIZE_ID_REGEX = "[^a-zA-Z0-9_]";
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.smarthome.core.thing.binding.ThingHandlerFactory;
import org.openhab.binding.hue.internal.discovery.HueLightDiscoveryService;
import org.openhab.binding.hue.internal.handler.HueBridgeHandler;
import org.openhab.binding.hue.internal.handler.HueGatewayHandler;
import org.openhab.binding.hue.internal.handler.HueLightHandler;
import org.openhab.binding.hue.internal.handler.sensors.ClipHandler;
import org.openhab.binding.hue.internal.handler.sensors.DimmerSwitchHandler;
Expand All @@ -59,12 +58,12 @@
@Component(service = ThingHandlerFactory.class, configurationPid = "binding.hue")
public class HueThingHandlerFactory extends BaseThingHandlerFactory {

public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.unmodifiableSet(
Stream.of(HueBridgeHandler.SUPPORTED_THING_TYPES.stream(), HueGatewayHandler.SUPPORTED_THING_TYPES.stream(),
HueLightHandler.SUPPORTED_THING_TYPES.stream(), DimmerSwitchHandler.SUPPORTED_THING_TYPES.stream(),
TapSwitchHandler.SUPPORTED_THING_TYPES.stream(), PresenceHandler.SUPPORTED_THING_TYPES.stream(),
TemperatureHandler.SUPPORTED_THING_TYPES.stream(), LightLevelHandler.SUPPORTED_THING_TYPES.stream(),
ClipHandler.SUPPORTED_THING_TYPES.stream()).flatMap(i -> i).collect(Collectors.toSet()));
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections.unmodifiableSet(Stream
.of(HueBridgeHandler.SUPPORTED_THING_TYPES.stream(), HueLightHandler.SUPPORTED_THING_TYPES.stream(),
DimmerSwitchHandler.SUPPORTED_THING_TYPES.stream(), TapSwitchHandler.SUPPORTED_THING_TYPES.stream(),
PresenceHandler.SUPPORTED_THING_TYPES.stream(), TemperatureHandler.SUPPORTED_THING_TYPES.stream(),
LightLevelHandler.SUPPORTED_THING_TYPES.stream(), ClipHandler.SUPPORTED_THING_TYPES.stream())
.flatMap(i -> i).collect(Collectors.toSet()));

private final Map<ThingUID, @Nullable ServiceRegistration<?>> discoveryServiceRegs = new HashMap<>();

Expand All @@ -73,10 +72,6 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory {
@Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
if (HueBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
return super.createThing(thingTypeUID, configuration, thingUID, null);
} else if (HueGatewayHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
ThingUID uid = thingUID != null ? thingUID
: getThingUID(thingTypeUID, configuration.get(BRIDGE_ID).toString(), bridgeUID);
return super.createThing(thingTypeUID, configuration, uid, bridgeUID);
} else if (HueLightHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
ThingUID hueLightUID = getLightUID(thingTypeUID, thingUID, configuration, bridgeUID);
return super.createThing(thingTypeUID, configuration, hueLightUID, bridgeUID);
Expand Down Expand Up @@ -130,8 +125,6 @@ private ThingUID getThingUID(ThingTypeUID thingTypeUID, String id, @Nullable Thi
HueBridgeHandler handler = new HueBridgeHandler((Bridge) thing);
registerLightDiscoveryService(handler);
return handler;
} else if (HueGatewayHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new HueGatewayHandler(thing);
} else if (HueLightHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
return new HueLightHandler(thing);
} else if (DimmerSwitchHandler.SUPPORTED_THING_TYPES.contains(thing.getThingTypeUID())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
import org.openhab.binding.hue.internal.handler.HueLightHandler;
import org.openhab.binding.hue.internal.handler.LightStatusListener;
import org.openhab.binding.hue.internal.handler.SensorStatusListener;
import org.openhab.binding.hue.internal.handler.sensors.ClipHandler;
import org.openhab.binding.hue.internal.handler.sensors.DimmerSwitchHandler;
import org.openhab.binding.hue.internal.handler.sensors.LightLevelHandler;
import org.openhab.binding.hue.internal.handler.sensors.PresenceHandler;
import org.openhab.binding.hue.internal.handler.sensors.TapSwitchHandler;
import org.openhab.binding.hue.internal.handler.sensors.TemperatureHandler;
import org.openhab.binding.hue.internal.handler.sensors.ClipHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -132,24 +132,6 @@ public void startScan() {
}
// search for unpaired lights
hueBridgeHandler.startSearch();

addBridgeAsGateway();
}

private void addBridgeAsGateway() {
ThingUID bridgeUID = hueBridgeHandler.getThing().getUID();
String bridgeId = hueBridgeHandler.getBridgeId();
ThingUID gatewayUID = new ThingUID(THING_TYPE_GATEWAY, bridgeUID, bridgeId);
Map<String, Object> properties = new HashMap<>();
properties.put(BRIDGE_ID, bridgeId);

DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(gatewayUID)//
.withThingType(THING_TYPE_GATEWAY)//
.withProperties(properties)//
.withBridge(bridgeUID)//
.withRepresentationProperty(BRIDGE_ID)//
.withLabel(hueBridgeHandler.getThing().getLabel()).build();
thingDiscovered(discoveryResult);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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.library.types.StringType;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.ThingStatus;
Expand Down Expand Up @@ -251,7 +252,9 @@ public HueBridgeHandler(Bridge bridge) {

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
// no commands
if (CHANNEL_SCENE.equals(channelUID.getId()) && command instanceof StringType) {
activateScene(command.toString());
}
}

@Override
Expand Down Expand Up @@ -632,7 +635,11 @@ public boolean unregisterSensorStatusListener(SensorStatusListener sensorStatusL
return result;
}

@Override
/**
* Activate scene to all lights that belong to the scene.
*
* @param id the ID of the scene to activate
*/
public void activateScene(String id) {
if (hueBridge != null) {
hueBridge.activateScene(id).thenAccept(result -> {
Expand Down Expand Up @@ -809,8 +816,4 @@ public Collection<ConfigStatusMessage> getConfigStatus() {

return configStatusMessages;
}

public String getBridgeId() {
return withReAuthentication("get bridge ID", () -> hueBridge.getConfig().getBridgeId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,4 @@ public interface HueClient {
* @param stateUpdate the state update
*/
void updateSensorState(FullSensor sensor, StateUpdate stateUpdate);

/**
* Activate scene to all lights that belong to the scene.
*
* @param id the ID of the scene to activate
*/
void activateScene(String id);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<label>Hue Bridge</label>
<description>The Hue bridge represents the Philips Hue bridge.</description>

<channels>
<channel id="scene" typeId="scene" />
</channels>

<properties>
<property name="vendor">Philips</property>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@

<!-- Scene Channel -->
<channel-type id="scene">
<item-type>String</item-type>
<label>Scene</label>
<description>The scene channel allows activating a scene to all lights that belong to the scene.</description>
<item-type>String</item-type>
<label>Scene</label>
<description>The scene channel allows activating a scene to all lights that belong to the scene.</description>
</channel-type>
</thing:thing-descriptions>

This file was deleted.

0 comments on commit 7e2a3bd

Please sign in to comment.