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));
}
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")));
}
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);
}
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")));
}
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);
}
}
}
Aggregations