use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes 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.convention.homie300.PropertyAttributes in project smarthome by eclipse.
the class HomieThingHandlerTests method handleCommandRefresh.
@SuppressWarnings("null")
@Test
public void handleCommandRefresh() {
// Create mocked homie device tree with one node and one read-only property
Node node = thingHandler.device.createNode("node", spy(new NodeAttributes()));
doReturn(future).when(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(node.attributes).unsubscribe();
node.attributes.name = "testnode";
Property property = node.createProperty("property", spy(new PropertyAttributes()));
doReturn(future).when(property.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(property.attributes).unsubscribe();
property.attributes.name = "testprop";
property.attributes.datatype = DataTypeEnum.string_;
property.attributes.settable = false;
property.attributesReceived();
node.properties.put(property.propertyID, property);
thingHandler.device.nodes.put(node.nodeID, node);
thingHandler.connection = connection;
thingHandler.handleCommand(property.channelUID, RefreshType.REFRESH);
verify(callback).stateUpdated(argThat(arg -> property.channelUID.equals(arg)), argThat(arg -> property.getChannelState().getCache().getChannelState().equals(arg)));
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes in project smarthome by eclipse.
the class HomieThingHandlerTests method createSpyProperty.
public Property createSpyProperty(String propertyID, Node node) {
// Create a property with the same ID and insert it instead
Property property = spy(node.createProperty(propertyID, spy(new PropertyAttributes())));
doAnswer(this::createSubscriberAnswer).when(property.attributes).createSubscriber(any(), any(), any(), anyBoolean());
property.attributes.name = "testprop";
property.attributes.datatype = DataTypeEnum.string_;
return property;
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes in project smarthome by eclipse.
the class HomieImplementationTests method createSpyProperty.
// Inject a spy'ed property
public Property createSpyProperty(InvocationOnMock invocation) {
final Node node = (Node) invocation.getMock();
final String id = (String) invocation.getArguments()[0];
Property property = spy(node.createProperty(id, spy(new PropertyAttributes())));
return property;
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes in project smarthome by eclipse.
the class HomieThingHandlerTests method handleCommandUpdate.
@SuppressWarnings("null")
@Test
public void handleCommandUpdate() {
// Create mocked homie device tree with one node and one writable property
Node node = thingHandler.device.createNode("node", spy(new NodeAttributes()));
doReturn(future).when(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(node.attributes).unsubscribe();
node.attributes.name = "testnode";
Property property = node.createProperty("property", spy(new PropertyAttributes()));
doReturn(future).when(property.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(property.attributes).unsubscribe();
property.attributes.name = "testprop";
property.attributes.datatype = DataTypeEnum.string_;
property.attributes.settable = true;
property.attributesReceived();
node.properties.put(property.propertyID, property);
thingHandler.device.nodes.put(node.nodeID, node);
ChannelState channelState = property.getChannelState();
assertNotNull(channelState);
// Pretend we called start()
ChannelStateHelper.setConnection(channelState, connection);
thingHandler.connection = connection;
StringType updateValue = new StringType("UPDATE");
thingHandler.handleCommand(property.channelUID, updateValue);
assertThat(property.getChannelState().getCache().getChannelState().toString(), is("UPDATE"));
verify(connection, times(1)).publish(any(), any(), anyInt(), anyBoolean());
// Check non writable property
property.attributes.settable = false;
property.attributesReceived();
// Assign old value
Value value = property.getChannelState().getCache();
Command command = TypeParser.parseCommand(value.getSupportedCommandTypes(), "OLDVALUE");
property.getChannelState().getCache().update(command);
// Try to update with new value
updateValue = new StringType("SOMETHINGNEW");
thingHandler.handleCommand(property.channelUID, updateValue);
// Expect old value and no MQTT publish
assertThat(property.getChannelState().getCache().getChannelState().toString(), is("OLDVALUE"));
verify(connection, times(1)).publish(any(), any(), anyInt(), anyBoolean());
}
Aggregations