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;
}
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());
}
}
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());
}
}
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());
}
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());
});
}
Aggregations