Search in sources :

Example 41 with ThingBuilder

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

the class UpnpHandler method updateChannels.

protected void updateChannels() {
    if (updateChannels) {
        List<Channel> channels = thing.getChannels().stream().filter(c -> !updatedChannelUIDs.contains(c.getUID())).collect(Collectors.toList());
        channels.addAll(updatedChannels);
        final ThingBuilder thingBuilder = editThing();
        thingBuilder.withChannels(channels);
        updateThing(thingBuilder.build());
    }
    updatedChannels.clear();
    updatedChannelUIDs.clear();
    updateChannels = false;
}
Also used : UpnpControlConfiguration(org.openhab.binding.upnpcontrol.internal.config.UpnpControlConfiguration) ScheduledFuture(java.util.concurrent.ScheduledFuture) UpnpControlUtil(org.openhab.binding.upnpcontrol.internal.util.UpnpControlUtil) UpnpIOService(org.openhab.core.io.transport.upnp.UpnpIOService) UpnpDynamicStateDescriptionProvider(org.openhab.binding.upnpcontrol.internal.UpnpDynamicStateDescriptionProvider) UpnpControlBindingConfiguration(org.openhab.binding.upnpcontrol.internal.config.UpnpControlBindingConfiguration) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) RegistryListener(org.jupnp.registry.RegistryListener) StateDescription(org.openhab.core.types.StateDescription) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) UpnpDynamicCommandDescriptionProvider(org.openhab.binding.upnpcontrol.internal.UpnpDynamicCommandDescriptionProvider) ArrayList(java.util.ArrayList) Thing(org.openhab.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) ChannelUID(org.openhab.core.thing.ChannelUID) CommandDescription(org.openhab.core.types.CommandDescription) CommandDescriptionBuilder(org.openhab.core.types.CommandDescriptionBuilder) ThreadPoolManager(org.openhab.core.common.ThreadPoolManager) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ThingStatus(org.openhab.core.thing.ThingStatus) Logger(org.slf4j.Logger) ChannelBuilder(org.openhab.core.thing.binding.builder.ChannelBuilder) UpnpPlaylistsListener(org.openhab.binding.upnpcontrol.internal.queue.UpnpPlaylistsListener) StateDescriptionFragmentBuilder(org.openhab.core.types.StateDescriptionFragmentBuilder) UpnpChannelName(org.openhab.binding.upnpcontrol.internal.UpnpChannelName) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) CommandOption(org.openhab.core.types.CommandOption) StateOption(org.openhab.core.types.StateOption) Collectors(java.util.stream.Collectors) RemoteDevice(org.jupnp.model.meta.RemoteDevice) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Channel(org.openhab.core.thing.Channel) List(java.util.List) UpnpIOParticipant(org.openhab.core.io.transport.upnp.UpnpIOParticipant) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) Channel(org.openhab.core.thing.Channel)

Example 42 with ThingBuilder

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

the class ZWayDeviceHandler method addChannel.

private synchronized void addChannel(String id, String acceptedItemType, String label, HashMap<String, String> properties) {
    boolean channelExists = false;
    // Check if a channel for this virtual device exist. Attention: same channel type could multiple assigned to a
    // thing. That's why not check the existence of channel type.
    List<Channel> channels = getThing().getChannels();
    for (Channel channel : channels) {
        if (channel.getProperties().get("deviceId") != null && channel.getProperties().get("deviceId").equals(properties.get("deviceId"))) {
            channelExists = true;
        }
    }
    if (!channelExists) {
        ThingBuilder thingBuilder = editThing();
        ChannelTypeUID channelTypeUID = new ChannelTypeUID(BINDING_ID, id);
        Channel channel = ChannelBuilder.create(new ChannelUID(getThing().getUID(), id + "-" + properties.get("deviceId")), acceptedItemType).withType(channelTypeUID).withLabel(label).withProperties(properties).build();
        thingBuilder.withChannel(channel);
        thingBuilder.withLabel(thing.getLabel());
        updateThing(thingBuilder.build());
    }
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel)

Example 43 with ThingBuilder

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

the class ZWayDeviceHandler method setLocation.

private synchronized void setLocation() {
    Map<String, String> properties = getThing().getProperties();
    // Load location from properties
    String location = properties.get(ZWayBindingConstants.DEVICE_PROP_LOCATION);
    if (location != null && !location.equals("") && getThing().getLocation() == null) {
        logger.debug("Set location to {}", location);
        ThingBuilder thingBuilder = editThing();
        thingBuilder.withLocation(location);
        thingBuilder.withLabel(thing.getLabel());
        updateThing(thingBuilder.build());
    }
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder)

Example 44 with ThingBuilder

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

the class OrbitBhyveSprinklerHandler method createChannel.

private void createChannel(String name, String type, String label, ChannelTypeUID typeUID) {
    ThingBuilder thingBuilder = editThing();
    Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), name), type).withLabel(label).withType(typeUID).build();
    thingBuilder.withChannel(channel);
    updateThing(thingBuilder.build());
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel)

Example 45 with ThingBuilder

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

the class WirelessChannelsHandler method initialize.

@Override
public void initialize() {
    super.initialize();
    withBridgeHandlerPresent(bridgeHandler -> {
        // add/remove channels depending on whether or not the device is wireless
        final int wirelessDeviceId = getThingConfig().getId() - bridgeHandler.getIntegraType().getOnMainboard();
        ThingBuilder thingBuilder = editThing();
        if (isWirelessDevice() && wirelessDeviceId > 0) {
            // if a wireless device, remove channels for wireless devices
            if (getChannel(TroubleState.DEVICE_LOBATT) == null) {
                thingBuilder.withChannel(ChannelBuilder.create(getChannelUID(TroubleState.DEVICE_LOBATT), "Switch").withType(CHANNEL_TYPE_LOBATT).build());
            }
            if (getChannel(TroubleState.DEVICE_NOCOMM) == null) {
                thingBuilder.withChannel(ChannelBuilder.create(getChannelUID(TroubleState.DEVICE_NOCOMM), "Switch").withType(CHANNEL_TYPE_NOCOMM).build());
            }
        } else {
            // if not a wireless device, remove channels for wireless devices
            thingBuilder.withoutChannel(getChannelUID(TroubleState.DEVICE_LOBATT)).withoutChannel(getChannelUID(TroubleState.DEVICE_NOCOMM));
        }
        updateThing(thingBuilder.build());
    });
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder)

Aggregations

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