Search in sources :

Example 16 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class ZoneTemperatureControlHandler method loadChannel.

private synchronized void loadChannel() {
    List<Channel> newChannelList = new ArrayList<Channel>(1);
    if (currentChannelID != null) {
        newChannelList.add(ChannelBuilder.create(new ChannelUID(this.getThing().getUID(), currentChannelID), DsChannelTypeProvider.getItemType(currentChannelID)).withType(new ChannelTypeUID(BINDING_ID, currentChannelID)).build());
    }
    ThingBuilder thingBuilder = editThing();
    thingBuilder.withChannels(newChannelList);
    updateThing(thingBuilder.build());
    logger.debug("load channel: {} with item: {}", currentChannelID, DsChannelTypeProvider.getItemType(currentChannelID));
}
Also used : ThingBuilder(org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder) ChannelTypeUID(org.eclipse.smarthome.core.thing.type.ChannelTypeUID) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) ArrayList(java.util.ArrayList)

Example 17 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class GenericItemChannelLinkProvider method createItemChannelLink.

private void createItemChannelLink(String context, String itemName, String channelUID, Configuration configuration) throws BindingConfigParseException {
    ChannelUID channelUIDObject = null;
    try {
        channelUIDObject = new ChannelUID(channelUID);
    } catch (IllegalArgumentException e) {
        throw new BindingConfigParseException(e.getMessage());
    }
    ItemChannelLink itemChannelLink = new ItemChannelLink(itemName, channelUIDObject, configuration);
    Set<String> itemNames = contextMap.get(context);
    if (itemNames == null) {
        itemNames = new HashSet<>();
        contextMap.put(context, itemNames);
    }
    itemNames.add(itemName);
    if (previousItemNames != null) {
        previousItemNames.remove(itemName);
    }
    Set<ItemChannelLink> links = itemChannelLinkMap.get(itemName);
    if (links == null) {
        itemChannelLinkMap.put(itemName, links = new HashSet<>());
    }
    if (!links.contains(itemChannelLink)) {
        links.add(itemChannelLink);
        notifyListenersAboutAddedElement(itemChannelLink);
    } else {
        notifyListenersAboutUpdatedElement(itemChannelLink, itemChannelLink);
    }
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) BindingConfigParseException(org.eclipse.smarthome.model.item.BindingConfigParseException) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) HashSet(java.util.HashSet)

Example 18 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class NtpOSGiTest method assertEventIsReceived.

private void assertEventIsReceived(UpdateEventType updateEventType, String channelID, String acceptedItemType) {
    Configuration configuration = new Configuration();
    initialize(configuration, channelID, acceptedItemType, null, null);
    EventSubscriber eventSubscriberMock = mock(EventSubscriber.class);
    when(eventSubscriberMock.getSubscribedEventTypes()).thenReturn(Collections.singleton(ItemStateEvent.TYPE));
    registerService(eventSubscriberMock);
    if (updateEventType.equals(UpdateEventType.HANDLE_COMMAND)) {
        ntpHandler.handleCommand(new ChannelUID("ntp:test:chan:1"), new StringType("test"));
    } else if (updateEventType.equals(UpdateEventType.CHANNEL_LINKED)) {
        ntpHandler.channelLinked(new ChannelUID("ntp:test:chan:1"));
    }
    waitForAssert(() -> {
        verify(eventSubscriberMock, atLeastOnce()).receive(ArgumentMatchers.any(Event.class));
    });
}
Also used : EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) Configuration(org.eclipse.smarthome.config.core.Configuration) StringType(org.eclipse.smarthome.core.library.types.StringType) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) ItemStateEvent(org.eclipse.smarthome.core.items.events.ItemStateEvent) Event(org.eclipse.smarthome.core.events.Event)

Example 19 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class NtpHandler method initialize.

@Override
public void initialize() {
    try {
        logger.debug("Initializing NTP handler for '{}'.", getThing().getUID());
        Configuration config = getThing().getConfiguration();
        hostname = config.get(PROPERTY_NTP_SERVER_HOST).toString();
        port = (BigDecimal) config.get(PROPERTY_NTP_SERVER_PORT);
        refreshInterval = (BigDecimal) config.get(PROPERTY_REFRESH_INTERVAL);
        refreshNtp = (BigDecimal) config.get(PROPERTY_REFRESH_NTP);
        refreshNtpCount = 0;
        try {
            Object timeZoneConfigValue = config.get(PROPERTY_TIMEZONE);
            if (timeZoneConfigValue != null) {
                timeZone = TimeZone.getTimeZone(timeZoneConfigValue.toString());
            } else {
                timeZone = TimeZone.getDefault();
                logger.debug("{} using default TZ '{}', because configuration property '{}' is null.", getThing().getUID(), timeZone, PROPERTY_TIMEZONE);
            }
        } catch (Exception e) {
            timeZone = TimeZone.getDefault();
            logger.debug("{} using default TZ '{}' due to an occurred exception: ", getThing().getUID(), timeZone, e);
        }
        try {
            Object localeStringConfigValue = config.get(PROPERTY_LOCALE);
            if (localeStringConfigValue != null) {
                locale = new Locale(localeStringConfigValue.toString());
            } else {
                locale = localeProvider.getLocale();
                logger.debug("{} using default locale '{}', because configuration property '{}' is null.", getThing().getUID(), locale, PROPERTY_LOCALE);
            }
        } catch (Exception e) {
            locale = localeProvider.getLocale();
            logger.debug("{} using default locale '{}' due to an occurred exception: ", getThing().getUID(), locale, e);
        }
        dateTimeChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_DATE_TIME);
        stringChannelUID = new ChannelUID(getThing().getUID(), CHANNEL_STRING);
        try {
            Channel stringChannel = getThing().getChannel(stringChannelUID.getId());
            if (stringChannel != null) {
                Configuration cfg = stringChannel.getConfiguration();
                String dateTimeFormatString = cfg.get(PROPERTY_DATE_TIME_FORMAT).toString();
                if (!(dateTimeFormatString == null || dateTimeFormatString.isEmpty())) {
                    dateTimeFormat = DateTimeFormatter.ofPattern(dateTimeFormatString);
                } else {
                    logger.debug("No format set in channel config for {}. Using default format.", stringChannelUID);
                    dateTimeFormat = DateTimeFormatter.ofPattern(DATE_PATTERN_WITH_TZ);
                }
            } else {
                logger.debug("Missing channel: '{}'", stringChannelUID.getId());
            }
        } catch (RuntimeException ex) {
            logger.debug("No channel config or invalid format for {}. Using default format. ({})", stringChannelUID, ex.getMessage());
            dateTimeFormat = DateTimeFormatter.ofPattern(DATE_PATTERN_WITH_TZ);
        }
        SDF.setTimeZone(timeZone);
        dateTimeFormat.withZone(timeZone.toZoneId());
        logger.debug("Initialized NTP handler '{}' with configuration: host '{}', refresh interval {}, timezone {}, locale {}.", getThing().getUID(), hostname, refreshInterval, timeZone, locale);
        startAutomaticRefresh();
    } catch (Exception ex) {
        logger.error("Error occurred while initializing NTP handler: {}", ex.getMessage(), ex);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/offline.conf-error-init-handler");
    }
}
Also used : Locale(java.util.Locale) Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 20 with ChannelUID

use of org.eclipse.smarthome.core.thing.ChannelUID in project smarthome by eclipse.

the class LifxLightHandler method getPowerOnTemperature.

private PercentType getPowerOnTemperature() {
    ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_TEMPERATURE);
    Channel channel = getThing().getChannel(channelUID.getId());
    if (channel == null) {
        return null;
    }
    Configuration configuration = channel.getConfiguration();
    Object powerOnTemperature = configuration.get(LifxBindingConstants.CONFIG_PROPERTY_POWER_ON_TEMPERATURE);
    if (powerOnTemperature != null) {
        return new PercentType(powerOnTemperature.toString());
    }
    return null;
}
Also used : Configuration(org.eclipse.smarthome.config.core.Configuration) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LifxMessageUtil.increaseDecreasePercentType(org.eclipse.smarthome.binding.lifx.internal.util.LifxMessageUtil.increaseDecreasePercentType)

Aggregations

ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)69 Test (org.junit.Test)31 Thing (org.eclipse.smarthome.core.thing.Thing)24 Channel (org.eclipse.smarthome.core.thing.Channel)16 JavaTest (org.eclipse.smarthome.test.java.JavaTest)14 Configuration (org.eclipse.smarthome.config.core.Configuration)10 Bridge (org.eclipse.smarthome.core.thing.Bridge)9 ThingBuilder (org.eclipse.smarthome.core.thing.binding.builder.ThingBuilder)9 Item (org.eclipse.smarthome.core.items.Item)7 Command (org.eclipse.smarthome.core.types.Command)7 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)7 DmxBridgeHandler (org.eclipse.smarthome.binding.dmx.internal.DmxBridgeHandler)6 StringItem (org.eclipse.smarthome.core.library.items.StringItem)6 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)6 BaseThingHandler (org.eclipse.smarthome.core.thing.binding.BaseThingHandler)6 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)6 ItemChannelLink (org.eclipse.smarthome.core.thing.link.ItemChannelLink)6 NonNull (org.eclipse.jdt.annotation.NonNull)5 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)5 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)5