use of org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState in project smarthome by eclipse.
the class HomieImplementationTests method retrieveAttributes.
@SuppressWarnings("null")
@Test
public void retrieveAttributes() throws InterruptedException, ExecutionException {
assertThat(connection.hasSubscribers(), is(false));
Node node = new Node(deviceTopic, "testnode", ThingChannelConstants.testHomieThing, callback, new NodeAttributes());
Property property = spy(new Property(deviceTopic + "/testnode", node, "temperature", callback, new PropertyAttributes()));
// Create a scheduler
ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(4);
property.subscribe(connection, scheduler, 100).get();
assertThat(property.attributes.settable, is(true));
assertThat(property.attributes.retained, is(true));
assertThat(property.attributes.name, is("Testprop"));
assertThat(property.attributes.unit, is("°C"));
assertThat(property.attributes.datatype, is(DataTypeEnum.float_));
assertThat(property.attributes.format, is("-100:100"));
verify(property).attributesReceived();
// Receive property value
ChannelState channelState = spy(property.getChannelState());
PropertyHelper.setChannelState(property, channelState);
property.startChannel(connection, scheduler, 200).get();
verify(channelState).start(any(), any(), anyInt());
verify(channelState).processMessage(any(), any());
verify(callback).updateChannelState(any(), any());
assertThat(property.getChannelState().getCache().getChannelState(), is(new DecimalType(10)));
property.stop().get();
assertThat(connection.hasSubscribers(), is(false));
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState in project smarthome by eclipse.
the class GenericThingHandlerTests method handleCommandUpdateBoolean.
@Test
public void handleCommandUpdateBoolean() {
OnOffValue value = spy(new OnOffValue("ON", "OFF"));
ChannelState channelConfig = spy(new ChannelState(ChannelConfigBuilder.create("stateTopic", "commandTopic").build(), textChannelUID, value, thingHandler));
doReturn(channelConfig).when(thingHandler).createChannelState(any(), any(), any());
thingHandler.initialize();
thingHandler.connection = connection;
StringType updateValue = new StringType("ON");
thingHandler.handleCommand(textChannelUID, updateValue);
verify(value).update(eq(updateValue));
assertThat(channelConfig.getCache().getChannelState(), is(OnOffType.ON));
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState in project smarthome by eclipse.
the class GenericThingHandlerTests method handleCommandRefresh.
@Test
public void handleCommandRefresh() {
ChannelState channelConfig = mock(ChannelState.class);
doReturn(CompletableFuture.completedFuture(true)).when(channelConfig).start(any(), any(), anyInt());
doReturn(CompletableFuture.completedFuture(true)).when(channelConfig).stop();
doReturn(channelConfig).when(thingHandler).createChannelState(any(), any(), any());
thingHandler.initialize();
TextValue value = spy(new TextValue());
doReturn(value).when(channelConfig).getCache();
thingHandler.connection = connection;
thingHandler.handleCommand(textChannelUID, RefreshType.REFRESH);
verify(value).getChannelState();
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState in project smarthome by eclipse.
the class GenericThingHandlerTests method handleCommandUpdateString.
@Test
public void handleCommandUpdateString() {
TextValue value = spy(new TextValue());
ChannelState channelConfig = spy(new ChannelState(ChannelConfigBuilder.create("stateTopic", "commandTopic").build(), textChannelUID, value, thingHandler));
doReturn(channelConfig).when(thingHandler).createChannelState(any(), any(), any());
thingHandler.initialize();
thingHandler.connection = connection;
StringType updateValue = new StringType("UPDATE");
thingHandler.handleCommand(textChannelUID, updateValue);
verify(value).update(eq(updateValue));
assertThat(channelConfig.getCache().getChannelState().toString(), is("UPDATE"));
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState in project smarthome by eclipse.
the class GenericThingHandlerTests method processMessage.
@Test
public void processMessage() {
TextValue textValue = new TextValue();
ChannelState channelConfig = spy(new ChannelState(ChannelConfigBuilder.create("test/state", "test/state/set").build(), textChannelUID, textValue, thingHandler));
doReturn(channelConfig).when(thingHandler).createChannelState(any(), any(), any());
thingHandler.initialize();
byte[] payload = "UPDATE".getBytes();
// Test process message
channelConfig.processMessage("test/state", payload);
verify(callback).statusUpdated(eq(thing), argThat(arg -> arg.getStatus().equals(ThingStatus.ONLINE)));
verify(callback).stateUpdated(eq(textChannelUID), argThat(arg -> "UPDATE".equals(arg.toString())));
assertThat(textValue.getChannelState().toString(), is("UPDATE"));
}
Aggregations