Search in sources :

Example 1 with State

use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.

the class ItemStateConverterImplTest method testNullState.

@Test
public void testNullState() {
    State undef = itemStateConverter.convertToAcceptedState(null, null);
    assertThat(undef, is(UnDefType.NULL));
}
Also used : State(org.eclipse.smarthome.core.types.State) Test(org.junit.Test)

Example 2 with State

use of org.eclipse.smarthome.core.types.State 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 3 with State

use of org.eclipse.smarthome.core.types.State 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 4 with State

use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.

the class ItemStateConverterImplTest method numberItemWitDimensionShouldConvertToItemStateDescriptionUnit.

@Test
public void numberItemWitDimensionShouldConvertToItemStateDescriptionUnit() {
    NumberItem item = mock(NumberItem.class);
    StateDescription stateDescription = mock(StateDescription.class);
    when(item.getStateDescription()).thenReturn(stateDescription);
    doReturn(Temperature.class).when(item).getDimension();
    when(stateDescription.getPattern()).thenReturn("%.1f K");
    State originalState = new QuantityType<>("12.34 °C");
    State convertedState = itemStateConverter.convertToAcceptedState(originalState, item);
    assertThat(convertedState, is(new QuantityType<>("285.49 K")));
}
Also used : NumberItem(org.eclipse.smarthome.core.library.items.NumberItem) QuantityType(org.eclipse.smarthome.core.library.types.QuantityType) State(org.eclipse.smarthome.core.types.State) StateDescription(org.eclipse.smarthome.core.types.StateDescription) Test(org.junit.Test)

Example 5 with State

use of org.eclipse.smarthome.core.types.State in project smarthome by eclipse.

the class AutoUpdateBinding method receiveCommand.

/**
 * Handle the received command event.
 *
 * <p>
 * If the command could be converted to a {@link State} the auto-update configurations are inspected.
 * If there is at least one configuration that enable the auto-update, auto-update is applied.
 * If there is no configuration provided at all the autoupdate defaults to {@code true} and an update is posted for
 * the corresponding {@link State}.
 *
 * @param commandEvent the command event
 */
@Override
protected void receiveCommand(ItemCommandEvent commandEvent) {
    final Command command = commandEvent.getItemCommand();
    if (command instanceof State) {
        final State state = (State) command;
        final String itemName = commandEvent.getItemName();
        Boolean autoUpdate = autoUpdate(itemName);
        // we didn't find any autoupdate configuration, so apply the default now
        if (autoUpdate == null) {
            autoUpdate = Boolean.TRUE;
        }
        if (autoUpdate) {
            postUpdate(itemName, state);
        } else {
            logger.trace("Won't update item '{}' as it is not configured to update its state automatically.", itemName);
        }
    }
}
Also used : Command(org.eclipse.smarthome.core.types.Command) State(org.eclipse.smarthome.core.types.State)

Aggregations

State (org.eclipse.smarthome.core.types.State)130 Test (org.junit.Test)59 DecimalType (org.eclipse.smarthome.core.library.types.DecimalType)23 PercentType (org.eclipse.smarthome.core.library.types.PercentType)22 Item (org.eclipse.smarthome.core.items.Item)21 NumberItem (org.eclipse.smarthome.core.library.items.NumberItem)19 Temperature (javax.measure.quantity.Temperature)18 StringType (org.eclipse.smarthome.core.library.types.StringType)18 QuantityType (org.eclipse.smarthome.core.library.types.QuantityType)17 ItemNotFoundException (org.eclipse.smarthome.core.items.ItemNotFoundException)15 HSBType (org.eclipse.smarthome.core.library.types.HSBType)15 OnOffType (org.eclipse.smarthome.core.library.types.OnOffType)15 RollershutterItem (org.eclipse.smarthome.core.library.items.RollershutterItem)13 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)13 ColorItem (org.eclipse.smarthome.core.library.items.ColorItem)12 SwitchItem (org.eclipse.smarthome.core.library.items.SwitchItem)11 DimmerItem (org.eclipse.smarthome.core.library.items.DimmerItem)10 RawType (org.eclipse.smarthome.core.library.types.RawType)10 Pressure (javax.measure.quantity.Pressure)9 GroupItem (org.eclipse.smarthome.core.items.GroupItem)8