Search in sources :

Example 41 with StringType

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;
    }
}
Also used : DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) StringType(org.eclipse.smarthome.core.library.types.StringType) State(org.eclipse.smarthome.core.types.State)

Example 42 with StringType

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 + "&amp;widgetId=" + widgetId;
        if (!itemUIRegistry.getVisiblity(w)) {
            url = URL_NONE_ICON;
        } else if ((sitemap != null) && ((state instanceof StringType) || validUrl)) {
            url = proxiedUrl + "&amp;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;
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) Video(org.eclipse.smarthome.model.sitemap.Video) State(org.eclipse.smarthome.core.types.State) Date(java.util.Date)

Example 43 with StringType

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 + "&amp;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 + "&amp;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;
}
Also used : StringType(org.eclipse.smarthome.core.library.types.StringType) State(org.eclipse.smarthome.core.types.State) RawType(org.eclipse.smarthome.core.library.types.RawType) Image(org.eclipse.smarthome.model.sitemap.Image) Date(java.util.Date)

Aggregations

StringType (org.eclipse.smarthome.core.library.types.StringType)43 State (org.eclipse.smarthome.core.types.State)13 Test (org.junit.Test)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)9 PercentType (org.eclipse.smarthome.core.library.types.PercentType)8 StateDescription (org.eclipse.smarthome.core.types.StateDescription)6 SonosEntry (org.eclipse.smarthome.binding.sonos.internal.SonosEntry)5 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)5 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)5 Date (java.util.Date)3 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)3 RefreshType (org.eclipse.smarthome.core.types.RefreshType)3 ArrayList (java.util.ArrayList)2 SensorEnum (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.constants.SensorEnum)2 DeviceStateUpdateImpl (org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.deviceparameters.impl.DeviceStateUpdateImpl)2 Event (org.eclipse.smarthome.core.events.Event)2 Item (org.eclipse.smarthome.core.items.Item)2 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)2 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)2