Skip to content

Commit

Permalink
make sure the client api is paired before requesting the gateway's id
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdgeisler committed Nov 24, 2022
1 parent 3acd3ca commit eb9cade
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public MqttBridge(
@Value("${dirigera.mqtt.reconnect:true}") final Boolean reconnect,
@Value("${dirigera.mqtt.timeout:10}") final Integer timeout,
final DirigeraApi api) throws MqttException {
super(String.format("tcp://%s:%d", host, port),
Objects.requireNonNull(api.status().map(s -> s.id).block()));
super(String.format("tcp://%s:%d", host, port), clientId(api));
final MqttConnectOptions options;
this.api = api;
this.eventHandler = new HashMap<>();
Expand Down Expand Up @@ -115,4 +114,9 @@ public <_Device extends Device> void removeDevice(final _Device device) {
.flatMap(factory -> factory.removeDevice(this, this.api, device))
.forEach(this::publishMessage);
}

private static String clientId(final DirigeraApi api) {
api.pairIfRequired().block();
return api.status().map(s -> s.id).block();
}
}

0 comments on commit eb9cade

Please sign in to comment.