use of org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes in project openhab-addons by openhab.
the class HomieImplementationTest method retrieveAttributes.
@SuppressWarnings("null")
@Test
public void retrieveAttributes() throws InterruptedException, ExecutionException {
assertThat(connection.hasSubscribers(), is(false));
Node node = new Node(DEVICE_TOPIC, "testnode", ThingChannelConstants.testHomieThing, callback, new NodeAttributes());
Property property = spy(new Property(DEVICE_TOPIC + "/testnode", node, "temperature", callback, new PropertyAttributes()));
// Create a scheduler
ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(4);
property.subscribe(connection, scheduler, 500).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_));
waitForAssert(() -> assertThat(property.attributes.format, is("-100:100")));
verify(property, timeout(500).atLeastOnce()).attributesReceived();
// Receive property value
ChannelState channelState = spy(property.getChannelState());
PropertyHelper.setChannelState(property, channelState);
property.startChannel(connection, scheduler, 500).get();
verify(channelState).start(any(), any(), anyInt());
verify(channelState, timeout(500)).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.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes in project openhab-addons by openhab.
the class HomieImplementationTest method createSpyNode.
// Inject a spy'ed node
public Node createSpyNode(InvocationOnMock invocation) {
final Device device = (Device) invocation.getMock();
final String id = (String) invocation.getArguments()[0];
// Create the node
Node node = spy(device.createNode(id, spy(new NodeAttributes())));
// Intercept creating a property in the next call and inject a spy'ed property.
doAnswer(this::createSpyProperty).when(node).createProperty(any());
return node;
}
Aggregations