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