use of org.eclipse.smarthome.core.thing.Channel 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");
}
}
use of org.eclipse.smarthome.core.thing.Channel 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;
}
use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.
the class LifxLightHandler method getPowerOnBrightness.
private PercentType getPowerOnBrightness() {
Channel channel = null;
if (product.isColor()) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_COLOR);
channel = getThing().getChannel(channelUID.getId());
} else {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_BRIGHTNESS);
channel = getThing().getChannel(channelUID.getId());
}
if (channel == null) {
return null;
}
Configuration configuration = channel.getConfiguration();
Object powerOnBrightness = configuration.get(LifxBindingConstants.CONFIG_PROPERTY_POWER_ON_BRIGHTNESS);
return powerOnBrightness == null ? null : new PercentType(powerOnBrightness.toString());
}
use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.
the class LifxLightHandler method getPowerOnColor.
private HSBType getPowerOnColor() {
Channel channel = null;
if (product.isColor()) {
ChannelUID channelUID = new ChannelUID(getThing().getUID(), LifxBindingConstants.CHANNEL_COLOR);
channel = getThing().getChannel(channelUID.getId());
}
if (channel == null) {
return null;
}
Configuration configuration = channel.getConfiguration();
Object powerOnColor = configuration.get(LifxBindingConstants.CONFIG_PROPERTY_POWER_ON_COLOR);
return powerOnColor == null ? null : new HSBType(powerOnColor.toString());
}
use of org.eclipse.smarthome.core.thing.Channel in project smarthome by eclipse.
the class ThingHelper method toString.
private static String toString(List<Channel> channels) {
List<String> strings = new ArrayList<>(channels.size());
for (Channel channel : channels) {
strings.add(channel.getUID().toString() + '#' + channel.getAcceptedItemType() + '#' + channel.getKind());
}
Collections.sort(strings);
return strings.stream().collect(Collectors.joining(","));
}
Aggregations