Search in sources :

Example 6 with Bridge

use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.

the class CircuitHandler method getDssBridgeHandler.

private synchronized BridgeHandler getDssBridgeHandler() {
    if (this.dssBridgeHandler == null) {
        Bridge bridge = getBridge();
        if (bridge == null) {
            logger.debug("Bride cannot be found");
            return null;
        }
        ThingHandler handler = bridge.getHandler();
        if (handler instanceof BridgeHandler) {
            dssBridgeHandler = (BridgeHandler) handler;
        } else {
            return null;
        }
    }
    return dssBridgeHandler;
}
Also used : BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 7 with Bridge

use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.

the class DeviceHandler method getDssBridgeHandler.

private synchronized BridgeHandler getDssBridgeHandler() {
    if (this.dssBridgeHandler == null) {
        Bridge bridge = getBridge();
        if (bridge == null) {
            logger.debug("Bride cannot be found");
            return null;
        }
        ThingHandler handler = bridge.getHandler();
        if (handler instanceof BridgeHandler) {
            dssBridgeHandler = (BridgeHandler) handler;
        } else {
            return null;
        }
    }
    return dssBridgeHandler;
}
Also used : BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 8 with Bridge

use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.

the class SceneHandler method getBridgeHandler.

private synchronized BridgeHandler getBridgeHandler() {
    if (this.bridgeHandler == null) {
        Bridge bridge = getBridge();
        if (bridge == null) {
            logger.debug("Bridge cannot be found");
            return null;
        }
        ThingHandler handler = bridge.getHandler();
        if (handler instanceof BridgeHandler) {
            this.bridgeHandler = (BridgeHandler) handler;
        } else {
            logger.debug("BridgeHandler cannot be found");
            return null;
        }
    }
    return this.bridgeHandler;
}
Also used : BaseThingHandler(org.eclipse.smarthome.core.thing.binding.BaseThingHandler) ThingHandler(org.eclipse.smarthome.core.thing.binding.ThingHandler) Bridge(org.eclipse.smarthome.core.thing.Bridge)

Example 9 with Bridge

use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.

the class ThingHelper method merge.

/**
 * Merges the content of a ThingDTO with an existing Thing.
 * Where ever the DTO has null values, the content of the original Thing is kept.
 * Where ever the DTO has non-null values, these are used.
 * In consequence, care must be taken when the content of a list (like configuration, properties or channels) is to
 * be updated - the DTO must contain the full list, otherwise entries will be deleted.
 *
 * @param thing the Thing instance to merge the new content into
 * @param updatedContents a DTO which carries the updated content
 * @return A Thing instance, which is the result of the merge
 */
public static Thing merge(Thing thing, ThingDTO updatedContents) {
    ThingBuilder builder;
    if (thing instanceof Bridge) {
        builder = BridgeBuilder.create(thing.getThingTypeUID(), thing.getUID());
    } else {
        builder = ThingBuilder.create(thing.getThingTypeUID(), thing.getUID());
    }
    // Update the label
    if (updatedContents.label != null) {
        builder.withLabel(updatedContents.label);
    } else {
        builder.withLabel(thing.getLabel());
    }
    // Update the location
    if (updatedContents.location != null) {
        builder.withLocation(updatedContents.location);
    } else {
        builder.withLocation(thing.getLocation());
    }
    // update bridge UID
    if (updatedContents.bridgeUID != null) {
        builder.withBridge(new ThingUID(updatedContents.bridgeUID));
    } else {
        builder.withBridge(thing.getBridgeUID());
    }
    // update thing configuration
    if (updatedContents.configuration != null && !updatedContents.configuration.keySet().isEmpty()) {
        builder.withConfiguration(new Configuration(updatedContents.configuration));
    } else {
        builder.withConfiguration(thing.getConfiguration());
    }
    // update thing properties
    if (updatedContents.properties != null) {
        builder.withProperties(updatedContents.properties);
    } else {
        builder.withProperties(thing.getProperties());
    }
    // Update the channels
    if (updatedContents.channels != null) {
        for (ChannelDTO channelDTO : updatedContents.channels) {
            builder.withChannel(ChannelDTOMapper.map(channelDTO));
        }
    } else {
        builder.withChannels(thing.getChannels());
    }
    if (updatedContents.location != null) {
        builder.withLocation(updatedContents.location);
    } else {
        builder.withLocation(thing.getLocation());
    }
    Thing mergedThing = builder.build();
    // keep all child things in place on a merged bridge
    if (mergedThing instanceof BridgeImpl && thing instanceof Bridge) {
        Bridge bridge = (Bridge) thing;
        BridgeImpl mergedBridge = (BridgeImpl) mergedThing;
        for (Thing child : bridge.getThings()) {
            mergedBridge.addThing(child);
        }
    }
    return mergedThing;
}
Also used : BridgeImpl(org.eclipse.smarthome.core.thing.internal.BridgeImpl) ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) Configuration(org.eclipse.smarthome.config.core.Configuration) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ChannelDTO(org.eclipse.smarthome.core.thing.dto.ChannelDTO) Bridge(org.eclipse.smarthome.core.thing.Bridge) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 10 with Bridge

use of org.eclipse.smarthome.core.thing.Bridge in project smarthome by eclipse.

the class DimmerThingHandlerTest method setUp.

@Before
public void setUp() {
    super.setup();
    thingProperties = new HashMap<>();
    thingProperties.put(CONFIG_DMX_ID, TEST_CHANNEL_CONFIG);
    thingProperties.put(CONFIG_DIMMER_FADE_TIME, TEST_FADE_TIME);
    dimmerThing = ThingBuilder.create(THING_TYPE_DIMMER, "testdimmer").withLabel("Dimmer Thing").withBridge(bridge.getUID()).withConfiguration(new Configuration(thingProperties)).withChannel(ChannelBuilder.create(CHANNEL_UID_BRIGHTNESS, "Brightness").withType(BRIGHTNESS_CHANNEL_TYPEUID).build()).build();
    dimmerThingHandler = new DimmerThingHandler(dimmerThing) {

        @Override
        @Nullable
        protected Bridge getBridge() {
            return bridge;
        }
    };
    initializeHandler(dimmerThingHandler);
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) DimmerThingHandler(org.eclipse.smarthome.binding.dmx.handler.DimmerThingHandler) Nullable(org.eclipse.jdt.annotation.Nullable) Bridge(org.eclipse.smarthome.core.thing.Bridge) Before(org.junit.Before)

Aggregations

Bridge (org.eclipse.smarthome.core.thing.Bridge)26 Configuration (org.eclipse.smarthome.config.core.Configuration)9 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)9 BaseThingHandler (org.eclipse.smarthome.core.thing.binding.BaseThingHandler)9 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)9 DmxBridgeHandler (org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler)7 Nullable (org.eclipse.jdt.annotation.Nullable)6 Thing (org.eclipse.smarthome.core.thing.Thing)6 BaseDmxChannel (org.eclipse.smarthome.binding.dmx.internal.multiverse.BaseDmxChannel)5 Semaphore (java.util.concurrent.Semaphore)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 BaseBridgeHandler (org.eclipse.smarthome.core.thing.binding.BaseBridgeHandler)3 Command (org.eclipse.smarthome.core.types.Command)3 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)3 Before (org.junit.Before)3 Test (org.junit.Test)3 HueBridge (org.eclipse.smarthome.binding.hue.internal.HueBridge)2 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1