Search in sources :

Example 6 with ThingBuilder

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());
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) Auxiliary(org.openhab.binding.iaqualink.internal.api.dto.Auxiliary) ChannelUID(org.openhab.core.thing.ChannelUID) Channel(org.openhab.core.thing.Channel) ArrayList(java.util.ArrayList) OneTouch(org.openhab.binding.iaqualink.internal.api.dto.OneTouch)

Example 7 with ThingBuilder

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();
            }
        }
    };
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) Channel(org.openhab.core.thing.Channel) ArrayList(java.util.ArrayList) ChannelTypeUID(org.openhab.core.thing.type.ChannelTypeUID) ChannelUID(org.openhab.core.thing.ChannelUID) ReadingPublisher(org.openhab.binding.jeelink.internal.ReadingPublisher) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with ThingBuilder

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());
}
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 9 with ThingBuilder

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());
}
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 10 with ThingBuilder

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

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