use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class WeatherUndergroundHandler method updateCurrentObservationChannel.
private State updateCurrentObservationChannel(String channelId, WeatherUndergroundJsonCurrent current) {
WUQuantity quantity;
String channelTypeId = getChannelTypeId(channelId);
switch(channelTypeId) {
case "location":
return undefOrState(current.getLocation(), new StringType(current.getLocation()));
case "stationId":
return undefOrState(current.getStationId(), new StringType(current.getStationId()));
case "observationTime":
return undefOrState(current.getObservationTime(), new DateTimeType(current.getObservationTime()));
case "conditions":
return undefOrState(current.getConditions(), new StringType(current.getConditions()));
case "temperature":
quantity = getTemperature(current.getTemperatureC(), current.getTemperatureF());
return undefOrQuantity(quantity);
case "relativeHumidity":
return undefOrState(current.getRelativeHumidity(), new QuantityType<>(current.getRelativeHumidity(), SmartHomeUnits.PERCENT));
case "windDirection":
return undefOrState(current.getWindDirection(), new StringType(current.getWindDirection()));
case "windDirectionDegrees":
return undefOrState(current.getWindDirectionDegrees(), new QuantityType<>(current.getWindDirectionDegrees(), SmartHomeUnits.DEGREE_ANGLE));
case "windSpeed":
quantity = getSpeed(current.getWindSpeedKmh(), current.getWindSpeedMph());
return undefOrQuantity(quantity);
case "windGust":
quantity = getSpeed(current.getWindGustKmh(), current.getWindGustMph());
return undefOrQuantity(quantity);
case "pressure":
quantity = getPressure(current.getPressureHPa(), current.getPressureInHg());
return undefOrQuantity(quantity);
case "pressureTrend":
return undefOrState(current.getPressureTrend(), new StringType(current.getPressureTrend()));
case "dewPoint":
quantity = getTemperature(current.getDewPointC(), current.getDewPointF());
return undefOrQuantity(quantity);
case "heatIndex":
quantity = getTemperature(current.getHeatIndexC(), current.getHeatIndexF());
return undefOrQuantity(quantity);
case "windChill":
quantity = getTemperature(current.getWindChillC(), current.getWindChillF());
return undefOrQuantity(quantity);
case "feelingTemperature":
quantity = getTemperature(current.getFeelingTemperatureC(), current.getFeelingTemperatureF());
return undefOrQuantity(quantity);
case "visibility":
quantity = getWUQuantity(KILO(SIUnits.METRE), ImperialUnits.MILE, current.getVisibilityKm(), current.getVisibilityMi());
return undefOrQuantity(quantity);
case "solarRadiation":
return undefOrQuantity(new WUQuantity(current.getSolarRadiation(), SmartHomeUnits.IRRADIANCE));
case "UVIndex":
return undefOrDecimal(current.getUVIndex());
case "precipitationDay":
quantity = getPrecipitation(current.getPrecipitationDayMm(), current.getPrecipitationDayIn());
return undefOrQuantity(quantity);
case "precipitationHour":
quantity = getPrecipitation(current.getPrecipitationHourMm(), current.getPrecipitationHourIn());
return undefOrQuantity(quantity);
case "iconKey":
return undefOrState(current.getIconKey(), new StringType(current.getIconKey()));
case "icon":
State icon = HttpUtil.downloadImage(current.getIcon().toExternalForm());
if (icon == null) {
logger.debug("Failed to download the content of URL {}", current.getIcon().toExternalForm());
return null;
}
return icon;
default:
return null;
}
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class VideoRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Video videoWidget = (Video) w;
String snippet = null;
String widgetId = itemUIRegistry.getWidgetId(w);
String sitemap = w.eResource().getURI().path();
// we handle mjpeg streams as an html image as browser can usually handle this
String snippetName = (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("mjpeg")) ? "image" : "video";
snippet = getSnippet(snippetName);
snippet = preprocessSnippet(snippet, w);
State state = itemUIRegistry.getState(w);
String url;
if (snippetName.equals("image")) {
boolean validUrl = false;
if (videoWidget.getUrl() != null && !videoWidget.getUrl().isEmpty()) {
try {
URI.create(videoWidget.getUrl());
validUrl = true;
} catch (IllegalArgumentException ex) {
}
}
String proxiedUrl = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId;
if (!itemUIRegistry.getVisiblity(w)) {
url = URL_NONE_ICON;
} else if ((sitemap != null) && ((state instanceof StringType) || validUrl)) {
url = proxiedUrl + "&t=" + (new Date()).getTime();
} else {
url = URL_NONE_ICON;
}
snippet = StringUtils.replace(snippet, "%valid_url%", validUrl ? "true" : "false");
snippet = StringUtils.replace(snippet, "%proxied_url%", proxiedUrl);
snippet = StringUtils.replace(snippet, "%update_interval%", "0");
snippet = StringUtils.replace(snippet, "%ignore_refresh%", "true");
snippet = StringUtils.replace(snippet, "%url%", url);
} else {
String mediaType;
if (videoWidget.getEncoding() != null && videoWidget.getEncoding().toLowerCase().contains("hls")) {
// For HTTP Live Stream we don't proxy the URL and we set the appropriate media type
url = (state instanceof StringType) ? state.toString() : videoWidget.getUrl();
mediaType = "type=\"application/vnd.apple.mpegurl\"";
} else {
url = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId;
mediaType = "";
}
snippet = StringUtils.replace(snippet, "%url%", url);
snippet = StringUtils.replace(snippet, "%media_type%", mediaType);
}
sb.append(snippet);
return null;
}
use of org.eclipse.smarthome.core.library.types.StringType in project smarthome by eclipse.
the class ImageRenderer method renderWidget.
@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Image image = (Image) w;
String snippet = (image.getChildren().size() > 0) ? getSnippet("image_link") : getSnippet("image");
if (image.getRefresh() > 0) {
snippet = StringUtils.replace(snippet, "%update_interval%", Integer.toString(image.getRefresh()));
} else {
snippet = StringUtils.replace(snippet, "%update_interval%", "0");
}
String widgetId = itemUIRegistry.getWidgetId(w);
snippet = StringUtils.replace(snippet, "%id%", widgetId);
snippet = preprocessSnippet(snippet, w);
String sitemap = null;
if (w.eResource() != null) {
sitemap = w.eResource().getURI().path();
}
boolean validUrl = false;
if (image.getUrl() != null && !image.getUrl().isEmpty()) {
try {
URI.create(image.getUrl());
validUrl = true;
} catch (IllegalArgumentException ex) {
}
}
String proxiedUrl = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId;
State state = itemUIRegistry.getState(w);
String url;
boolean ignoreRefresh;
if (!itemUIRegistry.getVisiblity(w)) {
url = URL_NONE_ICON;
ignoreRefresh = true;
} else if (state instanceof RawType) {
url = state.toFullString();
ignoreRefresh = true;
} else if ((sitemap != null) && ((state instanceof StringType) || validUrl)) {
url = proxiedUrl + "&t=" + (new Date()).getTime();
ignoreRefresh = false;
} else {
url = URL_NONE_ICON;
ignoreRefresh = true;
}
snippet = StringUtils.replace(snippet, "%valid_url%", validUrl ? "true" : "false");
snippet = StringUtils.replace(snippet, "%proxied_url%", proxiedUrl);
snippet = StringUtils.replace(snippet, "%ignore_refresh%", ignoreRefresh ? "true" : "false");
snippet = StringUtils.replace(snippet, "%url%", url);
sb.append(snippet);
return null;
}
Aggregations