Skip to content

Commit

Permalink
Use constants for magic strings
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienvermeille committed Feb 6, 2024
1 parent 4142a72 commit 2ffbdf9
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
@Flogger
public class MqttConfiguration {

private static final String DELIMITER = ":";
private static final String STOVE_ID = "stoveId";
private final MqttConfigProperties mqttConfigProperties;
private final ApplicationEventPublisher applicationEventPublisher;
private final Gson gson;
Expand All @@ -71,7 +73,7 @@ public MqttPahoClientFactory mqttClientFactory() {
new String[] {
mqttConfigProperties.getUriScheme()
+ mqttConfigProperties.getHost()
+ ":"
+ DELIMITER
+ mqttConfigProperties.getPort()
});
options.setUserName(mqttConfigProperties.getUsername());
Expand Down Expand Up @@ -159,10 +161,10 @@ public MessageHandler mqttInputMessageHandler() {
try {
final var type = new TypeToken<Map<String, String>>() {}.getType();
final Map<String, String> props = gson.fromJson(payload, type);
final var stoveId = Long.parseUnsignedLong(props.get("stoveId"));
final var stoveId = Long.parseUnsignedLong(props.get(STOVE_ID));

// remove stoveId props as it has its own property in the wrapping object
props.remove("stoveId");
props.remove(STOVE_ID);

applicationEventPublisher.publishEvent(
MqttCommandEvent.builder().withStoveId(stoveId).withProps(props));
Expand Down

0 comments on commit 2ffbdf9

Please sign in to comment.