Java Code Examples for org.eclipse.smarthome.core.types.State#toFullString()

The following examples show how to use org.eclipse.smarthome.core.types.State#toFullString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemEventFactory.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates an item state predicted event.
 *
 * @param itemName the name of the item to send the state update for
 * @param state the predicted state to send
 * @param isConfirmation whether this is a confirmation of a previous state
 * @return the created item state predicted event
 * @throws IllegalArgumentException if itemName or state is null
 */
public static ItemStatePredictedEvent createStatePredictedEvent(String itemName, State state,
        boolean isConfirmation) {
    assertValidArguments(itemName, state, "state");
    String topic = buildTopic(ITEM_STATE_PREDICTED_EVENT_TOPIC, itemName);
    ItemStatePredictedEventPayloadBean bean = new ItemStatePredictedEventPayloadBean(getStateType(state),
            state.toFullString(), isConfirmation);
    String payload = serializePayload(bean);
    return new ItemStatePredictedEvent(topic, payload, itemName, state, isConfirmation);
}
 
Example 2
Source File: ItemEventFactory.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
public static GroupItemStateChangedEvent createGroupStateChangedEvent(String itemName, String memberName,
        State newState, State oldState) {
    assertValidArguments(itemName, memberName, newState, "state");
    String topic = buildGroupTopic(GROUPITEM_STATE_CHANGED_EVENT_TOPIC, itemName, memberName);
    ItemStateChangedEventPayloadBean bean = new ItemStateChangedEventPayloadBean(getStateType(newState),
            newState.toFullString(), getStateType(oldState), oldState.toFullString());
    String payload = serializePayload(bean);
    return new GroupItemStateChangedEvent(topic, payload, itemName, memberName, newState, oldState);
}
 
Example 3
Source File: StateTypeAdapter.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void write(JsonWriter writer, State state) throws IOException {
    if (state == null) {
        writer.nullValue();
        return;
    }
    String value = state.getClass().getName() + TYPE_SEPARATOR + state.toFullString();
    writer.value(value);
}
 
Example 4
Source File: ImageRenderer.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@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, "%refresh%", "id=\"%id%\" data-timeout=\"" + image.getRefresh()
                + "\" onload=\"startReloadImage('%url%', '%id%')\"");
    } else {
        snippet = StringUtils.replace(snippet, "%refresh%", "");
    }

    String widgetId = itemUIRegistry.getWidgetId(w);
    snippet = StringUtils.replace(snippet, "%id%", widgetId);

    String sitemap = null;
    if (w.eResource() != null) {
        sitemap = w.eResource().getURI().path();
    }
    boolean validUrl = isValidURL(image.getUrl());
    String proxiedUrl = "../proxy?sitemap=" + sitemap + "&widgetId=" + widgetId;
    State state = itemUIRegistry.getState(w);
    String url;
    if (state instanceof RawType) {
        url = state.toFullString();
    } else if ((sitemap != null) && ((state instanceof StringType) || validUrl)) {
        url = proxiedUrl + "&t=" + (new Date()).getTime();
    } else {
        url = "images/none.png";
    }
    snippet = StringUtils.replace(snippet, "%url%", url);

    sb.append(snippet);
    return null;
}
 
Example 5
Source File: ImageRenderer.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@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 = isValidURL(image.getUrl());
    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;
}
 
Example 6
Source File: ItemEventFactory.java    From smarthome with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Creates an item state event.
 *
 * @param itemName the name of the item to send the state update for
 * @param state the new state to send
 * @param source the name of the source identifying the sender (can be null)
 * @return the created item state event
 * @throws IllegalArgumentException if itemName or state is null
 */
public static ItemStateEvent createStateEvent(String itemName, State state, String source) {
    assertValidArguments(itemName, state, "state");
    String topic = buildTopic(ITEM_STATE_EVENT_TOPIC, itemName);
    ItemEventPayloadBean bean = new ItemEventPayloadBean(getStateType(state), state.toFullString());
    String payload = serializePayload(bean);
    return new ItemStateEvent(topic, payload, itemName, state, source);
}
 
Example 7
Source File: ItemEventFactory.java    From smarthome with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Creates an item state changed event.
 *
 * @param itemName the name of the item to send the state changed event for
 * @param newState the new state to send
 * @param oldState the old state of the item
 * @return the created item state changed event
 * @throws IllegalArgumentException if itemName or state is null
 */
public static ItemStateChangedEvent createStateChangedEvent(String itemName, State newState, State oldState) {
    assertValidArguments(itemName, newState, "state");
    String topic = buildTopic(ITEM_STATE_CHANGED_EVENT_TOPIC, itemName);
    ItemStateChangedEventPayloadBean bean = new ItemStateChangedEventPayloadBean(getStateType(newState),
            newState.toFullString(), getStateType(oldState), oldState.toFullString());
    String payload = serializePayload(bean);
    return new ItemStateChangedEvent(topic, payload, itemName, newState, oldState);
}