use of org.eclipse.smarthome.binding.mqtt.generic.internal.tools.DelayedBatchProcessing in project smarthome by eclipse.
the class HomieThingHandlerTests method setUp.
@Before
public void setUp() {
final ThingStatusInfo thingStatus = new ThingStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE, null);
MockitoAnnotations.initMocks(this);
final Configuration config = new Configuration();
config.put("basetopic", "homie");
config.put("deviceid", deviceID);
thing = ThingBuilder.create(MqttBindingConstants.HOMIE300_MQTT_THING, testHomieThing.getId()).withConfiguration(config).build();
thing.setStatusInfo(thingStatus);
// Return the mocked connection object if the bridge handler is asked for it
when(bridgeHandler.getConnectionAsync()).thenReturn(CompletableFuture.completedFuture(connection));
doReturn(CompletableFuture.completedFuture(true)).when(connection).subscribe(any(), any());
doReturn(CompletableFuture.completedFuture(true)).when(connection).unsubscribe(any(), any());
doReturn(CompletableFuture.completedFuture(true)).when(connection).unsubscribeAll();
doReturn(CompletableFuture.completedFuture(true)).when(connection).publish(any(), any(), anyInt(), anyBoolean());
doReturn(false).when(scheduledFuture).isDone();
doReturn(scheduledFuture).when(scheduler).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
final HomieThingHandler handler = new HomieThingHandler(thing, channelTypeProvider, 30, 5);
thingHandler = spy(handler);
thingHandler.setCallback(callback);
final Device device = new Device(thing.getUID(), thingHandler, spy(new DeviceAttributes()), spy(new ChildMap<>()));
thingHandler.setInternalObjects(spy(device), spy(new DelayedBatchProcessing<Object>(500, thingHandler, scheduler)));
// Return the bridge handler if the thing handler asks for it
doReturn(bridgeHandler).when(thingHandler).getBridgeHandler();
// We are by default online
doReturn(thingStatus).when(thingHandler).getBridgeStatus();
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.tools.DelayedBatchProcessing in project smarthome by eclipse.
the class HomieThingHandler method accept.
/**
* Callback of {@link DelayedBatchProcessing}.
* Add all newly discovered nodes and properties to the Thing and start subscribe to each channel state topic.
*/
@Override
public void accept(@Nullable List<Object> t) {
if (!device.isInitialized()) {
return;
}
List<Channel> channels = device.nodes().stream().flatMap(n -> n.properties.stream()).map(prop -> prop.getChannel()).collect(Collectors.toList());
updateThing(editThing().withChannels(channels).build());
updateProperty(MqttBindingConstants.HOMIE_PROPERTY_VERSION, device.attributes.homie);
final MqttBrokerConnection connection = this.connection;
if (connection != null) {
device.startChannels(connection, scheduler, attributeReceiveTimeout, this).thenRun(() -> {
logger.trace("Homie device {} fully attached", device.attributes.name);
});
}
}
Aggregations