use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class IAqualinkHandler method updateChannels.
/**
* Creates channels based on what is supported by the controller.
*/
private void updateChannels(Auxiliary[] auxes, OneTouch[] oneTouches) {
List<Channel> channels = new ArrayList<>(getThing().getChannels());
for (Auxiliary aux : auxes) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), aux.getName());
logger.debug("Add channel Aux Name: {} Label: {} Type: {} Subtype: {}", aux.getName(), aux.getLabel(), aux.getType(), aux.getSubtype());
switch(aux.getType()) {
case "1":
addNewChannelToList(channels, channelUID, "Dimmer", IAqualinkBindingConstants.CHANNEL_TYPE_UID_AUX_DIMMER, aux.getLabel());
break;
case "2":
{
addNewChannelToList(channels, channelUID, "String", AuxiliaryType.fromSubType(aux.getSubtype()).getChannelTypeUID(), aux.getLabel());
}
break;
default:
addNewChannelToList(channels, channelUID, "Switch", IAqualinkBindingConstants.CHANNEL_TYPE_UID_AUX_SWITCH, aux.getLabel());
}
}
for (OneTouch oneTouch : oneTouches) {
if ("0".equals(oneTouch.getStatus())) {
// OneTouch is not enabled
continue;
}
ChannelUID channelUID = new ChannelUID(getThing().getUID(), oneTouch.getName());
addNewChannelToList(channels, channelUID, "Switch", IAqualinkBindingConstants.CHANNEL_TYPE_UID_ONETOUCH, oneTouch.getLabel());
}
ThingBuilder thingBuilder = editThing();
thingBuilder.withChannels(channels);
updateThing(thingBuilder.build());
}
use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class LaCrosseTemperatureSensorHandler method createPublisher.
@Override
public ReadingPublisher<LaCrosseTemperatureReading> createPublisher() {
return new ReadingPublisher<LaCrosseTemperatureReading>() {
private final Map<Integer, ReadingPublisher<LaCrosseTemperatureReading>> channelPublishers = new HashMap<>();
@Override
public void publish(LaCrosseTemperatureReading reading) {
if (reading != null) {
int channelNo = reading.getChannel();
ReadingPublisher<LaCrosseTemperatureReading> publisher;
synchronized (channelPublishers) {
publisher = channelPublishers.get(channelNo);
if (publisher == null) {
publisher = createPublisherForChannel(channelNo);
channelPublishers.put(channelNo, publisher);
createMissingChannels(reading.getChannel());
}
}
publisher.publish(reading);
}
}
private void createMissingChannels(int channelNo) {
List<Channel> missingChannels = new ArrayList<>();
String idSuffix = channelNo > 1 ? String.valueOf(channelNo) : "";
String labelSuffix = channelNo > 1 ? " " + channelNo : "";
for (String channelName : new String[] { TEMPERATURE_CHANNEL, HUMIDITY_CHANNEL }) {
if (getThing().getChannel(channelName + idSuffix) == null) {
missingChannels.add(ChannelBuilder.create(new ChannelUID(getThing().getUID(), channelName + idSuffix), "Number").withType(new ChannelTypeUID(getThing().getThingTypeUID().getBindingId(), channelName)).withLabel(StringUtils.capitalize(channelName + labelSuffix)).build());
}
}
missingChannels.addAll(getThing().getChannels());
if (!missingChannels.isEmpty()) {
ThingBuilder thingBuilder = editThing();
thingBuilder.withChannels(missingChannels);
updateThing(thingBuilder.build());
}
}
@Override
public void dispose() {
synchronized (channelPublishers) {
for (ReadingPublisher<LaCrosseTemperatureReading> p : channelPublishers.values()) {
p.dispose();
}
channelPublishers.clear();
}
}
};
}
use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class JablotronJa100Handler method createPGMChannel.
private void createPGMChannel(String name, String label) {
ChannelTypeUID pgmStatus = new ChannelTypeUID(BINDING_ID, "pgm_state");
ThingBuilder thingBuilder = editThing();
Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), name), "Switch").withLabel(label).withType(pgmStatus).build();
thingBuilder.withChannel(channel);
updateThing(thingBuilder.build());
}
use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class JablotronJa100Handler method createTempChannel.
private void createTempChannel(String name, String label) {
ChannelTypeUID temperature = new ChannelTypeUID(BINDING_ID, "temperature");
ThingBuilder thingBuilder = editThing();
Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), name), "Number:Temperature").withLabel(label).withType(temperature).build();
thingBuilder.withChannel(channel);
updateThing(thingBuilder.build());
}
use of org.openhab.core.thing.binding.builder.ThingBuilder in project openhab-addons by openhab.
the class JablotronJa100Handler method createThermostatChannel.
private void createThermostatChannel(String name, String label) {
ChannelTypeUID temperature = new ChannelTypeUID(BINDING_ID, "thermostat");
ThingBuilder thingBuilder = editThing();
Channel channel = ChannelBuilder.create(new ChannelUID(thing.getUID(), name), "Number:Temperature").withLabel(label).withType(temperature).build();
thingBuilder.withChannel(channel);
updateThing(thingBuilder.build());
}
Aggregations