Search in sources :

Example 1 with RawType

use of org.eclipse.smarthome.core.library.types.RawType in project smarthome by eclipse.

the class ZonePlayerHandler method updateAlbumArtChannel.

private void updateAlbumArtChannel(boolean allGroup) {
    String url = getAlbumArtUrl();
    if (url != null) {
        // We download the cover art in a different thread to not delay the other operations
        scheduler.submit(() -> {
            RawType image = HttpUtil.downloadImage(url, true, 500000);
            updateChannel(CURRENTALBUMART, image != null ? image : UnDefType.UNDEF, allGroup);
        });
    } else {
        updateChannel(CURRENTALBUMART, UnDefType.UNDEF, allGroup);
    }
}
Also used : RawType(org.eclipse.smarthome.core.library.types.RawType)

Example 2 with RawType

use of org.eclipse.smarthome.core.library.types.RawType in project smarthome by eclipse.

the class GroupItemTest method assertThatGroupItemChangesDoNotAffectTheGroupStatusIfnoFunctionOrBaseItemAreDefined.

@SuppressWarnings("deprecation")
@Test
public void assertThatGroupItemChangesDoNotAffectTheGroupStatusIfnoFunctionOrBaseItemAreDefined() throws InterruptedException {
    events.clear();
    GroupItem groupItem = new GroupItem("root");
    TestItem member = new TestItem("member1");
    groupItem.addMember(member);
    groupItem.setEventPublisher(publisher);
    State oldGroupState = groupItem.getState();
    // State changes -> NO change event should be fired
    member.setState(new RawType());
    // wait to see that the event doesn't fire
    Thread.sleep(WAIT_EVENT_TO_BE_HANDLED);
    assertThat(events.size(), is(0));
    assertTrue(groupItem.getState().equals(oldGroupState));
}
Also used : State(org.eclipse.smarthome.core.types.State) RawType(org.eclipse.smarthome.core.library.types.RawType) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 3 with RawType

use of org.eclipse.smarthome.core.library.types.RawType in project smarthome by eclipse.

the class ImageItemTest method testRawType.

@Test
public void testRawType() {
    ImageItem item = new ImageItem("test");
    State state = new RawType(new byte[0], "application/octet-stream");
    item.setState(state);
    assertEquals(state, item.getState());
}
Also used : State(org.eclipse.smarthome.core.types.State) RawType(org.eclipse.smarthome.core.library.types.RawType) Test(org.junit.Test)

Example 4 with RawType

use of org.eclipse.smarthome.core.library.types.RawType in project smarthome by eclipse.

the class StateUtil method getAllStates.

public static List<State> getAllStates() {
    LinkedList<State> states = new LinkedList<>();
    DateTimeType dateTime = new DateTimeType();
    states.add(dateTime);
    DecimalType decimal = new DecimalType(23);
    states.add(decimal);
    PercentType percent = new PercentType(50);
    states.add(percent);
    HSBType hsb = new HSBType("50,75,42");
    states.add(hsb);
    states.add(OnOffType.ON);
    states.add(OnOffType.OFF);
    states.add(OpenClosedType.OPEN);
    states.add(OpenClosedType.CLOSED);
    states.add(PlayPauseType.PLAY);
    states.add(PlayPauseType.PAUSE);
    PointType point = new PointType("42.23,23.5");
    states.add(point);
    RawType raw = new RawType(new byte[0], "application/octet-stream");
    states.add(raw);
    states.add(RewindFastforwardType.REWIND);
    states.add(RewindFastforwardType.FASTFORWARD);
    StringListType stringList = new StringListType(new String[] { "foo", "bar" });
    states.add(stringList);
    StringType string = new StringType("foo");
    states.add(string);
    states.add(UnDefType.NULL);
    states.add(UnDefType.UNDEF);
    states.add(UpDownType.UP);
    states.add(UpDownType.DOWN);
    QuantityType<Temperature> quantityType = new QuantityType<Temperature>("12 °C");
    states.add(quantityType);
    return states;
}
Also used : Temperature(javax.measure.quantity.Temperature) StringType(org.eclipse.smarthome.core.library.types.StringType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) LinkedList(java.util.LinkedList) DateTimeType(org.eclipse.smarthome.core.library.types.DateTimeType) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PointType(org.eclipse.smarthome.core.library.types.PointType) RawType(org.eclipse.smarthome.core.library.types.RawType) HSBType(org.eclipse.smarthome.core.library.types.HSBType) StringListType(org.eclipse.smarthome.core.library.types.StringListType)

Example 5 with RawType

use of org.eclipse.smarthome.core.library.types.RawType 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, "%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 = 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;
    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;
}
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

RawType (org.eclipse.smarthome.core.library.types.RawType)7 State (org.eclipse.smarthome.core.types.State)5 StringType (org.eclipse.smarthome.core.library.types.StringType)3 Date (java.util.Date)2 Image (org.eclipse.smarthome.model.sitemap.Image)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Temperature (javax.measure.quantity.Temperature)1 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)1 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)1 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)1 HSBType (org.eclipse.smarthome.core.library.types.HSBType)1 PercentType (org.eclipse.smarthome.core.library.types.PercentType)1 PointType (org.eclipse.smarthome.core.library.types.PointType)1 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)1 StringListType (org.eclipse.smarthome.core.library.types.StringListType)1 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)1