Search in sources :

Example 1 with DecimalType

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

the class ItemStateConverterImplTest method testStateConversion.

@Test
public void testStateConversion() {
    Item item = new NumberItem("number");
    State originalState = new PercentType("42");
    State convertedState = itemStateConverter.convertToAcceptedState(originalState, item);
    assertThat(convertedState, is(new DecimalType("0.42")));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) PercentType(org.eclipse.smarthome.core.library.types.PercentType) Test(org.junit.Test)

Example 2 with DecimalType

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

the class ItemStateConverterImplTest method testNoConversion.

@Test
public void testNoConversion() {
    Item item = new NumberItem("number");
    State originalState = new DecimalType(12.34);
    State state = itemStateConverter.convertToAcceptedState(originalState, item);
    assertTrue(originalState == state);
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) Item(org.eclipse.smarthome.core.items.Item) State(org.eclipse.smarthome.core.types.State) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 3 with DecimalType

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

the class SitemapResourceTest method whenLongPolling_ShouldObserveItemsFromValueColorConditions.

@Test
public void whenLongPolling_ShouldObserveItemsFromValueColorConditions() {
    new Thread(() -> {
        try {
            // wait for the #getPageData call and listeners to attach to the
            Thread.sleep(STATE_UPDATE_WAIT_TIME);
            // item
            valueColorItem.setState(new DecimalType(BigDecimal.ONE));
        } catch (InterruptedException e) {
        }
    }).start();
    // non-null is sufficient here.
    when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(Collections.emptyList());
    Response response = sitemapResource.getPageData(headers, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null);
    PageDTO pageDTO = (PageDTO) response.getEntity();
    // assert that the item state change did trigger the blocking method to
    assertThat(pageDTO.timeout, is(false));
// return
}
Also used : Response(javax.ws.rs.core.Response) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 4 with DecimalType

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

the class SitemapResourceTest method whenLongPolling_ShouldObserveItemsFromLabelColorConditions.

@Test
public void whenLongPolling_ShouldObserveItemsFromLabelColorConditions() {
    new Thread(() -> {
        try {
            // wait for the #getPageData call and listeners to attach to the
            Thread.sleep(STATE_UPDATE_WAIT_TIME);
            // item
            labelColorItem.setState(new DecimalType(BigDecimal.ONE));
        } catch (InterruptedException e) {
        }
    }).start();
    // non-null is sufficient here.
    when(headers.getRequestHeader(HTTP_HEADER_X_ATMOSPHERE_TRANSPORT)).thenReturn(Collections.emptyList());
    Response response = sitemapResource.getPageData(headers, null, SITEMAP_MODEL_NAME, SITEMAP_NAME, null);
    PageDTO pageDTO = (PageDTO) response.getEntity();
    // assert that the item state change did trigger the blocking method to
    assertThat(pageDTO.timeout, is(false));
// return
}
Also used : Response(javax.ws.rs.core.Response) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) Test(org.junit.Test)

Example 5 with DecimalType

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

the class ZonePlayerHandler method snoozeAlarm.

public void snoozeAlarm(Command command) {
    if (isAlarmRunning() && command instanceof DecimalType) {
        int minutes = ((DecimalType) command).intValue();
        Map<String, String> inputs = new HashMap<String, String>();
        Calendar snoozePeriod = Calendar.getInstance();
        snoozePeriod.setTimeZone(TimeZone.getTimeZone("GMT"));
        snoozePeriod.setTimeInMillis(0);
        snoozePeriod.add(Calendar.MINUTE, minutes);
        SimpleDateFormat pFormatter = new SimpleDateFormat("HH:mm:ss");
        pFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
        try {
            inputs.put("Duration", pFormatter.format(snoozePeriod.getTime()));
        } catch (NumberFormatException ex) {
            logger.debug("Action Invalid Value Format Exception {}", ex.getMessage());
        }
        Map<String, String> result = service.invokeAction(this, "AVTransport", "SnoozeAlarm", inputs);
        for (String variable : result.keySet()) {
            this.onValueReceived(variable, result.get(variable), "AVTransport");
        }
    } else {
        logger.debug("There is no alarm running on {}", getUDN());
    }
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) DecimalType(org.eclipse.smarthome.core.library.types.DecimalType) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)68 Test (org.junit.Test)33 State (org.eclipse.smarthome.core.types.State)17 PercentType (org.eclipse.smarthome.core.library.types.PercentType)16 HistoricItem (org.eclipse.smarthome.core.persistence.HistoricItem)11 StringType (org.eclipse.smarthome.core.library.types.StringType)9 HSBType (org.eclipse.smarthome.core.library.types.HSBType)8 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)7 Type (org.eclipse.smarthome.core.types.Type)7 Item (org.eclipse.smarthome.core.items.Item)6 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BigDecimal (java.math.BigDecimal)5 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)4 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)4 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)4 Response (javax.ws.rs.core.Response)3 ValueSet (org.eclipse.smarthome.binding.dmx.internal.ValueSet)3 FadeAction (org.eclipse.smarthome.binding.dmx.internal.action.FadeAction)3 DateTimeType (org.eclipse.smarthome.core.library.types.DateTimeType)3