Search in sources :

Example 61 with ThingBuilder

use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.

the class Tr064SubHandler method internalInitialize.

private void internalInitialize() {
    final Bridge bridge = getBridge();
    if (bridge == null) {
        return;
    }
    final Tr064RootHandler bridgeHandler = (Tr064RootHandler) bridge.getHandler();
    if (bridgeHandler == null) {
        logger.warn("Bridge-handler is null in thing {}", thing.getUID());
        return;
    }
    final SCPDUtil scpdUtil = bridgeHandler.getSCPDUtil();
    if (scpdUtil == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Could not get device definitions");
        return;
    }
    if (checkProperties(scpdUtil)) {
        // properties set, check channels
        ThingBuilder thingBuilder = editThing();
        thingBuilder.withoutChannels(thing.getChannels());
        Util.checkAvailableChannels(thing, thingBuilder, scpdUtil, config.uuid, deviceType, channels);
        updateThing(thingBuilder.build());
        // remove connect scheduler
        removeConnectScheduler();
        soapConnector = bridgeHandler.getSOAPConnector();
        isInitialized = true;
        installPolling();
        updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
    }
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) SCPDUtil(org.openhab.binding.tr064.internal.util.SCPDUtil) Bridge(org.openhab.core.thing.Bridge)

Example 62 with ThingBuilder

use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.

the class WLedHandler method removeChannels.

public void removeChannels(ArrayList<Channel> removeChannels) {
    if (!removeChannels.isEmpty()) {
        ThingBuilder thingBuilder = editThing();
        thingBuilder.withoutChannels(removeChannels);
        updateThing(thingBuilder.build());
    }
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder)

Example 63 with ThingBuilder

use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.

the class PLCCommonHandler method dispose.

@Override
public void dispose() {
    logger.debug("Dispose LOGO! common block handler.");
    super.dispose();
    ThingBuilder tBuilder = editThing();
    for (Channel channel : getThing().getChannels()) {
        tBuilder.withoutChannel(channel.getUID());
    }
    updateThing(tBuilder.build());
    synchronized (oldValues) {
        oldValues.clear();
    }
    family = NOT_SUPPORTED;
    client = null;
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) Channel(org.openhab.core.thing.Channel)

Example 64 with ThingBuilder

use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.

the class PLCMemoryHandler method doInitialization.

@Override
protected void doInitialization() {
    Thing thing = getThing();
    logger.debug("Initialize LOGO! memory handler.");
    config.set(getConfigAs(PLCMemoryConfiguration.class));
    super.doInitialization();
    if (ThingStatus.OFFLINE != thing.getStatus()) {
        String kind = getBlockKind();
        String name = config.get().getBlockName();
        boolean isDigital = MEMORY_BYTE.equalsIgnoreCase(kind) && (getBit(name) != INVALID);
        String text = isDigital ? "Digital" : "Analog";
        ThingBuilder tBuilder = editThing();
        String label = thing.getLabel();
        if (label == null) {
            Bridge bridge = getBridge();
            label = (bridge == null) || (bridge.getLabel() == null) ? "Siemens Logo!" : bridge.getLabel();
            label += (": " + text.toLowerCase() + " in/output");
        }
        tBuilder.withLabel(label);
        String type = config.get().getChannelType();
        ChannelUID uid = new ChannelUID(thing.getUID(), isDigital ? STATE_CHANNEL : VALUE_CHANNEL);
        ChannelBuilder cBuilder = ChannelBuilder.create(uid, type);
        cBuilder.withType(new ChannelTypeUID(BINDING_ID, type.toLowerCase()));
        cBuilder.withLabel(name);
        cBuilder.withDescription(text + " in/output block " + name);
        cBuilder.withProperties(Collections.singletonMap(BLOCK_PROPERTY, name));
        tBuilder.withChannel(cBuilder.build());
        setOldValue(name, null);
        updateThing(tBuilder.build());
        updateStatus(ThingStatus.ONLINE);
    }
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) PLCMemoryConfiguration(org.openhab.binding.plclogo.internal.config.PLCMemoryConfiguration) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelUID(org.openhab.core.thing.ChannelUID) ChannelBuilder(org.openhab.core.thing.binding.builder.ChannelBuilder) Thing(org.openhab.core.thing.Thing) Bridge(org.openhab.core.thing.Bridge)

Example 65 with ThingBuilder

use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.

the class PLCAnalogHandler method doInitialization.

@Override
protected void doInitialization() {
    Thing thing = getThing();
    logger.debug("Initialize LOGO! analog input blocks handler.");
    config.set(getConfigAs(PLCAnalogConfiguration.class));
    super.doInitialization();
    if (ThingStatus.OFFLINE != thing.getStatus()) {
        String kind = getBlockKind();
        String text = I_ANALOG.equalsIgnoreCase(kind) || NI_ANALOG.equalsIgnoreCase(kind) ? "input" : "output";
        ThingBuilder tBuilder = editThing();
        String label = thing.getLabel();
        if (label == null) {
            Bridge bridge = getBridge();
            label = (bridge == null) || (bridge.getLabel() == null) ? "Siemens Logo!" : bridge.getLabel();
            label += (": analog " + text + "s");
        }
        tBuilder.withLabel(label);
        String type = config.get().getChannelType();
        for (int i = 0; i < getNumberOfChannels(); i++) {
            String name = kind + String.valueOf(i + 1);
            ChannelUID uid = new ChannelUID(thing.getUID(), name);
            ChannelBuilder cBuilder = ChannelBuilder.create(uid, type);
            cBuilder.withType(new ChannelTypeUID(BINDING_ID, type.toLowerCase()));
            cBuilder.withLabel(name);
            cBuilder.withDescription("Analog " + text + " block " + name);
            cBuilder.withProperties(Collections.singletonMap(BLOCK_PROPERTY, name));
            tBuilder.withChannel(cBuilder.build());
            setOldValue(name, null);
        }
        updateThing(tBuilder.build());
        updateStatus(ThingStatus.ONLINE);
    }
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelUID(org.openhab.core.thing.ChannelUID) PLCAnalogConfiguration(org.openhab.binding.plclogo.internal.config.PLCAnalogConfiguration) ChannelBuilder(org.openhab.core.thing.binding.builder.ChannelBuilder) Thing(org.openhab.core.thing.Thing) Bridge(org.openhab.core.thing.Bridge)

Aggregations

ThingBuilder (org.openhab.core.thing.binding.builder.ThingBuilder)107 Channel (org.openhab.core.thing.Channel)71 ChannelUID (org.openhab.core.thing.ChannelUID)60 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)38 ArrayList (java.util.ArrayList)37 Thing (org.openhab.core.thing.Thing)29 HashMap (java.util.HashMap)23 ChannelBuilder (org.openhab.core.thing.binding.builder.ChannelBuilder)20 Map (java.util.Map)19 ThingStatus (org.openhab.core.thing.ThingStatus)18 ThingStatusDetail (org.openhab.core.thing.ThingStatusDetail)18 Logger (org.slf4j.Logger)18 LoggerFactory (org.slf4j.LoggerFactory)18 Bridge (org.openhab.core.thing.Bridge)17 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)16 List (java.util.List)15 Nullable (org.eclipse.jdt.annotation.Nullable)15 Configuration (org.openhab.core.config.core.Configuration)15 Collectors (java.util.stream.Collectors)14 Command (org.openhab.core.types.Command)12